tmp_fd->state = buf->state;
tmp_fd->max_sb_size = buf->max_sb_size;
strncpy(tmp_fd->path_name, buf->path_name, PATH_MAX);
+ tmp_fd->path_name[PATH_MAX - 1] = '\0';
/* Opening the tracefile in write mode */
ret = open(tmp_fd->path_name,
static char *tracing_group;
static int connected;
+/*
+ * Copy string from src to dst and enforce null terminated byte.
+ */
+static void copy_string(char *dst, const char *src, size_t len)
+{
+ if (src && dst) {
+ strncpy(dst, src, len);
+ /* Enforce the NULL terminated byte */
+ dst[len - 1] = '\0';
+ }
+}
+
/*
* send_data_sessiond
*
/* Are we in the tracing group ? */
ret = check_tracing_group(tracing_group);
if (ret < 0 && getuid() != 0) {
- if (sprintf(sessiond_sock_path, DEFAULT_HOME_CLIENT_UNIX_SOCK,
- getenv("HOME")) < 0) {
+ if (snprintf(sessiond_sock_path, PATH_MAX,
+ DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
return -ENOMEM;
}
} else {
- strncpy(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
- sizeof(DEFAULT_GLOBAL_CLIENT_UNIX_SOCK));
+ copy_string(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ PATH_MAX);
}
return 0;
}
}
-/*
- * Copy string from src to dst and enforce null terminated byte.
- */
-static void copy_string(char *dst, const char *src, size_t len)
-{
- if (src && dst) {
- strncpy(dst, src, len);
- /* Enforce the NULL terminated byte */
- dst[len - 1] = '\0';
- }
-}
-
/*
* Start tracing for all trace of the session.
*/
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
+ sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun));
if (ret < 0) {
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
- strncpy(sun.sun_path, pathname, strlen(pathname));
+ strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
+ sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
/* Unlink the old file if present */
(void) unlink(pathname);
goto error;
}
}
- strncpy(elist[count].name, event, strlen(event));
+ strncpy(elist[count].name, event, LTTNG_SYMBOL_NAME_LEN);
+ elist[count].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
count++;
}
lkm.state = stream->state;
lkm.max_sb_size = channel->channel->attr.subbuf_size;
strncpy(lkm.path_name, stream->pathname, PATH_MAX);
+ lkm.path_name[PATH_MAX - 1] = '\0';
DBG("Sending fd %d to kconsumerd", lkm.fd);
lkm.state = ACTIVE_FD;
lkm.max_sb_size = session->metadata->conf->attr.subbuf_size;
strncpy(lkm.path_name, session->metadata->pathname, PATH_MAX);
+ lkm.path_name[PATH_MAX - 1] = '\0';
ret = lttcomm_send_fds_unix_sock(sock, &lkm, &lkm.fd, 1, sizeof(lkm));
if (ret < 0) {
*/
cds_list_for_each_entry(session, &session_list_ptr->head, list) {
strncpy(sessions[i].path, session->path, PATH_MAX);
+ sessions[i].path[PATH_MAX - 1] = '\0';
strncpy(sessions[i].name, session->name, NAME_MAX);
+ sessions[i].name[NAME_MAX - 1] = '\0';
i++;
}
}
/* Kernel channels */
cds_list_for_each_entry(event, &kchan->events_list.head , list) {
strncpy(events[i].name, event->event->name, LTTNG_SYMBOL_NAME_LEN);
+ events[i].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
events[i].enabled = event->enabled;
switch (event->event->instrumentation) {
case LTTNG_KERNEL_TRACEPOINT:
strncpy(kctx.u.perf_counter.name,
cmd_ctx->lsm->u.context.ctx.u.perf_counter.name,
LTTNG_SYMBOL_NAME_LEN);
+ kctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
/* Add kernel context to kernel tracer. See context.c */
ret = add_kernel_context(cmd_ctx->session->kernel_session, &kctx,
attr->u.kprobe.offset = ev->attr.probe.offset;
strncpy(attr->u.kprobe.symbol_name,
ev->attr.probe.symbol_name, LTTNG_SYM_NAME_LEN);
+ attr->u.kprobe.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0';
break;
case LTTNG_EVENT_FUNCTION:
attr->instrumentation = LTTNG_KERNEL_KRETPROBE;
attr->u.kretprobe.offset = ev->attr.probe.offset;
strncpy(attr->u.kretprobe.symbol_name,
ev->attr.probe.symbol_name, LTTNG_SYM_NAME_LEN);
+ attr->u.kretprobe.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0';
break;
case LTTNG_EVENT_FUNCTION_ENTRY:
attr->instrumentation = LTTNG_KERNEL_FUNCTION;
strncpy(attr->u.ftrace.symbol_name,
ev->attr.ftrace.symbol_name, LTTNG_SYM_NAME_LEN);
+ attr->u.ftrace.symbol_name[LTTNG_SYM_NAME_LEN - 1] = '\0';
break;
case LTTNG_EVENT_TRACEPOINT:
attr->instrumentation = LTTNG_KERNEL_TRACEPOINT;
/* Copy event name */
strncpy(attr->name, ev->name, LTTNG_SYM_NAME_LEN);
+ attr->name[LTTNG_SYM_NAME_LEN - 1] = '\0';
/* Setting up a kernel event */
lke->fd = 0;
if (session->kern_session_count > 0) {
trace.type = KERNEL;
- strncpy(trace.name, "kernel", 6);
+ strncpy(trace.name, "kernel", sizeof(trace.name));
+ trace.name[sizeof(trace.name) - 1] = '\0';
memcpy(&traces[i], &trace, sizeof(trace));
}
}
/* Copy name and type of the event */
strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
+ ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
ret = lttng_disable_event(&dom, event_name, channel_name);
if (ret < 0) {
MSG("Unable to disable event %s for channel %s",
ret = sscanf(opt, "%[^'+']+%s", name, s_hex);
if (ret == 2) {
strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
+ ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
DBG("probe symbol %s", ev->attr.probe.symbol_name);
if (strlen(s_hex) == 0) {
ERR("Invalid probe offset %s", s_hex);
ret = sscanf(opt, "%s", name);
if (ret == 1) {
strncpy(ev->attr.probe.symbol_name, name, LTTNG_SYMBOL_NAME_LEN);
+ ev->attr.probe.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
DBG("probe symbol %s", ev->attr.probe.symbol_name);
ev->attr.probe.offset = 0;
DBG("probe offset %" PRIu64, ev->attr.probe.offset);
event_name, channel_name);
/* Copy name and type of the event */
strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
+ ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
ev.type = opt_event_type;
switch (opt_event_type) {
strncpy(ev.attr.ftrace.symbol_name,
opt_function_entry_symbol,
LTTNG_SYMBOL_NAME_LEN);
+ ev.attr.ftrace.symbol_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
break;
default:
ret = CMD_NOT_IMPLEMENTED;