[PATCH 4/4] cpukit/libmisc/dumpbuf/dumpbuf.c: Fix undefined behavior for sprintf().

Joel Sherrill joel.sherrill at oarcorp.com
Tue Sep 1 21:40:54 UTC 2015


Updates #2405.
---
 cpukit/libmisc/dumpbuf/dumpbuf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cpukit/libmisc/dumpbuf/dumpbuf.c b/cpukit/libmisc/dumpbuf/dumpbuf.c
index 9d34d42..36a8656 100644
--- a/cpukit/libmisc/dumpbuf/dumpbuf.c
+++ b/cpukit/libmisc/dumpbuf/dumpbuf.c
@@ -62,18 +62,20 @@ static inline void Dump_Line(
 
   int  i;
   char line_buffer[120];
+  int  len;
 
   line_buffer[0] = '\0';
 
   for( i=0 ; i<length ; i++ )
-    sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] );
+    sprintf( &line_buffer[i*3], "%02x ", buffer[ i ] );
 
   for( ; i<16 ; i++ )
     strcat( line_buffer, "   " );
 
   strcat( line_buffer, "|" );
+  len = strlen( line_buffer );
   for( i=0 ; i<length ; i++ )
-    sprintf( line_buffer, "%s%c", line_buffer,
+    sprintf( &line_buffer[len+i], "%c", 
              isprint( buffer[ i ] ) ? buffer[ i ] : '.' );
 
   for( ; i<16 ; i++ )
-- 
1.8.3.1




More information about the devel mailing list