Skip to contentSkip to conversation

mtd-utils: tests: jittertest: reject overlong file names

PATCH Applied Aviv Daum 2 participants 2 messages Mar 18 – Apr 13

Subsystems (2)
lore
Share & tools
lore

Aviv Daum

author
#0 lore raw

PATCH 1/1 mtd-utils: tests: jittertest: reject overlong file names

plotJittervsFill copies the -f argument into a 250-byte buffer with strncpy(..., sizeof(LogFile)). A 250-byte file name leaves the buffer unterminated, and the subsequent fopen() reads past the end of LogFile.

JitterTest uses the same fixed-size file name pattern for -r, while -c still silently truncates overlong names and -f already rejects them.

Validate jittertest file name arguments before copying them so these options all reject overlong input instead of truncating it or reading past the end of fixed-size buffers.

Add a shell regression test that exercises the accepted and rejected boundary lengths for plotJittervsFill and JitterTest during make check.

---
 Makefile.am                            |   3 +
 configure.ac                           |   1 +
 tests/jittertest/JitterTest.c          |  52 +++++++----
 tests/jittertest/Makemodule.am         |   6 +-
 tests/jittertest/filename_bounds.sh.in | 115 +++++++++++++++++++++++++
 tests/jittertest/plotJittervsFill.c    |  17 +++-
 6 files changed, 175 insertions(+), 19 deletions(-)
 create mode 100755 tests/jittertest/filename_bounds.sh.in
Makefile.am +3 -0
index c756127..ba54acc 100644
@@ -42,6 +42,9 @@ test_SCRIPTS =
 test_DATA =
 
 TESTS =
+TEST_EXTENSIONS = .sh
+SH_LOG_COMPILER = $(SHELL)
+AM_TESTS_ENVIRONMENT = TESTBINDIR='$(abs_top_builddir)'; export TESTBINDIR;
 EXTRA_DIST = COPYING CHANGELOG.md README.txt
 
 include lib/Makemodule.am
configure.ac +1 -0
index 2a79ba8..f17d703 100644
@@ -304,6 +304,7 @@ AC_CONFIG_FILES([tests/fs-tests/fs_help_all.sh
 	tests/fs-tests/fs_run_all.sh
 	tests/fs-tests/stress/fs_stress00.sh
 	tests/fs-tests/stress/fs_stress01.sh
+	tests/jittertest/filename_bounds.sh
 	tests/ubi-tests/runubitests.sh
 	tests/ubi-tests/ubi-stress-test.sh
 	tests/ubifs_tools-tests/lib/common.sh
tests/jittertest/JitterTest.c +36 -16

87 lines not on this page · raw message

tests/jittertest/Makemodule.am +4 -2
index d280192..2cb85c1 100644
@@ -6,6 +6,8 @@ plotJittervsFill_CPPFLAGS = $(AM_CPPFLAGS)
 
 test_PROGRAMS += JitterTest plotJittervsFill
 
-test_SCRIPTS += tests/jittertest/filljffs2.sh
+test_SCRIPTS += tests/jittertest/filljffs2.sh tests/jittertest/filename_bounds.sh
+TESTS += tests/jittertest/filename_bounds.sh
 
-EXTRA_DIST += tests/jittertest/README tests/jittertest/filljffs2.sh
+EXTRA_DIST += tests/jittertest/README tests/jittertest/filljffs2.sh \
+	tests/jittertest/filename_bounds.sh.in
tests/jittertest/filename_bounds.sh.in new file +115 -0

115 lines not on this page · raw message

tests/jittertest/plotJittervsFill.c +16 -1
index 03929a9..8929f9a 100644
@@ -75,6 +75,21 @@ static int Debug = 0; /* Debug level. Each "-d" on the cmd line increases the le
 
 #define MIN_JITTER_THRESHOLD 1 /* ms minimum jitter threshold */
 
+static void SetLogFileName(
+    const char *pFileName)          /* ptr to desired input file name   */
+{
+    size_t fileNameLen;             /* file name length (bytes)         */
+
+    fileNameLen = strlen(pFileName);
+    if (fileNameLen > sizeof(LogFile) - 1) {
+        printf("File name %s exceeds maximum length %d.\n",
+               pFileName, (int)(sizeof(LogFile) - 1));
+        exit(0);
+    }
+
+    strcpy(LogFile, pFileName);
+}
+
 static void PrintHelpInfo(void)
 {
     printf("Usage: plotJittervsFill [options] -f [--file] <input log file name> -t [--jitter_threshold] <jitter threshold in ms>\n");
@@ -122,7 +137,7 @@ static void HandleCmdLineArgs(
                 /* Set the name of the output file. */
                 ++argNum;
                 if (argNum < argc) {
-                    strncpy(LogFile, argv[argNum], sizeof(LogFile));
+                    SetLogFileName(argv[argNum]);
                 }
                 else {
                     printf("*** Input file name not specified. ***\n");
Signature · 6 lines
2.34.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/