[PATCH 10/10] psxstat/test.c: Avoid potential string overflow

Joel Sherrill joel at rtems.org
Wed Jun 21 17:52:17 UTC 2017


---
 testsuites/psxtests/psxstat/test.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/testsuites/psxtests/psxstat/test.c b/testsuites/psxtests/psxstat/test.c
index e489180..b616f55 100644
--- a/testsuites/psxtests/psxstat/test.c
+++ b/testsuites/psxtests/psxstat/test.c
@@ -512,16 +512,19 @@ void make_many_symlinks(
   char name2[5];
   char *link_file;
 
+  /* limit the link_count to ensure filename buffer doesn't overflow */
+  rtems_test_assert( link_count < 1000 );
+
   link_file = real_file;
   for (i=1; i < link_count; i++) {
-    sprintf( name1, "%d", i );
+    sprintf( name1, "%04d", i );
     make_a_symlink( link_file, name1 );
     strcpy( name2, name1 );
     link_file = name2;
   }
 
   for (i=1; i < link_count; i++) {
-    sprintf( name1, "%d", i );
+    sprintf( name1, "%04d", i );
     stat_a_file( name1 );
     lstat_a_file( name1 );
   }
-- 
1.8.3.1




More information about the devel mailing list