From f65d5ce4187ee0889ac89d3dcc14559e090a2059 Mon Sep 17 00:00:00 2001 From: 0x35c Date: Fri, 27 Sep 2024 12:03:52 +0200 Subject: [PATCH] fix: strcmp protection with NULL args --- libbozo/src/string/strcmp.c | 2 ++ src/shell/commands/color_cmd.c | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libbozo/src/string/strcmp.c b/libbozo/src/string/strcmp.c index 616ffd1..4456800 100644 --- a/libbozo/src/string/strcmp.c +++ b/libbozo/src/string/strcmp.c @@ -4,6 +4,8 @@ int strcmp(const char *s1, const char *s2) { size_t i = 0; + if (!s1 || !s2) + return -1; while (s1[i] == s2[i] && s1[i] != '\0') i++; return s1[i] - s2[i]; diff --git a/src/shell/commands/color_cmd.c b/src/shell/commands/color_cmd.c index 759401c..049fd04 100644 --- a/src/shell/commands/color_cmd.c +++ b/src/shell/commands/color_cmd.c @@ -1,10 +1,9 @@ #include "kprintf.h" #include "string.h" #include "terminal.h" +#include "utils.h" #include -#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0]) - void color_cmd(char *arg) { uint8_t tmp_color; @@ -21,16 +20,14 @@ void color_cmd(char *arg) } } tmp_color = terminal_get_default_color(); - kprintf(KERN_WARNING "Invalid argument\navailable color: "); + kprintf(KERN_WARNING "Invalid argument\n"); + kprintf("Available colors: "); for (size_t i = 0; i < ARRAY_SIZE(colors); i++) { terminal_set_default_fg_color(i); - // Unai the STRING MERGE argument of kprintf cause me a - // cramptissue. I lost all my skibidi aura to fix it but it work - // (; kprintf(colors[i]); if (i != ARRAY_SIZE(colors) - 1) kprintf(", "); } terminal_set_default_fg_color(tmp_color); kprintf("\n"); -} \ No newline at end of file +}