[PATCH v3] Added more error checks when strtol function is used
Pekka Paalanen
ppaalanen at gmail.com
Mon Nov 10 05:27:15 PST 2014
On Wed, 5 Nov 2014 17:40:18 +0200
Imran Zaman <imran.zaman at gmail.com> wrote:
> Signed-off-by: Imran Zaman <imran.zaman at gmail.com>
> ---
> src/scanner.c | 4 +++-
> src/wayland-client.c | 5 ++++-
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/scanner.c b/src/scanner.c
> index 5e5152b..fa8e0c0 100644
> --- a/src/scanner.c
> +++ b/src/scanner.c
> @@ -405,11 +405,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;
> }
This is not a library function, so restoring errno here is not
required, but ok.
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index b0f77b9..01629e0 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -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)
Nice, pushed.
Thanks,
pq
More information about the wayland-devel
mailing list