diff options
| -rw-r--r-- | lib-src/ChangeLog | 8 | ||||
| -rw-r--r-- | lib-src/hexl.c | 8 | ||||
| -rw-r--r-- | lib-src/make-docfile.c | 13 | ||||
| -rw-r--r-- | lib-src/movemail.c | 3 | ||||
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/emacs.c | 3 | ||||
| -rw-r--r-- | src/frame.c | 11 |
7 files changed, 40 insertions, 11 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 232bb389fd7..74509f4ae5e 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2011-01-23 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Check return values of some library calls. | ||
| 4 | * hexl.c (main): Check fread result. | ||
| 5 | * make-docfile.c (main): Check chdir result. | ||
| 6 | (scan_c_file): Check fscanf result. | ||
| 7 | * movemail.c (main): Check ftruncate result. | ||
| 8 | |||
| 1 | 2011-01-17 Paul Eggert <eggert@cs.ucla.edu> | 9 | 2011-01-17 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 10 | ||
| 3 | Include <unistd.h> unilaterally. | 11 | Include <unistd.h> unilaterally. |
diff --git a/lib-src/hexl.c b/lib-src/hexl.c index aa5b370aade..e0a5166760a 100644 --- a/lib-src/hexl.c +++ b/lib-src/hexl.c | |||
| @@ -179,7 +179,9 @@ main (int argc, char **argv) | |||
| 179 | 179 | ||
| 180 | #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) | 180 | #define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10) |
| 181 | 181 | ||
| 182 | fread (buf, 1, 10, fp); /* skip 10 bytes */ | 182 | /* Skip 10 bytes. */ |
| 183 | if (fread (buf, 1, 10, fp) != 10) | ||
| 184 | break; | ||
| 183 | 185 | ||
| 184 | for (i=0; i < 16; ++i) | 186 | for (i=0; i < 16; ++i) |
| 185 | { | 187 | { |
| @@ -207,7 +209,9 @@ main (int argc, char **argv) | |||
| 207 | if (i < 16) | 209 | if (i < 16) |
| 208 | break; | 210 | break; |
| 209 | 211 | ||
| 210 | fread (buf, 1, 18, fp); /* skip 18 bytes */ | 212 | /* Skip 18 bytes. */ |
| 213 | if (fread (buf, 1, 18, fp) != 18) | ||
| 214 | break; | ||
| 211 | } | 215 | } |
| 212 | } | 216 | } |
| 213 | } | 217 | } |
diff --git a/lib-src/make-docfile.c b/lib-src/make-docfile.c index 4260e4c08f6..b6fccfacfec 100644 --- a/lib-src/make-docfile.c +++ b/lib-src/make-docfile.c | |||
| @@ -158,7 +158,11 @@ main (int argc, char **argv) | |||
| 158 | } | 158 | } |
| 159 | if (argc > i + 1 && !strcmp (argv[i], "-d")) | 159 | if (argc > i + 1 && !strcmp (argv[i], "-d")) |
| 160 | { | 160 | { |
| 161 | chdir (argv[i + 1]); | 161 | if (chdir (argv[i + 1]) != 0) |
| 162 | { | ||
| 163 | perror (argv[i + 1]); | ||
| 164 | return EXIT_FAILURE; | ||
| 165 | } | ||
| 162 | i += 2; | 166 | i += 2; |
| 163 | } | 167 | } |
| 164 | 168 | ||
| @@ -648,6 +652,7 @@ scan_c_file (char *filename, const char *mode) | |||
| 648 | 652 | ||
| 649 | if (defunflag && (commas == 1 || commas == 2)) | 653 | if (defunflag && (commas == 1 || commas == 2)) |
| 650 | { | 654 | { |
| 655 | int scanned = 0; | ||
| 651 | do | 656 | do |
| 652 | c = getc (infile); | 657 | c = getc (infile); |
| 653 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); | 658 | while (c == ' ' || c == '\n' || c == '\r' || c == '\t'); |
| @@ -655,12 +660,14 @@ scan_c_file (char *filename, const char *mode) | |||
| 655 | goto eof; | 660 | goto eof; |
| 656 | ungetc (c, infile); | 661 | ungetc (c, infile); |
| 657 | if (commas == 2) /* pick up minargs */ | 662 | if (commas == 2) /* pick up minargs */ |
| 658 | fscanf (infile, "%d", &minargs); | 663 | scanned = fscanf (infile, "%d", &minargs); |
| 659 | else /* pick up maxargs */ | 664 | else /* pick up maxargs */ |
| 660 | if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ | 665 | if (c == 'M' || c == 'U') /* MANY || UNEVALLED */ |
| 661 | maxargs = -1; | 666 | maxargs = -1; |
| 662 | else | 667 | else |
| 663 | fscanf (infile, "%d", &maxargs); | 668 | scanned = fscanf (infile, "%d", &maxargs); |
| 669 | if (scanned < 0) | ||
| 670 | goto eof; | ||
| 664 | } | 671 | } |
| 665 | } | 672 | } |
| 666 | 673 | ||
diff --git a/lib-src/movemail.c b/lib-src/movemail.c index b127c85951d..f492188963d 100644 --- a/lib-src/movemail.c +++ b/lib-src/movemail.c | |||
| @@ -488,7 +488,8 @@ main (int argc, char **argv) | |||
| 488 | #ifdef MAIL_USE_SYSTEM_LOCK | 488 | #ifdef MAIL_USE_SYSTEM_LOCK |
| 489 | if (! preserve_mail) | 489 | if (! preserve_mail) |
| 490 | { | 490 | { |
| 491 | ftruncate (indesc, 0L); | 491 | if (ftruncate (indesc, 0L) != 0) |
| 492 | pfatal_with_name (inname); | ||
| 492 | } | 493 | } |
| 493 | #endif /* MAIL_USE_SYSTEM_LOCK */ | 494 | #endif /* MAIL_USE_SYSTEM_LOCK */ |
| 494 | 495 | ||
diff --git a/src/ChangeLog b/src/ChangeLog index 06b9e313bd5..fbc1b2175b8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2011-01-23 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-01-23 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | Check return values of some library calls. | ||
| 4 | * emacs.c (main): Check dup result. | ||
| 5 | * frame.c: Include <limits.h>, for INT_MIN and INT_MAX. | ||
| 6 | (frame_name_fnn_p): Check strtol result. | ||
| 7 | |||
| 3 | * image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash | 8 | * image.c (x_create_bitmap_from_xpm_data): Add cast to fix type clash |
| 4 | when calling XpmCreatePixmapFromData. | 9 | when calling XpmCreatePixmapFromData. |
| 5 | 10 | ||
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) | |||
| 912 | emacs_close (0); | 912 | emacs_close (0); |
| 913 | emacs_close (1); | 913 | emacs_close (1); |
| 914 | result = emacs_open (term, O_RDWR, 0); | 914 | result = emacs_open (term, O_RDWR, 0); |
| 915 | if (result < 0) | 915 | if (result < 0 || dup (0) < 0) |
| 916 | { | 916 | { |
| 917 | char *errstring = strerror (errno); | 917 | char *errstring = strerror (errno); |
| 918 | fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring); | 918 | fprintf (stderr, "%s: %s: %s\n", argv[0], term, errstring); |
| 919 | exit (1); | 919 | exit (1); |
| 920 | } | 920 | } |
| 921 | dup (0); | ||
| 922 | if (! isatty (0)) | 921 | if (! isatty (0)) |
| 923 | { | 922 | { |
| 924 | fprintf (stderr, "%s: %s: not a tty\n", argv[0], term); | 923 | 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 <http://www.gnu.org/licenses/>. */ | |||
| 23 | 23 | ||
| 24 | #include <stdio.h> | 24 | #include <stdio.h> |
| 25 | #include <ctype.h> | 25 | #include <ctype.h> |
| 26 | #include <errno.h> | ||
| 27 | #include <limits.h> | ||
| 26 | #include <setjmp.h> | 28 | #include <setjmp.h> |
| 27 | #include "lisp.h" | 29 | #include "lisp.h" |
| 28 | #include "character.h" | 30 | #include "character.h" |
| @@ -2149,10 +2151,13 @@ frame_name_fnn_p (char *str, EMACS_INT len) | |||
| 2149 | if (len > 1 && str[0] == 'F') | 2151 | if (len > 1 && str[0] == 'F') |
| 2150 | { | 2152 | { |
| 2151 | char *end_ptr; | 2153 | char *end_ptr; |
| 2154 | long int n; | ||
| 2155 | errno = 0; | ||
| 2156 | n = strtol (str + 1, &end_ptr, 10); | ||
| 2152 | 2157 | ||
| 2153 | strtol (str + 1, &end_ptr, 10); | 2158 | if (end_ptr == str + len |
| 2154 | 2159 | && INT_MIN <= n && n <= INT_MAX | |
| 2155 | if (end_ptr == str + len) | 2160 | && ((LONG_MIN < n && n < LONG_MAX) || errno != ERANGE)) |
| 2156 | return 1; | 2161 | return 1; |
| 2157 | } | 2162 | } |
| 2158 | return 0; | 2163 | return 0; |