From de0fa3bc6423e1cb0c0c66ec02e8cf3facb8e9e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 7 Sep 2010 15:33:56 -0400 Subject: [PATCH] Send terminating nul character when sending strings --- connection.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/connection.c b/connection.c index 2f173b4b..5c6ee2cd 100644 --- a/connection.c +++ b/connection.c @@ -354,7 +354,7 @@ wl_connection_vmarshal(struct wl_connection *connection, break; case 's': s = va_arg(ap, const char *); - length = s ? strlen(s) : 0; + length = s ? strlen(s) + 1: 0; *p++ = length; memcpy(p, s, length); p += DIV_ROUNDUP(length, sizeof(*p)); @@ -459,13 +459,20 @@ wl_connection_demarshal(struct wl_connection *connection, if (length == 0) { closure->values[i].string = NULL; } else { - closure->values[i].string = malloc(length + 1); + closure->values[i].string = malloc(length); if (closure->values[i].string == NULL) { errno = ENOMEM; goto err; } 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; break;