Fix: using putenv() and free()-ing the value is invalid
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 76d087a1e5c90c1198afa870f19be9a4ae526d49..297db20ce062201630bd96ab91f268b79897916b 100644 (file)
@@ -2413,9 +2413,9 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                         * fallback on the 32-bit one,
                         */
                        DBG3("Looking for a kernel consumer at these locations:");
-                       DBG3("  1) %s", config.consumerd64_bin_path.value);
+                       DBG3("  1) %s", config.consumerd64_bin_path.value ? : "NULL");
                        DBG3("  2) %s/%s", INSTALL_BIN_PATH, DEFAULT_CONSUMERD_FILE);
-                       DBG3("  3) %s", config.consumerd32_bin_path.value);
+                       DBG3("  3) %s", config.consumerd32_bin_path.value ? : "NULL");
                        if (stat(config.consumerd64_bin_path.value, &st) == 0) {
                                DBG3("Found location #1");
                                consumer_to_use = config.consumerd64_bin_path.value;
@@ -2442,7 +2442,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                {
                        char *tmpnew = NULL;
 
-                       if (config.consumerd64_lib_dir.value[0] != '\0') {
+                       if (config.consumerd64_lib_dir.value) {
                                char *tmp;
                                size_t tmplen;
 
@@ -2450,20 +2450,18 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                if (!tmp) {
                                        tmp = "";
                                }
-                               tmplen = strlen("LD_LIBRARY_PATH=")
-                                       + strlen(config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp);
+                               tmplen = strlen(config.consumerd64_lib_dir.value) + 1 /* : */ + strlen(tmp);
                                tmpnew = zmalloc(tmplen + 1 /* \0 */);
                                if (!tmpnew) {
                                        ret = -ENOMEM;
                                        goto error;
                                }
-                               strcpy(tmpnew, "LD_LIBRARY_PATH=");
                                strcat(tmpnew, config.consumerd64_lib_dir.value);
                                if (tmp[0] != '\0') {
                                        strcat(tmpnew, ":");
                                        strcat(tmpnew, tmp);
                                }
-                               ret = putenv(tmpnew);
+                               ret = setenv("LD_LIBRARY_PATH", tmpnew, 1);
                                if (ret) {
                                        ret = -errno;
                                        free(tmpnew);
@@ -2476,16 +2474,14 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        "--group", config.tracing_group_name.value,
                                        NULL);
-                       if (config.consumerd64_lib_dir.value[0] != '\0') {
-                               free(tmpnew);
-                       }
+                       free(tmpnew);
                        break;
                }
                case LTTNG_CONSUMER32_UST:
                {
                        char *tmpnew = NULL;
 
-                       if (config.consumerd32_lib_dir.value[0] != '\0') {
+                       if (config.consumerd32_lib_dir.value) {
                                char *tmp;
                                size_t tmplen;
 
@@ -2493,20 +2489,18 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                if (!tmp) {
                                        tmp = "";
                                }
-                               tmplen = strlen("LD_LIBRARY_PATH=")
-                                       + strlen(config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp);
+                               tmplen = strlen(config.consumerd32_lib_dir.value) + 1 /* : */ + strlen(tmp);
                                tmpnew = zmalloc(tmplen + 1 /* \0 */);
                                if (!tmpnew) {
                                        ret = -ENOMEM;
                                        goto error;
                                }
-                               strcpy(tmpnew, "LD_LIBRARY_PATH=");
                                strcat(tmpnew, config.consumerd32_lib_dir.value);
                                if (tmp[0] != '\0') {
                                        strcat(tmpnew, ":");
                                        strcat(tmpnew, tmp);
                                }
-                               ret = putenv(tmpnew);
+                               ret = setenv("LD_LIBRARY_PATH", tmpnew, 1);
                                if (ret) {
                                        ret = -errno;
                                        free(tmpnew);
@@ -2519,14 +2513,12 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
                                        "--consumerd-err-sock", consumer_data->err_unix_sock_path,
                                        "--group", config.tracing_group_name.value,
                                        NULL);
-                       if (config.consumerd32_lib_dir.value[0] != '\0') {
-                               free(tmpnew);
-                       }
+                       free(tmpnew);
                        break;
                }
                default:
-                       PERROR("unknown consumer type");
-                       exit(EXIT_FAILURE);
+                       ERR("unknown consumer type");
+                       errno = 0;
                }
                if (errno != 0) {
                        PERROR("Consumer execl()");
This page took 0.025419 seconds and 4 git commands to generate.