lineedit: do not tab-complete any strings which have control characters
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 7 Nov 2017 17:09:29 +0000 (18:09 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Wed, 8 Nov 2017 11:35:02 +0000 (12:35 +0100)
function                                             old     new   delta
add_match                                             41      68     +27

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/lineedit.c

index c0e35bb2160e3bccee775bb159f7e94bb68f5cf8..56e81404e0e032b1e53852dc4ddaacd622ec410a 100644 (file)
@@ -645,6 +645,18 @@ static void free_tab_completion_data(void)
 
 static void add_match(char *matched)
 {
+       unsigned char *p = (unsigned char*)matched;
+       while (*p) {
+               /* ESC attack fix: drop any string with control chars */
+               if (*p < ' '
+                || (!ENABLE_UNICODE_SUPPORT && *p >= 0x7f)
+                || (ENABLE_UNICODE_SUPPORT && *p == 0x7f)
+               ) {
+                       free(matched);
+                       return;
+               }
+               p++;
+       }
        matches = xrealloc_vector(matches, 4, num_matches);
        matches[num_matches] = matched;
        num_matches++;