X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsyscall.c;h=6ee38bd0fa27a3f51c5541f8601a890d130b8aed;hp=b4f2e1eca92f2fb726aa774f8bc94f384bc2f000;hb=ab0ee2ca29394fa28284b94cc3c598960660404f;hpb=1f47715a589b81c62de8fd49a342bf4cf4be770a diff --git a/src/bin/lttng-sessiond/syscall.c b/src/bin/lttng-sessiond/syscall.c index b4f2e1eca..6ee38bd0f 100644 --- a/src/bin/lttng-sessiond/syscall.c +++ b/src/bin/lttng-sessiond/syscall.c @@ -15,7 +15,7 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -51,7 +51,7 @@ int syscall_init_table(void) fd = kernctl_syscall_list(kernel_tracer_fd); if (fd < 0) { - ret = -errno; + ret = fd; PERROR("kernelctl syscall list"); goto error_ioctl; } @@ -72,7 +72,7 @@ int syscall_init_table(void) } while (fscanf(fp, - "syscall { index = %lu; \ + "syscall { index = %zu; \ name = %" XSTR(SYSCALL_NAME_LEN) "[^;]; \ bitness = %u; };\n", &index, name, &bitness) == 3) { @@ -82,7 +82,7 @@ int syscall_init_table(void) /* Double memory size. */ new_nbmem = max(index, nbmem << 1); - if (new_nbmem < nbmem) { + if (new_nbmem > (SIZE_MAX / sizeof(*new_list))) { /* Overflow, stop everything, something went really wrong. */ ERR("Syscall listing memory size overflow. Stopping"); free(syscall_table); @@ -108,8 +108,13 @@ int syscall_init_table(void) } syscall_table[index].index = index; syscall_table[index].bitness = bitness; - strncpy(syscall_table[index].name, name, - sizeof(syscall_table[index].name)); + if (lttng_strncpy(syscall_table[index].name, name, + sizeof(syscall_table[index].name))) { + ret = -EINVAL; + free(syscall_table); + syscall_table = NULL; + goto error; + } /* DBG("Syscall name '%s' at index %" PRIu32 " of bitness %u", syscall_table[index].name, @@ -333,102 +338,3 @@ error: rcu_read_unlock(); return ret; } - -/* - * Add enabled syscall to the events list using the given kernel channel. - * - * Return the number of entry of the events array that is different from size - * if the array grows. On error, return negative value and events is untouched. - */ -ssize_t syscall_list_channel(struct ltt_kernel_channel *kchan, - struct lttng_event **_events, size_t size) -{ - int err, i; - size_t new_size; - ssize_t ret, count; - char *mask = NULL; - uint32_t len; - struct lttng_event *events = NULL; - /* Hash table used to filter duplicate out. */ - struct lttng_ht *syscalls_ht = NULL; - - assert(kchan); - - /* Get syscall mask from the kernel tracer. */ - err = kernel_syscall_mask(kchan->fd, &mask, &len); - if (err < 0) { - ret = err; - goto error; - } - - ret = init_syscall_ht(&syscalls_ht); - if (ret < 0) { - goto error; - } - - count = new_size = size; - events = *_events; - - for (i = 0; i < len; i++) { - unsigned char val; - struct syscall *ksyscall; - - bitfield_read_be(mask, unsigned char, i, 1, &val); - if (!val) { - /* Syscall is disabled, continue the loop. */ - continue; - } - - /* Skip empty syscall. */ - if (*syscall_table[i].name == '\0') { - continue; - } - - /* Syscall is enabled thus add it to the events list. */ - - if (count >= new_size) { - struct lttng_event *new_events; - - /* Get the maximum here since count can be 0. */ - new_size = max(count << 1, 1); - DBG3("Listing syscall realloc events array from %zu to %zu", count, - new_size); - new_events = realloc(events, new_size * sizeof(*new_events)); - if (!new_events) { - PERROR("realloc kernel events list"); - ret = -ENOMEM; - goto error; - } - memset(new_events + count, 0, - (new_size - count) * sizeof(*new_events)); - events = new_events; - } - - ksyscall = lookup_syscall(syscalls_ht, syscall_table[i].name); - if (ksyscall) { - update_event_syscall_bitness(events, i, ksyscall->index); - continue; - } - - ret = add_syscall_to_ht(syscalls_ht, i, count); - if (ret < 0) { - goto error; - } - - update_event_syscall_bitness(events, i, count); - strncpy(events[count].name, syscall_table[i].name, - sizeof(events[count].name)); - events[count].enabled = 1; - events[count].type = LTTNG_KERNEL_SYSCALL; - count++; - } - - *_events = events; - - return count; - -error: - destroy_syscall_ht(syscalls_ht); - free(events); - return ret; -}