]> 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:53:57 +0000 (19:53 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 25 Nov 2024 19:56:01 +0000 (19:56 +0000)
gcc warns that:
  warning: 'char* strncpy(char*, const char*, size_t)' specified bound 4096 equals destination size [-Wstringop-truncation]

Return an error when lttng_strncpy reports that a truncation occurred.

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

index 7dfcccc5828ffabfd2df9e5295f60228f0b5855b..46a333b4527f1cf78a57dfa54566836091271211 100644 (file)
@@ -151,7 +151,10 @@ char *utils_partial_realpath(const char *path)
                 * return it as is
                 */
        } else {
-               strncpy(resolved_path, path, LTTNG_PATH_MAX);
+               const auto strncpy_ret = lttng_strncpy(resolved_path, path, LTTNG_PATH_MAX);
+               if (strncpy_ret) {
+                       goto error;
+               }
        }
 
        /* Then we return the 'partially' resolved path */
@@ -164,6 +167,7 @@ error:
        if (try_path_prev != try_path) {
                free(try_path_prev);
        }
+
        return nullptr;
 }
 
This page took 0.028791 seconds and 4 git commands to generate.