Send terminating nul character when sending strings

dev
Kristian Høgsberg 14 years ago
parent 9f897988fd
commit de0fa3bc64
  1. 13
      connection.c

@ -354,7 +354,7 @@ wl_connection_vmarshal(struct wl_connection *connection,
break; break;
case 's': case 's':
s = va_arg(ap, const char *); s = va_arg(ap, const char *);
length = s ? strlen(s) : 0; length = s ? strlen(s) + 1: 0;
*p++ = length; *p++ = length;
memcpy(p, s, length); memcpy(p, s, length);
p += DIV_ROUNDUP(length, sizeof(*p)); p += DIV_ROUNDUP(length, sizeof(*p));
@ -459,13 +459,20 @@ wl_connection_demarshal(struct wl_connection *connection,
if (length == 0) { if (length == 0) {
closure->values[i].string = NULL; closure->values[i].string = NULL;
} else { } else {
closure->values[i].string = malloc(length + 1); closure->values[i].string = malloc(length);
if (closure->values[i].string == NULL) { if (closure->values[i].string == NULL) {
errno = ENOMEM; errno = ENOMEM;
goto err; goto err;
} }
memcpy(closure->values[i].string, p, length); memcpy(closure->values[i].string, p, length);
closure->values[i].string[length] = '\0'; if (closure->values[i].string[length - 1] != '\0') {
printf("string not nul-terminated, "
"message %s(%s)\n",
message->name,
message->signature);
errno = EINVAL;
goto err;
}
} }
p = next; p = next;
break; break;

Loading…
Cancel
Save