diff options
| author | Paul Eggert | 2011-04-12 22:02:54 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-04-12 22:02:54 -0700 |
| commit | 273a5f82856e545365fbf9278bd739cb6c5aa35e (patch) | |
| tree | bd7ce9c14b199db74fd95b29fc97bf07fd633eb9 /src/process.c | |
| parent | 3e047f51d5ad36df46d553d1090e28f546af9382 (diff) | |
| download | emacs-273a5f82856e545365fbf9278bd739cb6c5aa35e.tar.gz emacs-273a5f82856e545365fbf9278bd739cb6c5aa35e.zip | |
emacs_write: Return size_t, not ssize_t, to avoid overflow issues.
* gnutls.c, gnutls.h (emacs_gnutls_write): Return size_t, not ssize_t.
* sysdep.c, lisp.h (emacs_write): Likewise.
Without the above change, emacs_gnutls_write and emacs_write had
undefined behavior and would typically mistakenly report an error
when writing a buffer whose size exceeds SSIZE_MAX.
(emacs_read, emacs_write): Remove check for negative size, as the
Emacs source code has been audited now.
(emacs_write): Adjust to new signature, making the code look more
like that of emacs_gnutls_write.
* process.c (send_process): Adjust to the new signatures of
emacs_write and emacs_gnutls_write. Do not attempt to store
a byte offset into an 'int'; it might overflow.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/process.c b/src/process.c index 624610069d8..2eed7b4654f 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -5367,6 +5367,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5367 | /* Send this batch, using one or more write calls. */ | 5367 | /* Send this batch, using one or more write calls. */ |
| 5368 | while (this > 0) | 5368 | while (this > 0) |
| 5369 | { | 5369 | { |
| 5370 | size_t written = 0; | ||
| 5370 | int outfd = p->outfd; | 5371 | int outfd = p->outfd; |
| 5371 | old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); | 5372 | old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); |
| 5372 | #ifdef DATAGRAM_SOCKETS | 5373 | #ifdef DATAGRAM_SOCKETS |
| @@ -5375,7 +5376,9 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5375 | rv = sendto (outfd, buf, this, | 5376 | rv = sendto (outfd, buf, this, |
| 5376 | 0, datagram_address[outfd].sa, | 5377 | 0, datagram_address[outfd].sa, |
| 5377 | datagram_address[outfd].len); | 5378 | datagram_address[outfd].len); |
| 5378 | if (rv < 0 && errno == EMSGSIZE) | 5379 | if (0 <= rv) |
| 5380 | written = rv; | ||
| 5381 | else if (errno == EMSGSIZE) | ||
| 5379 | { | 5382 | { |
| 5380 | signal (SIGPIPE, old_sigpipe); | 5383 | signal (SIGPIPE, old_sigpipe); |
| 5381 | report_file_error ("sending datagram", | 5384 | report_file_error ("sending datagram", |
| @@ -5387,12 +5390,13 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5387 | { | 5390 | { |
| 5388 | #ifdef HAVE_GNUTLS | 5391 | #ifdef HAVE_GNUTLS |
| 5389 | if (XPROCESS (proc)->gnutls_p) | 5392 | if (XPROCESS (proc)->gnutls_p) |
| 5390 | rv = emacs_gnutls_write (outfd, | 5393 | written = emacs_gnutls_write (outfd, |
| 5391 | XPROCESS (proc), | 5394 | XPROCESS (proc), |
| 5392 | buf, this); | 5395 | buf, this); |
| 5393 | else | 5396 | else |
| 5394 | #endif | 5397 | #endif |
| 5395 | rv = emacs_write (outfd, buf, this); | 5398 | written = emacs_write (outfd, buf, this); |
| 5399 | rv = (written == this ? 0 : -1); | ||
| 5396 | #ifdef ADAPTIVE_READ_BUFFERING | 5400 | #ifdef ADAPTIVE_READ_BUFFERING |
| 5397 | if (p->read_output_delay > 0 | 5401 | if (p->read_output_delay > 0 |
| 5398 | && p->adaptive_read_buffering == 1) | 5402 | && p->adaptive_read_buffering == 1) |
| @@ -5419,7 +5423,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5419 | that may allow the program | 5423 | that may allow the program |
| 5420 | to finish doing output and read more. */ | 5424 | to finish doing output and read more. */ |
| 5421 | { | 5425 | { |
| 5422 | int offset = 0; | 5426 | size_t offset = 0; |
| 5423 | 5427 | ||
| 5424 | #ifdef BROKEN_PTY_READ_AFTER_EAGAIN | 5428 | #ifdef BROKEN_PTY_READ_AFTER_EAGAIN |
| 5425 | /* A gross hack to work around a bug in FreeBSD. | 5429 | /* A gross hack to work around a bug in FreeBSD. |
| @@ -5465,16 +5469,14 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, | |||
| 5465 | offset); | 5469 | offset); |
| 5466 | else if (STRINGP (object)) | 5470 | else if (STRINGP (object)) |
| 5467 | buf = offset + SSDATA (object); | 5471 | buf = offset + SSDATA (object); |
| 5468 | |||
| 5469 | rv = 0; | ||
| 5470 | } | 5472 | } |
| 5471 | else | 5473 | else |
| 5472 | /* This is a real error. */ | 5474 | /* This is a real error. */ |
| 5473 | report_file_error ("writing to process", Fcons (proc, Qnil)); | 5475 | report_file_error ("writing to process", Fcons (proc, Qnil)); |
| 5474 | } | 5476 | } |
| 5475 | buf += rv; | 5477 | buf += written; |
| 5476 | len -= rv; | 5478 | len -= written; |
| 5477 | this -= rv; | 5479 | this -= written; |
| 5478 | } | 5480 | } |
| 5479 | } | 5481 | } |
| 5480 | } | 5482 | } |