scanner, client: Added more error checks when strtol function is used

Signed-off-by: Imran Zaman <imran.zaman@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Imran Zaman 2014-11-05 17:40:18 +02:00 committed by Bryce Harrington
parent ca0ee83157
commit 3170fdfbc3
2 changed files with 7 additions and 2 deletions

View file

@ -404,11 +404,13 @@ start_element(void *data, const char *element_name, const char **atts)
message->destructor = 0;
if (since != NULL) {
int prev_errno = errno;
errno = 0;
version = strtol(since, &end, 0);
if (errno == EINVAL || end == since || *end != '\0')
if (errno != 0 || end == since || *end != '\0')
fail(&ctx->loc,
"invalid integer (%s)\n", since);
errno = prev_errno;
} else {
version = 1;
}

View file

@ -829,9 +829,12 @@ wl_display_connect(const char *name)
connection = getenv("WAYLAND_SOCKET");
if (connection) {
int prev_errno = errno;
errno = 0;
fd = strtol(connection, &end, 0);
if (*end != '\0')
if (errno != 0 || connection == end || *end != '\0')
return NULL;
errno = prev_errno;
flags = fcntl(fd, F_GETFD);
if (flags != -1)