diff options
| author | Paul Eggert | 2018-02-20 13:42:20 -0800 |
|---|---|---|
| committer | Paul Eggert | 2018-02-20 13:45:27 -0800 |
| commit | d599dce1353ce59d134fcff21cde02c70025253d (patch) | |
| tree | f209e4f35cc4afd930eca9ba14958d92dd33fe42 | |
| parent | 630da78a3cc2a5df2d61e1edf0c209b806b336e2 (diff) | |
| download | emacs-d599dce1353ce59d134fcff21cde02c70025253d.tar.gz emacs-d599dce1353ce59d134fcff21cde02c70025253d.zip | |
Port recent MAX_RW_COUNT checks to POSIX
* src/sysdep.c (MAX_RW_COUNT): Verify that it fits in POSIX standard
types, to go along with already-existing checks for MS-Windows types.
(emacs_intr_read): eassert on all platforms, not just MS-Windows.
| -rw-r--r-- | src/sysdep.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 08db376b261..c59034ce5c3 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -2554,6 +2554,22 @@ emacs_close (int fd) | |||
| 2554 | #define MAX_RW_COUNT (INT_MAX >> 18 << 18) | 2554 | #define MAX_RW_COUNT (INT_MAX >> 18 << 18) |
| 2555 | #endif | 2555 | #endif |
| 2556 | 2556 | ||
| 2557 | /* Verify that MAX_RW_COUNT fits in the relevant standard types. */ | ||
| 2558 | #ifndef SSIZE_MAX | ||
| 2559 | # define SSIZE_MAX TYPE_MAXIMUM (ssize_t) | ||
| 2560 | #endif | ||
| 2561 | verify (MAX_RW_COUNT <= PTRDIFF_MAX); | ||
| 2562 | verify (MAX_RW_COUNT <= SIZE_MAX); | ||
| 2563 | verify (MAX_RW_COUNT <= SSIZE_MAX); | ||
| 2564 | |||
| 2565 | #ifdef WINDOWSNT | ||
| 2566 | /* Verify that Emacs read requests cannot cause trouble, even in | ||
| 2567 | 64-bit builds. The last argument of 'read' is 'unsigned int', and | ||
| 2568 | the return value's type (see 'sys_read') is 'int'. */ | ||
| 2569 | verify (MAX_RW_COUNT <= INT_MAX); | ||
| 2570 | verify (MAX_RW_COUNT <= UINT_MAX); | ||
| 2571 | #endif | ||
| 2572 | |||
| 2557 | /* Read from FD to a buffer BUF with size NBYTE. | 2573 | /* Read from FD to a buffer BUF with size NBYTE. |
| 2558 | If interrupted, process any quits and pending signals immediately | 2574 | If interrupted, process any quits and pending signals immediately |
| 2559 | if INTERRUPTIBLE, and then retry the read unless quitting. | 2575 | if INTERRUPTIBLE, and then retry the read unless quitting. |
| @@ -2562,18 +2578,11 @@ emacs_close (int fd) | |||
| 2562 | static ptrdiff_t | 2578 | static ptrdiff_t |
| 2563 | emacs_intr_read (int fd, void *buf, ptrdiff_t nbyte, bool interruptible) | 2579 | emacs_intr_read (int fd, void *buf, ptrdiff_t nbyte, bool interruptible) |
| 2564 | { | 2580 | { |
| 2581 | /* No caller should ever pass a too-large size to emacs_read. */ | ||
| 2582 | eassert (nbyte <= MAX_RW_COUNT); | ||
| 2583 | |||
| 2565 | ssize_t result; | 2584 | ssize_t result; |
| 2566 | 2585 | ||
| 2567 | /* There is no need to check against MAX_RW_COUNT, since no caller ever | ||
| 2568 | passes a size that large to emacs_read. */ | ||
| 2569 | #ifdef WINDOWSNT | ||
| 2570 | /* On MS-Windows, 'read's last argument is declared as 'unsigned | ||
| 2571 | int', and the return value's type (see 'sys_read') is 'int'. | ||
| 2572 | This might cause trouble, especially in 64-bit builds, if the | ||
| 2573 | above comment ever becomes incorrect. The following assertion | ||
| 2574 | should make us more future-proof. */ | ||
| 2575 | eassert (nbyte <= INT_MAX); | ||
| 2576 | #endif | ||
| 2577 | do | 2586 | do |
| 2578 | { | 2587 | { |
| 2579 | if (interruptible) | 2588 | if (interruptible) |