patch-2.4.25 linux-2.4.25/lib/vsprintf.c

Next file: linux-2.4.25/mm/filemap.c
Previous file: linux-2.4.25/kernel/signal.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.24/lib/vsprintf.c linux-2.4.25/lib/vsprintf.c
@@ -248,6 +248,18 @@
 				/* 'z' support added 23/7/1999 S.H.    */
 				/* 'z' changed to 'Z' --davidm 1/25/99 */
 
+	/* Reject out-of-range values early */
+	if (unlikely((int) size < 0)) {
+		/* There can be only one.. */
+		static int warn = 1;
+		if (warn) {
+			printk(KERN_WARNING "improper call of vsnprintf!\n");
+			dump_stack();
+			warn = 0;
+		}
+		return 0;
+	}
+
 	str = buf;
 	end = buf + size - 1;
 
@@ -488,7 +500,7 @@
  */
 int vsprintf(char *buf, const char *fmt, va_list args)
 {
-	return vsnprintf(buf, 0xFFFFFFFFUL, fmt, args);
+	return vsnprintf(buf, (~0U)>>1, fmt, args);
 }
 
 
@@ -586,7 +598,7 @@
 				field_width = 1;
 			do {
 				*s++ = *str++;
-			} while(field_width-- > 0 && *str);
+			} while (--field_width > 0 && *str);
 			num++;
 		}
 		continue;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)