[PATCH v1] Added more error checks when strtol function is used
Imran Zaman
imran.zaman at gmail.com
Wed Nov 5 07:42:20 PST 2014
pushed v3 to patchwork with the change mentioned and marked the older
versions as superceeded
http://patchwork.freedesktop.org/patch/36297/
BR
imran
On Wed, Nov 5, 2014 at 5:27 PM, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> On Tue, 4 Nov 2014 15:55:06 +0200
> Imran Zaman <imran.zaman at gmail.com> wrote:
>
> > Signed-off-by: Imran Zaman <imran.zaman at gmail.com>
> > ---
> > src/scanner.c | 2 +-
> > src/wayland-client.c | 3 ++-
> > 2 files changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/scanner.c b/src/scanner.c
> > index 5e5152b..2ed9775 100644
> > --- a/src/scanner.c
> > +++ b/src/scanner.c
> > @@ -407,7 +407,7 @@ start_element(void *data, const char *element_name,
> const char **atts)
> > if (since != NULL) {
> > 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);
> > } else {
> > diff --git a/src/wayland-client.c b/src/wayland-client.c
> > index b0f77b9..c99dbeb 100644
> > --- a/src/wayland-client.c
> > +++ b/src/wayland-client.c
> > @@ -829,8 +829,9 @@ wl_display_connect(const char *name)
> >
> > connection = getenv("WAYLAND_SOCKET");
> > if (connection) {
> > + errno = 0;
> > fd = strtol(connection, &end, 0);
> > - if (*end != '\0')
> > + if (errno != 0 || connection == end || *end != '\0')
> > return NULL;
> >
> > flags = fcntl(fd, F_GETFD);
>
> If we follow the "don't clobber errno with zero" rule of thumb, here
> you'd need to save errno first, do strtol, and if strtol succeeded,
> restore errno.
>
> Otherwise looks good.
>
>
> Thanks,
> pq
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20141105/a3bf1eb2/attachment.html>
More information about the wayland-devel
mailing list