From: Jérémie Galarneau Date: Sun, 15 Sep 2019 18:27:40 +0000 (-0400) Subject: sessiond: fix: strncpy called with source length X-Git-Tag: v2.9.13~2 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=567232955c426c82d88c05fc58eb6bcd9cca94cf;p=lttng-tools.git sessiond: fix: strncpy called with source length strncpy is called with the source's length in two cases in the session save code. Use the destination and remaining destination length as intended by the API. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index d2db1edb9..8ef68acf3 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1850,7 +1850,7 @@ int save_session(struct ltt_session *session, struct lttng_save_session_attr *attr, lttng_sock_cred *creds) { int ret, fd = -1; - char config_file_path[PATH_MAX]; + char config_file_path[LTTNG_PATH_MAX]; size_t len; struct config_writer *writer = NULL; size_t session_name_len; @@ -1878,7 +1878,7 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SET_URL; goto end; } - strncpy(config_file_path, provided_path, len); + strncpy(config_file_path, provided_path, sizeof(config_file_path)); } else { ssize_t ret_len; char *home_dir = utils_get_user_home_dir( @@ -1922,7 +1922,7 @@ int save_session(struct ltt_session *session, * was done just above. */ config_file_path[len++] = '/'; - strncpy(config_file_path + len, session->name, session_name_len); + strncpy(config_file_path + len, session->name, sizeof(config_file_path) - len); len += session_name_len; strcpy(config_file_path + len, DEFAULT_SESSION_CONFIG_FILE_EXTENSION); len += sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION);