Skip to contentSkip to conversation

fix possible tst_xxx buffer overrun

PATCH New Cyril Hrubis 1 participant 1 message Oct 9, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix possible tst_xxx buffer overrun

Hi!
Following patch fixes tst_** functions that would segfault for printing messages longer than 2048 chars. Now such message is truncated.

Signed-off-by [email protected]
Signature · 2 lines
Cyril Hrubis
[email protected]
lib/tst_res.c +19 -21
Index: ltp/lib/tst_res.c
===================================================================
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * Copyring  (c) 2009 Cyril Hrubis [email protected]
+ * Copyright (c) 2009 Cyril Hrubis [email protected]
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License as
@@ -131,20 +131,18 @@
  * EXPAND_VAR_ARGS - Expand the variable portion (arg_fmt) of a result
  *                   message into the specified string.
  */
-#define EXPAND_VAR_ARGS(arg_fmt, str) {   \
-   va_list ap; /* varargs mechanism */    \
-                                          \
-   if (arg_fmt != NULL) {                 \
-      if ( Expand_varargs == TRUE ) {     \
-         va_start(ap, arg_fmt);           \
-         vsprintf(str, arg_fmt, ap);      \
-         va_end(ap);                      \
-      } else {                            \
-         strcpy(str, arg_fmt);            \
-      }                                   \
-   } else {                               \
-      str[0] = '\0';                      \
-   }                                      \
+#define EXPAND_VAR_ARGS(buf, arg_fmt, buf_len) {              \
+	va_list ap;                                           \
+	                                                      \
+	if (arg_fmt != NULL) {                                \
+		if (Expand_varargs) {                         \
+			va_start(ap, arg_fmt);                \
+			vsnprintf(buf, buf_len, arg_fmt, ap); \
+			va_end(ap);                           \
+		} else                                        \
+			strncpy(buf, arg_fmt, buf_len);       \
+	} else                                                \
+		buf[0] = '\0';                                \
 }
 
 /*
@@ -300,7 +298,7 @@ void tst_res(int ttype, char *fname, cha
 	       Tst_count, Tst_range); fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	/*
 	 * Save the test result type by ORing ttype into the current exit
@@ -625,7 +623,7 @@ void tst_brk(int ttype, char *fname, voi
 	fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	/*
 	 * Only FAIL, BROK, CONF, and RETR are supported by tst_brk().
@@ -686,7 +684,7 @@ void tst_brkloop(int ttype, char *fname,
 	fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	if (Tst_lpstart < 0 || Tst_lptotal < 0) {
 		tst_print(TCID, 0, 1, TWARN,
@@ -748,7 +746,7 @@ void tst_resm(int ttype, char *arg_fmt, 
 	fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	tst_res(ttype, NULL, "%s", tmesg);
 }
@@ -766,7 +764,7 @@ void tst_brkm(int ttype, void (*func)(vo
 	fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	tst_brk(ttype, NULL, func, "%s", tmesg);
 }
@@ -784,7 +782,7 @@ void tst_brkloopm(int ttype, void (*func
 	fflush(stdout);
 #endif
 
-	EXPAND_VAR_ARGS(arg_fmt, tmesg);
+	EXPAND_VAR_ARGS(tmesg, arg_fmt, USERMESG);
 
 	tst_brkloop(ttype, NULL, func, "%s", tmesg);
 }

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference

_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list