Fix: liblttng-ctl: unreported truncations when copying strings
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl-health.c
index 83f092593e84f816d87821217b2aeec8d2712876..c20522bd6b458ac446da3093c79ace48a6f286e6 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <unistd.h>
 #include <sys/types.h>
 #include <stdint.h>
 #include <limits.h>
 #include <errno.h>
+#include <string.h>
 #include <lttng/health-internal.h>
 
 #include <bin/lttng-sessiond/health-sessiond.h>
@@ -70,6 +70,8 @@ const char *sessiond_thread_name[NR_HEALTH_SESSIOND_TYPES] = {
        [ HEALTH_SESSIOND_TYPE_HT_CLEANUP ] = "Session daemon hash table cleanup",
        [ HEALTH_SESSIOND_TYPE_APP_MANAGE_NOTIFY ] = "Session daemon application notification manager",
        [ HEALTH_SESSIOND_TYPE_APP_REG_DISPATCH ] = "Session daemon application registration dispatcher",
+       [ HEALTH_SESSIOND_TYPE_ROTATION ] = "Session daemon rotation manager",
+       [ HEALTH_SESSIOND_TYPE_TIMER ] = "Session daemon timer manager",
 };
 
 static
@@ -101,7 +103,7 @@ const char **thread_name[NR_HEALTH_COMPONENT] = {
 /*
  * Set health socket path.
  *
- * Returns 0 on success or -ENOMEM.
+ * Returns 0 on success or a negative errno.
  */
 static
 int set_health_socket_path(struct lttng_health *lh,
@@ -150,10 +152,10 @@ int set_health_socket_path(struct lttng_health *lh,
        uid = getuid();
 
        if (uid == 0 || tracing_group) {
-               lttng_ctl_copy_string(lh->health_sock_path,
+               ret = lttng_strncpy(lh->health_sock_path,
                                global_str,
                                sizeof(lh->health_sock_path));
-               return 0;
+               return ret == 0 ? 0 : -EINVAL;
        }
 
        /*
@@ -225,20 +227,30 @@ struct lttng_health *
 
 struct lttng_health *lttng_health_create_relayd(const char *path)
 {
-       struct lttng_health *lh;
+       int ret;
+       struct lttng_health *lh = NULL;
 
        if (!path) {
-               return NULL;
+               goto error;
        }
 
        lh = lttng_health_create(HEALTH_COMPONENT_RELAYD,
                        NR_HEALTH_RELAYD_TYPES);
        if (!lh) {
-               return NULL;
+               goto error;
        }
-       lttng_ctl_copy_string(lh->health_sock_path, path,
-               sizeof(lh->health_sock_path));
+
+       ret = lttng_strncpy(lh->health_sock_path, path ?: "",
+                           sizeof(lh->health_sock_path));
+       if (ret) {
+               goto error;
+       }
+
        return lh;
+
+error:
+       free(lh);
+       return NULL;
 }
 
 void lttng_health_destroy(struct lttng_health *lh)
This page took 0.024066 seconds and 4 git commands to generate.