X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsave.c;h=3c4c3b2bce527045f7c1c9d3c09f00773fd68a07;hb=dc1d59677f2e7686dc33b095663b95eb1ccf89e6;hp=ce9f2f9ff1772910ac5ce1a1b3b8023e566214c9;hpb=e32d7f274604b77bcd83c24994e88df3761ed658;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index ce9f2f9ff..3c4c3b2bc 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -2284,9 +2284,8 @@ static int save_session(struct ltt_session *session, struct lttng_save_session_attr *attr, lttng_sock_cred *creds) { - int ret, fd; - unsigned int file_opened = 0; /* Indicate if the file has been opened */ - char config_file_path[PATH_MAX]; + int ret, fd = -1; + char config_file_path[LTTNG_PATH_MAX]; size_t len; struct config_writer *writer = NULL; size_t session_name_len; @@ -2314,7 +2313,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( @@ -2358,7 +2357,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); @@ -2378,7 +2377,6 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - file_opened = 1; writer = config_writer_create(fd, 1); if (!writer) { @@ -2492,12 +2490,12 @@ end: } if (ret) { /* Delete file in case of error */ - if (file_opened && unlink(config_file_path)) { + if ((fd >= 0) && unlink(config_file_path)) { PERROR("Unlinking XML session configuration."); } } - if (file_opened) { + if (fd >= 0) { ret = close(fd); if (ret) { PERROR("Closing XML session configuration");