[rtems commit] psxstat/test.c: Avoid potential string overflow

Joel Sherrill joel at rtems.org
Thu Jun 22 14:04:33 UTC 2017


Module:    rtems
Branch:    master
Commit:    b8b4b7d429b4a1091800891e02cf9e1605c2e60d
Changeset: http://git.rtems.org/rtems/commit/?id=b8b4b7d429b4a1091800891e02cf9e1605c2e60d

Author:    Joel Sherrill <joel at rtems.org>
Date:      Thu Jun 15 12:42:59 2017 -0500

psxstat/test.c: Avoid potential string overflow

---

 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 );
   }



More information about the vc mailing list