]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add vsnprintf() protection for vargs
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Apr 2015 14:39:04 +0000 (07:39 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Apr 2015 14:39:04 +0000 (07:39 -0700)
src/store.cc

index 334cab3b880b96304cdab1a0d2bcaf018d8b30b0..6fa07933f60b8d6340b256f839dda3cb5583c240 100644 (file)
@@ -872,11 +872,26 @@ StoreEntry::vappendf(const char *fmt, va_list vargs)
     *buf = 0;
     int x;
 
+#ifdef VA_COPY
+    va_args ap;
+    /* Fix of bug 753r. The value of vargs is undefined
+     * after vsnprintf() returns. Make a copy of vargs
+     * incase we loop around and call vsnprintf() again.
+     */
+    VA_COPY(ap,vargs);
+    errno = 0;
+    if ((x = vsnprintf(buf, sizeof(buf), fmt, ap)) < 0) {
+        fatalf( xstrerror(errno));
+        return;
+    }
+    va_end(ap);
+#else /* VA_COPY */
     errno = 0;
     if ((x = vsnprintf(buf, sizeof(buf), fmt, vargs)) < 0) {
         fatalf( xstrerror(errno));
         return;
     }
+#endif /*VA_COPY*/
 
     if (x < sizeof(buf)) {
         append(buf, x);