From 1417ca79f84c53bc3e363d422e994b7c607d3178 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 5 May 2023 01:15:22 -0400 Subject: [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) --- src/mod_dirlisting.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') 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 } -- cgit v1.2.1