[PATCH v2] Added more error checks when strtol function is used

Imran Zaman imran.zaman at gmail.com
Wed Nov 5 07:35:38 PST 2014


Signed-off-by: Imran Zaman <imran.zaman at gmail.com>
---
 src/scanner.c        | 5 ++++-
 src/wayland-client.c | 6 +++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/scanner.c b/src/scanner.c
index 5e5152b..9ba34e8 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -405,9 +405,12 @@ start_element(void *data, const char *element_name, const char **atts)
 			message->destructor = 0;
 
 		if (since != NULL) {
+			int prev_errno = errno, new_errno;
 			errno = 0;
 			version = strtol(since, &end, 0);
-			if (errno == EINVAL || end == since || *end != '\0')
+			new_errno = errno;
+			errno = prev_errno;
+			if (new_errno != 0 || end == since || *end != '\0')
 				fail(&ctx->loc,
 				     "invalid integer (%s)\n", since);
 		} else {
diff --git a/src/wayland-client.c b/src/wayland-client.c
index b0f77b9..f4f559e 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -829,8 +829,12 @@ wl_display_connect(const char *name)
 
 	connection = getenv("WAYLAND_SOCKET");
 	if (connection) {
+		int prev_errno = errno, new_errno;
+		errno = 0;
 		fd = strtol(connection, &end, 0);
-		if (*end != '\0')
+		new_errno = errno;
+		errno = prev_errno;
+		if (new_errno != 0 || connection == end || *end != '\0')
 			return NULL;
 
 		flags = fcntl(fd, F_GETFD);
-- 
1.9.1



More information about the wayland-devel mailing list