From: Matthias Kruk Date: Sun, 5 Jan 2020 08:01:19 +0000 (+0900) Subject: sys_debug: Make sure strings are properly NUL-terminated before passing them to dbg_p... X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=2a023d26e3028daafab7013adab737b7a3c341c0;p=corax sys_debug: Make sure strings are properly NUL-terminated before passing them to dbg_printf() --- diff --git a/kernel/core/posixcall.c b/kernel/core/posixcall.c index 289a9ee..7fe4b57 100644 --- a/kernel/core/posixcall.c +++ b/kernel/core/posixcall.c @@ -413,10 +413,10 @@ int sys_debug(const char *str, const u32_t len) process_t *cproc; cproc = process_get_current(); - ret_val = len < sizeof(buffer) ? len : sizeof(buffer); + ret_val = len < (sizeof(buffer) - 1) ? len : (sizeof(buffer) - 1); process_memcpy_ptok(cproc, buffer, str, ret_val); - buffer[sizeof(buffer) - 1] = 0; + buffer[ret_val] = 0; dbg_printf("%s\n", buffer);