From: Jérémie Galarneau Date: Mon, 16 Jan 2023 19:19:20 +0000 (-0500) Subject: Fix: ini parser: truncation of value name X-Git-Tag: v2.13.10~13 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6415838fffb8294e0f8b5230449b260ea5eb1c38 Fix: ini parser: truncation of value name clang 14 reports the following: ini-config/ini.cpp:88:16: warning: 'char* strncpy(char*, const char*, size_t)' output may be truncated copying 49 bytes from a string of length 199 [-Wstringop-truncation] 88 | strncpy(dest, src, size - 1); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~ Indeed, a silent truncation of `name` occurs whenever it is longer than prev_name (49 characters, excluding the terminator). Report an error when this condition occurs. Signed-off-by: Jérémie Galarneau Change-Id: I973bd27185e0130d8e4a452525d9277de45ba200 --- diff --git a/src/common/config/ini.c b/src/common/config/ini.c index 826d9afa3..c8cf307aa 100644 --- a/src/common/config/ini.c +++ b/src/common/config/ini.c @@ -182,6 +182,10 @@ int ini_parse_file(FILE* file, ini_entry_handler handler, void* user) * Valid name[=:]value pair found, call * handler */ + if (strlen(name) >= sizeof(prev_name)) { + /* Truncation occurs, report an error. */ + error = lineno; + } strncpy0(prev_name, name, sizeof(prev_name)); if (handler(user, section, name, value) < 0 && !error) {