diff options
-rw-r--r-- | color.c | 15 | ||||
-rwxr-xr-x | tests.sh | 6 | ||||
-rw-r--r-- | tests/test_color_star.out | 20 |
3 files changed, 36 insertions, 5 deletions
@@ -222,9 +222,13 @@ static const char *get_ext_color(const struct colors *colors, const char *filena * The parsed chunk as a dstring. */ static char *unescape(const char *value, char end, const char **next) { + if (!value) { + goto fail; + } + char *str = dstralloc(0); if (!str) { - goto fail; + goto fail_str; } const char *i; @@ -301,7 +305,7 @@ static char *unescape(const char *value, char end, const char **next) { break; case '\0': - goto fail; + goto fail_str; default: c = *i; @@ -315,7 +319,7 @@ static char *unescape(const char *value, char end, const char **next) { c = '\177'; break; case '\0': - goto fail; + goto fail_str; default: // CTRL masks bits 6 and 7 c = *i & 0x1F; @@ -329,7 +333,7 @@ static char *unescape(const char *value, char end, const char **next) { } if (dstrapp(&str, c) != 0) { - goto fail; + goto fail_str; } } @@ -341,8 +345,9 @@ static char *unescape(const char *value, char end, const char **next) { return str; -fail: +fail_str: dstrfree(str); +fail: *next = NULL; return NULL; } @@ -617,6 +617,7 @@ bfs_tests=( test_color_missing_colon test_color_no_stat test_color_L_no_stat + test_color_star test_execdir_plus @@ -2099,6 +2100,11 @@ function test_color_L_no_stat() { LS_COLORS="mh=0:ex=0:sg=0:su=0:st=0:ow=0:tw=0:*.txt=01:" bfs_diff -L rainbow -color } +function test_color_star() { + # Regression test: don't segfault on LS_COLORS="*" + LS_COLORS="*" bfs_diff rainbow -color +} + function test_deep() { closefrom 4 diff --git a/tests/test_color_star.out b/tests/test_color_star.out new file mode 100644 index 0000000..77fc8a8 --- /dev/null +++ b/tests/test_color_star.out @@ -0,0 +1,20 @@ +[01;34mrainbow[0m +[01;34mrainbow/[0m[01;32mexec.sh[0m +[01;34mrainbow/[0m[01;35msocket[0m +[01;34mrainbow/[0m[01;36mbroken[0m +[01;34mrainbow/[0m[01;36mchardev_link[0m +[01;34mrainbow/[0m[01;36mlink.txt[0m +[01;34mrainbow/[0m[30;42msticky_ow[0m +[01;34mrainbow/[0m[30;43msgid[0m +[01;34mrainbow/[0m[33mpipe[0m +[01;34mrainbow/[0m[34;42mow[0m +[01;34mrainbow/[0m[37;41msugid[0m +[01;34mrainbow/[0m[37;41msuid[0m +[01;34mrainbow/[0m[37;44msticky[0m +[01;34mrainbow/[0mfile.dat +[01;34mrainbow/[0mfile.txt +[01;34mrainbow/[0mmh1 +[01;34mrainbow/[0mmh2 +[01;34mrainbow/[0mstar.gz +[01;34mrainbow/[0mstar.tar +[01;34mrainbow/[0mstar.tar.gz |