Browse Source

* more checks in f2b_cmsg_extract_args()

master
Alex 'AdUser' Z 8 years ago
parent
commit
3fb9dc9d05
  1. 6
      src/cmsg.c
  2. 8
      t/t_cmsg.c

6
src/cmsg.c

@ -21,6 +21,12 @@ f2b_cmsg_extract_args(const f2b_cmsg_t *msg, const char **argv) {
assert(msg != NULL);
assert(argv != NULL);
if (msg->size == 0)
return 0; /* no args */
if (msg->data[msg->size - 1] != '\0')
return -1; /* message data not null-terminated */
for (size_t i = 0; i < msg->size; i++) {
if (prev == '\0' && msg->data[i] != '\0')
argv[argc] = &msg->data[i], argc++;

8
t/t_cmsg.c

@ -20,5 +20,13 @@ int main() {
assert(memcmp(argv[0], "test1\0", 6) == 0);
assert(memcmp(argv[1], "test2\0", 6) == 0);
/* data not null-terminated */
msg.size = 10;
memcpy(msg.data, "test1\0test2\n", 10);
assert(f2b_cmsg_extract_args(&msg, argv) == -1);
msg.size = 0;
assert(f2b_cmsg_extract_args(&msg, argv) == 0);
return EXIT_SUCCESS;
}

Loading…
Cancel
Save