shithub: scc

Download patch

ref: 5ab34fe6b03c4e0938f17fe445e96bc19bf76768
parent: 6bebff844a6aa4f95675dc7beae9ff24d06464b0
author: Hiltjo Posthuma <hiltjo@codemadness.org>
date: Thu May 19 14:53:46 EDT 2022

libc: fix underflow in vsnprintf when size is 0

"If n is zero, nothing is written, and s may be a null pointer."

--- a/src/libc/stdio/vsnprintf.c
+++ b/src/libc/stdio/vsnprintf.c
@@ -19,7 +19,8 @@
 	if (s) {
 		if (f.wp == f.rp)
 			--f.wp;
-		*f.wp = '\0';
+		if (siz != 0)
+			*f.wp = '\0';
 	}
 
 	return r;