From b3312002a5d96cd486156a711d3c1861c150b7c6 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sun, 4 Oct 2020 13:22:23 -0400 Subject: parse: Fail if -color is passed and the colors couldn't be parsed --- parse.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'parse.c') diff --git a/parse.c b/parse.c index fadf0c5..c0c345c 100644 --- a/parse.c +++ b/parse.c @@ -962,7 +962,13 @@ static struct expr *parse_capable(struct parser_state *state, int flag, int arg2 static struct expr *parse_color(struct parser_state *state, int color, int arg2) { struct bfs_ctx *ctx = state->ctx; struct colors *colors = ctx->colors; + if (color) { + if (!colors) { + parse_error(state, "${blu}%s${rs}: %s.\n", state->argv[0], strerror(ctx->colors_error)); + return NULL; + } + state->use_color = COLOR_ALWAYS; ctx->cout->colors = colors; ctx->cerr->colors = colors; @@ -971,6 +977,7 @@ static struct expr *parse_color(struct parser_state *state, int color, int arg2) ctx->cout->colors = NULL; ctx->cerr->colors = NULL; } + return parse_nullary_option(state); } @@ -3479,6 +3486,9 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { } ctx->colors = parse_colors(getenv("LS_COLORS")); + if (!ctx->colors) { + ctx->colors_error = errno; + } ctx->cout = cfdup(stdout, use_color ? ctx->colors : NULL); if (!ctx->cout) { -- cgit v1.2.3