]> git.lttng.org Git - lttng-tools.git/commitdiff
Fix: path: handle truncation in utils_partial_realpath()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 25 Nov 2024 19:49:05 +0000 (19:49 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 25 Nov 2024 19:55:56 +0000 (19:55 +0000)
gcc warns that:
  warning: 'char* strncpy(char*, const char*, size_t)' specified bound 4096 equals destination size [-Wstringop-truncation]

Error-out when snprintf indicates that a truncation occurred.

Change-Id: I8c514da6b0ccb1a59d1555b02bfea2dd3c57febb
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/path.cpp

index c4fb41e233a4f525fd9c9ce58c28a4447dd34ec3..7dfcccc5828ffabfd2df9e5295f60228f0b5855b 100644 (file)
@@ -134,7 +134,12 @@ char *utils_partial_realpath(const char *path)
                }
 
                /* Concatenate the strings */
-               snprintf(resolved_path, LTTNG_PATH_MAX, "%s%s", try_path_prev, cut_path);
+               const auto snprintf_ret =
+                       snprintf(resolved_path, LTTNG_PATH_MAX, "%s%s", try_path_prev, cut_path);
+               if (snprintf_ret >= LTTNG_PATH_MAX) {
+                       ERR("Path exceeded maximal allowed length while determining canonicalized absolute pathname");
+                       goto error;
+               }
 
                /* Free the allocated memory */
                free(cut_path);
This page took 0.028727 seconds and 4 git commands to generate.