diff options
| author | Paul Eggert | 2011-07-28 14:38:23 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-28 14:38:23 -0700 |
| commit | b4fb63147af14661b28c59d07987f8306deb5ed1 (patch) | |
| tree | d08ec36b66ae41e36f8004f2e196c85372ba0d84 /src | |
| parent | c9f8d652ab67b148cd0a1cb375b0e51e673c4094 (diff) | |
| download | emacs-b4fb63147af14661b28c59d07987f8306deb5ed1.tar.gz emacs-b4fb63147af14661b28c59d07987f8306deb5ed1.zip | |
* emacs.c (main, sort_args): Check for size-calculation overflow.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 2 | ||||
| -rw-r--r-- | src/emacs.c | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b823dd54498..52f1a76e54c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-07-28 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * emacs.c (main, sort_args): Check for size-calculation overflow. | ||
| 4 | |||
| 3 | * editfns.c: Integer and memory overflow fixes. | 5 | * editfns.c: Integer and memory overflow fixes. |
| 4 | (set_time_zone_rule): Don't assume environment length fits in int. | 6 | (set_time_zone_rule): Don't assume environment length fits in int. |
| 5 | (message_length): Now ptrdiff_t, not int. | 7 | (message_length): Now ptrdiff_t, not int. |
diff --git a/src/emacs.c b/src/emacs.c index 39870ec0079..4de567a5588 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -1360,9 +1360,12 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1360 | This requires inserting a new element into argv. */ | 1360 | This requires inserting a new element into argv. */ |
| 1361 | if (displayname != 0 && skip_args - count_before == 1) | 1361 | if (displayname != 0 && skip_args - count_before == 1) |
| 1362 | { | 1362 | { |
| 1363 | char **new = (char **) xmalloc (sizeof (char *) * (argc + 2)); | 1363 | char **new; |
| 1364 | int j; | 1364 | int j; |
| 1365 | 1365 | ||
| 1366 | if (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (char *) - 2 < argc) | ||
| 1367 | memory_full (SIZE_MAX); | ||
| 1368 | new = (char **) xmalloc (sizeof *new * argc + sizeof *new * 2); | ||
| 1366 | for (j = 0; j < count_before + 1; j++) | 1369 | for (j = 0; j < count_before + 1; j++) |
| 1367 | new[j] = argv[j]; | 1370 | new[j] = argv[j]; |
| 1368 | new[count_before + 1] = (char *) "-d"; | 1371 | new[count_before + 1] = (char *) "-d"; |
| @@ -1838,13 +1841,19 @@ sort_args (int argc, char **argv) | |||
| 1838 | 0 for an option that takes no arguments, | 1841 | 0 for an option that takes no arguments, |
| 1839 | 1 for an option that takes one argument, etc. | 1842 | 1 for an option that takes one argument, etc. |
| 1840 | -1 for an ordinary non-option argument. */ | 1843 | -1 for an ordinary non-option argument. */ |
| 1841 | int *options = (int *) xmalloc (sizeof (int) * argc); | 1844 | int *options; |
| 1842 | int *priority = (int *) xmalloc (sizeof (int) * argc); | 1845 | int *priority; |
| 1843 | int to = 1; | 1846 | int to = 1; |
| 1844 | int incoming_used = 1; | 1847 | int incoming_used = 1; |
| 1845 | int from; | 1848 | int from; |
| 1846 | int i; | 1849 | int i; |
| 1847 | 1850 | ||
| 1851 | if (sizeof (char *) < sizeof (int) | ||
| 1852 | && min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < argc) | ||
| 1853 | memory_full (SIZE_MAX); | ||
| 1854 | options = (int *) xmalloc (sizeof (int) * argc); | ||
| 1855 | priority = (int *) xmalloc (sizeof (int) * argc); | ||
| 1856 | |||
| 1848 | /* Categorize all the options, | 1857 | /* Categorize all the options, |
| 1849 | and figure out which argv elts are option arguments. */ | 1858 | and figure out which argv elts are option arguments. */ |
| 1850 | for (from = 1; from < argc; from++) | 1859 | for (from = 1; from < argc; from++) |