From: Amos Jeffries Date: Mon, 27 Apr 2015 14:39:04 +0000 (-0700) Subject: Add vsnprintf() protection for vargs X-Git-Tag: merge-candidate-3-v1~101^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd74680720ec985b36a531a2a1cad2fd5fe26f1f;p=thirdparty%2Fsquid.git Add vsnprintf() protection for vargs --- diff --git a/src/store.cc b/src/store.cc index 334cab3b88..6fa07933f6 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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);