Explorar o código

Force string length limits for vsnprintf operations (#175)

See 3 of https://github.com/civetweb/civetweb/issues/175#issuecomment-139703181
bel %!s(int64=10) %!d(string=hai) anos
pai
achega
3792243dc3
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      src/civetweb.c

+ 2 - 1
src/civetweb.c

@@ -3704,8 +3704,9 @@ static int alloc_vprintf2(char **buf, const char *fmt, va_list ap)
 			break;
 		}
 		va_copy(ap_copy, ap);
-		len = vsnprintf_impl(*buf, size, fmt, ap_copy);
+		len = vsnprintf_impl(*buf, size - 1, fmt, ap_copy);
 		va_end(ap_copy);
+		*buf[size - 1] = 0;
 	}
 
 	return len;