diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-05 01:15:22 -0400 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2023-05-05 01:21:15 -0400 |
commit | 1417ca79f84c53bc3e363d422e994b7c607d3178 (patch) | |
tree | 1dd0a781481b2acc2e94751aa8f361548a04d3e9 | |
parent | 082eb8a4f8ddc28a46c17c683e0a894bdc66f13a (diff) | |
download | lighttpd-git-1417ca79f84c53bc3e363d422e994b7c607d3178.tar.gz |
[mod_dirlisting] _WIN32 fix fstat() after close()
fix fstat() after close(); revert part of 699e0e46
(bug on master branch; not released) (found by coverity static analysis)
-rw-r--r-- | src/mod_dirlisting.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index f0f037cc..108af1b2 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -1701,14 +1701,22 @@ static void mod_dirlisting_cache_add (request_st * const r, handler_ctx * const const int fd = fdevent_mkostemp(oldpath, 0); if (fd < 0) return; int rc = mod_dirlisting_write_cq(fd, &r->write_queue, r->conf.errh); - close(fd); + #ifdef _WIN32 + close(fd); /*(rename fails if file is open; MS filesystem limitation)*/ + fd = -1; + #endif if (rc && 0 == fdevent_rename(oldpath, newpath)) { stat_cache_invalidate_entry(newpath, len); /* Cache-Control and ETag (also done in mod_dirlisting_cache_check())*/ mod_dirlisting_cache_control(r, hctx->conf.cache->max_age); if (0 != r->conf.etag_flags) { struct stat st; - if (0 == fstat(fd, &st)) { + #ifdef _WIN32 + if (0 == stat(newpath, &st)) + #else + if (0 == fstat(fd, &st)) + #endif + { buffer * const vb = http_header_response_set_ptr(r, HTTP_HEADER_ETAG, CONST_STR_LEN("ETag")); @@ -1718,6 +1726,9 @@ static void mod_dirlisting_cache_add (request_st * const r, handler_ctx * const } else unlink(oldpath); + #ifndef _WIN32 + close(fd); + #endif } |