summaryrefslogtreecommitdiffstats
path: root/color.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-06-27 19:16:20 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-06-27 19:16:44 -0400
commit86da865d82a977c4db084327274912d228f2e9f5 (patch)
tree594796764ecf3469558906345642ab68fdd26db9 /color.c
parent257a7060906a25e299e63a367272251a8dc05b83 (diff)
downloadbfs-86da865d82a977c4db084327274912d228f2e9f5.tar.xz
color: Fix a crash if LS_COLORS ends in *
Diffstat (limited to 'color.c')
-rw-r--r--color.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/color.c b/color.c
index 9806b52..c397050 100644
--- a/color.c
+++ b/color.c
@@ -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;
}