From 9055082ef8a2f1b9033f77f0eb2b9c756a306c01 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 22 Jan 2011 23:30:19 -0800 Subject: Check return values of some library calls. --- src/ChangeLog | 5 +++++ src/emacs.c | 3 +-- src/frame.c | 11 ++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ChangeLog b/src/ChangeLog index 2e9e80d938d..c717b3fe3ee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2011-01-23 Paul Eggert + Check return values of some library calls. + * emacs.c (main): Check dup result. + * frame.c: Include , for INT_MIN and INT_MAX. + (frame_name_fnn_p): Check strtol result. + * image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash when calling XpmCreatePixmapFromData. diff --git a/src/emacs.c b/src/emacs.c index 70dd76d3a3b..9e9989ebbc6 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -912,13 +912,12 @@ main (int argc, char **argv) emacs_close (0); emacs_close (1); result = emacs_open (term, O_RDWR, 0); - if (result < 0) + if (result < 0 || dup (0) < 0) { char *errstring = strerror (errno); fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring); exit (1); } - dup (0); if (! isatty (0)) { fprintf (stderr, "%s: %s: not a tty\n", argv[0], term); diff --git a/src/frame.c b/src/frame.c index 5cbdcf15abf..e663538a840 100644 --- a/src/frame.c +++ b/src/frame.c @@ -23,6 +23,8 @@ along with GNU Emacs. If not, see . */ #include #include +#include +#include #include #include "lisp.h" #include "character.h" @@ -2149,10 +2151,13 @@ frame_name_fnn_p (char *str, EMACS_INT len) if (len > 1 && str[0] == 'F') { char *end_ptr; + long int n; + errno = 0; + n = strtol (str + 1, &end_ptr, 10); - strtol (str + 1, &end_ptr, 10); - - if (end_ptr == str + len) + if (end_ptr == str + len + && INT_MIN <= n && n <= INT_MAX + && ((LONG_MIN < n && n < LONG_MAX) || errno != ERANGE)) return 1; } return 0; -- cgit v1.3