From 4cbd13df3fe0467e39979c809a99c074d0c322c0 Mon Sep 17 00:00:00 2001 From: Jeremias Stotter Date: Sat, 30 Dec 2023 20:12:02 +0100 Subject: [PATCH] Fixed a memory overrun when gradient_count > 8 --- config.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index a53ce48..3af93ee 100644 --- a/config.c +++ b/config.c @@ -129,6 +129,15 @@ bool validate_colors(void *params, void *err) { } if (p->gradient) { + if (p->gradient_count < 2) { + write_errorf(error, "\nAtleast two colors must be given as gradient!\n"); + return false; + } + if (p->gradient_count > 8) { + write_errorf(error, "\nMaximum 8 colors can be specified as gradient!\n"); + return false; + } + for (int i = 0; i < p->gradient_count; i++) { if (!validate_color(p->gradient_colors[i], p, error)) { write_errorf( @@ -182,17 +191,6 @@ bool validate_colors(void *params, void *err) { if (p->bcolor[0] == '#') p->bgcol = 8; // default if invalid - if (p->gradient) { - - if (p->gradient_count < 2) { - write_errorf(error, "\nAtleast two colors must be given as gradient!\n"); - return false; - } - if (p->gradient_count > 8) { - write_errorf(error, "\nMaximum 8 colors can be specified as gradient!\n"); - return false; - } - } return true; }