- /* Copy channel name and normalize it */
- strncpy(chan.name, channel_name, NAME_MAX);
- chan.name[NAME_MAX - 1] = '\0';
+ /* Validate channel name's length */
+ if (strlen(channel_name) >= NAME_MAX) {
+ ERR("Channel name is too long (max. %zu characters)",
+ sizeof(chan.name) - 1);
+ ret = LTTNG_ERR_INVALID_CHANNEL_NAME;
+ goto error;
+ }
+
+ /* Copy channel name */
+ strcpy(chan.name, channel_name);