Fix: missing memset 0 and NULL byte in string
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index 0c91239931ad6125049687ea411fad8c52bddea7..fd6c5d894e6f9a7ef099ba3a01088bb114bd870b 100644 (file)
@@ -1239,6 +1239,7 @@ end_net_output:
                        ret = !output->dst.net.control_isset ?
                                LTTNG_ERR_URL_CTRL_MISS :
                                LTTNG_ERR_URL_DATA_MISS;
+                       free(uri);
                        goto end;
                }
 
@@ -1397,6 +1398,7 @@ 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];
        size_t len;
        struct config_writer *writer = NULL;
@@ -1408,6 +1410,7 @@ int save_session(struct ltt_session *session,
        assert(creds);
 
        session_name_len = strlen(session->name);
+       memset(config_file_path, 0, sizeof(config_file_path));
 
        if (!session_access_ok(session,
                LTTNG_SOCK_GET_UID_CRED(creds),
@@ -1418,6 +1421,7 @@ int save_session(struct ltt_session *session,
 
        provided_path = lttng_save_session_attr_get_output_url(attr);
        if (provided_path) {
+               DBG3("Save session in provided path %s", provided_path);
                len = strlen(provided_path);
                if (len >= sizeof(config_file_path)) {
                        ret = LTTNG_ERR_SET_URL;
@@ -1470,6 +1474,8 @@ int save_session(struct ltt_session *session,
        strncpy(config_file_path + len, session->name, session_name_len);
        len += session_name_len;
        strcpy(config_file_path + len, DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
+       len += sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
+       config_file_path[len] = '\0';
 
        if (!access(config_file_path, F_OK) && !attr->overwrite) {
                /* A file with the same name already exists, skip */
@@ -1484,6 +1490,7 @@ int save_session(struct ltt_session *session,
                ret = LTTNG_ERR_SAVE_IO_FAIL;
                goto end;
        }
+       file_opened = 1;
 
        writer = config_writer_create(fd);
        if (!writer) {
@@ -1578,7 +1585,7 @@ end:
        }
        if (ret) {
                /* Delete file in case of error */
-               if (unlink(config_file_path)) {
+               if (file_opened && unlink(config_file_path)) {
                        PERROR("Unlinking XML session configuration.");
                }
        }
This page took 0.025354 seconds and 4 git commands to generate.