]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3408: Wrong header length leads to EFAULTs when creating UFS swap.log.new
authorMatthias Pitzl <silamael@coronamundi.de>
Thu, 17 Nov 2011 09:40:29 +0000 (02:40 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 17 Nov 2011 09:40:29 +0000 (02:40 -0700)
Also localized the header variable as it may be destroyed at any time.

src/fs/ufs/store_dir_ufs.cc

index 092b2f552e02827370bbe1c3e79d77512c29ad5a..7e798505199cc5217eeac3bdd268e52c645a104e 100644 (file)
@@ -768,7 +768,6 @@ UFSSwapDir::openTmpSwapLog(int *clean_flag, int *zero_flag)
     struct stat clean_sb;
     FILE *fp;
     int fd;
-    StoreSwapLogHeader *head;
 
     if (::stat(swaplog_path, &log_sb) < 0) {
         debugs(47, 1, "Cache Dir #" << index << ": No log file");
@@ -794,10 +793,11 @@ UFSSwapDir::openTmpSwapLog(int *clean_flag, int *zero_flag)
 
     swaplog_fd = fd;
 
-    head = new StoreSwapLogHeader;
-
-    file_write(swaplog_fd, -1, head, head->record_size,
-               NULL, NULL, FreeHeader);
+    {
+        StoreSwapLogHeader *header = new StoreSwapLogHeader;
+        file_write(swaplog_fd, -1, header, sizeof(*header),
+                   NULL, NULL, FreeHeader);
+    }
 
     /* open a read-only stream of the old log */
     fp = fopen(swaplog_path, "rb");