[PATCH weston 2/3] xwayland: Improve error checking for strtol call

Bryce Harrington bryce at osg.samsung.com
Wed Jul 13 04:16:32 UTC 2016


This updates the error checking for the strtol() call in xwayland's
create_lockfile to match other cases.  C.f. cbc05378 and other recent
patches.

A notable difference here is that the existing error checking was
verifying that exactly 10 digits were being read from the lock file,
but the fact that it's 10 digits is just an implementation detail for
how we're writing it.  The pid could be a shorter number of digits, and
would just be space-padded on the left.

This change allows the file to contain any number of digits, but it
can't be blank, all of the digits must be numeric, and the resulting
number must be within the accepted range.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 xwayland/launcher.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/xwayland/launcher.c b/xwayland/launcher.c
index b7aee3b..5b81fef 100644
--- a/xwayland/launcher.c
+++ b/xwayland/launcher.c
@@ -164,8 +164,9 @@ create_lockfile(int display, char *lockfile, size_t lsize)
 			return -1;
 		}
 
+		errno = 0;
 		other = strtol(pid, &end, 10);
-		if (end != pid + 10) {
+		if (errno != 0 || end == pid || *end != '\0') {
 			weston_log("can't parse lock file %s\n",
 				lockfile);
 			close(fd);
-- 
1.9.1



More information about the wayland-devel mailing list