]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: fix crash with invalid command input file
authorStephen Hemminger <stephen@networkplumber.org>
Mon, 18 Dec 2017 17:51:02 +0000 (09:51 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 18 Dec 2017 19:18:55 +0000 (11:18 -0800)
If given an invalid input file with -F flag, ss would crash.
Examples of invalid input are line to long, or null file.

Found by fuzzing with ASAN.

Reported-by:Bug Basher <iamliketohack@gmail.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
misc/ssfilter.y

index ba82b65f712bdfa9b0efdefb4a4457de666925a0..4db3c95faa3ccfb7e1757abc87abcee01962e2f7 100644 (file)
@@ -202,15 +202,23 @@ int yylex(void)
                                argc++;
                        } else if (yy_fp) {
                                while (tokptr == NULL) {
-                                       if (fgets(argbuf, sizeof(argbuf)-1, yy_fp) == NULL)
+                                       size_t len;
+
+                                       if (fgets(argbuf, sizeof(argbuf), yy_fp) == NULL)
                                                return 0;
-                                       argbuf[sizeof(argbuf)-1] = 0;
-                                       if (strlen(argbuf) == sizeof(argbuf) - 1) {
-                                               fprintf(stderr, "Too long line in filter");
+
+                                       len = strnlen(argbuf, sizeof(argbuf));
+                                       if (len == 0) {
+                                               fprintf(stderr, "Invalid line\n");
+                                               exit(-1);
+                                       }
+
+                                       if (len >= sizeof(argbuf) - 1) {
+                                               fprintf(stderr, "Too long line in filter\n");
                                                exit(-1);
                                        }
-                                       if (argbuf[strlen(argbuf)-1] == '\n')
-                                               argbuf[strlen(argbuf)-1] = 0;
+                                       if (argbuf[len - 1] == '\n')
+                                               argbuf[len-1] = 0;
                                        if (argbuf[0] == '#' || argbuf[0] == '0')
                                                continue;
                                        tokptr = argbuf;