all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: jim@meyering.net, emacs-devel@gnu.org
Subject: Re: oops? read/write vs type of length parameter
Date: Wed, 13 Apr 2011 05:46:27 -0400	[thread overview]
Message-ID: <E1Q9weZ-0005e3-Us@fencepost.gnu.org> (raw)
In-Reply-To: <4DA55B85.5090305@cs.ucla.edu> (message from Paul Eggert on Wed,  13 Apr 2011 01:15:01 -0700)

> Date: Wed, 13 Apr 2011 01:15:01 -0700
> From: Paul Eggert <eggert@cs.ucla.edu>
> CC: jim@meyering.net, emacs-devel@gnu.org
> 
> On 04/12/2011 11:37 PM, Eli Zaretskii wrote:
> 
> > The current code handles this situation (by looping for what's left
> > to write), while your suggested code will treat that as a fatal error.
> 
> No, the suggested code also loops for what's left to write.
> Perhaps you misread the code? (or am I misunderstanding your comment?)

I was talking about the calls in process.c.  It says now

		    if (XPROCESS (proc)->gnutls_p)
		      rv = emacs_gnutls_write (outfd,
					       XPROCESS (proc),
					       buf, this);
		    else
		      rv = emacs_write (outfd, buf, this);
		      ...
		if (rv < 0)
		  {
		    if (errno == EWOULDBLOCK || errno == EAGAIN)
		      {
		        ...
			rv = 0;
		      }
		    else
		      /* This is a real error.  */
		      report_file_error ("writing to process", Fcons (proc, Qnil));
		  }
		buf += rv;
		len -= rv;
		this -= rv;

and it continues looping if rv is positive.  With your change, it
looks like this:

		    if (XPROCESS (proc)->gnutls_p)
		      written = emacs_gnutls_write (outfd,
					       XPROCESS (proc),
					       buf, this);
		    else
		      written = emacs_write (outfd, buf, this);
		    rv = (written == this ? 0 : -1);
		      ...
		if (rv < 0)
		  {
		    if (errno == EWOULDBLOCK || errno == EAGAIN)
		      {
		        ...
			rv = 0;
		      }
		    else
		      /* This is a real error.  */
		      report_file_error ("writing to process", Fcons (proc, Qnil));
		  }
		buf += rv;
		len -= rv;
		this -= rv;

and it will (with enough luck) exit the loop through
report_file_error, because `rv' becomes negative if `written' is not
equal to `this'.  I was asking whether testing errno for EWOULDBLOCK
and EAGAIN, and the code that deals with when that happens, are good
enough for all the possible reasons that emacs_write and
emacs_gnutls_write could return a partial count of bytes.

> > Emacs cannot have buffers (or any other streams of bytes) that are
> > larger than SSIZE_MAX, because a small number of bits is reserved for
> > the Lisp tags.
> 
> That kind of argument violates abstraction boundaries: sysdep.c
> is supposed to be about system things, and it's not supposed to
> rely on assumptions about Emacs Lisp internals.

sysdep.c is not about system things, it's about Emacs code that
requires platform-dependent techniques.  Most of that indeed deals
with system types, but you will find quite a few Emacs specific
internals there: Lisp_Object and EMACS_TIME data types, calls to
`intern' and Fsleep_for, use of macros such as STRINGP and
FRAME_TERMCAP_P, etc.

> For example, it would be a fairly small change to make Emacs buildable on
> a machine with 32-bit pointers and 64-bit EMACS_INT.

Somehow, I doubt it is a small change.  But if it is, by all means
let's do it now!  What are we waiting for?

>  And this would
> have real advantages: on 32-bit hosts it would remove the arbitrary
> (and really annoying :-) 256 MiB limit on editable files.

Since Emacs 23.2, it's 512 MB, btw, not 256.

> emacs_write should not stand in the way of plausible improvements
> such as this one.

Such a configuration (if it indeed is possible "easily") will need to
revamp several calls to emacs_write anyway, so what type we use there
now is a moot point.

> > It was also about a mistaken
> > call to emacs_write with a negative value in the last argument...
> > 
> > That danger still exists with your proposed version of emacs_write,
> 
> No it doesn't, because I've carefully audited all the Emacs code
> (which is how I found all those *other* bugs :-).  With the
> proposed change, emacs_write is never called with a negative
> argument.

Either you care about future changes or you don't.  If you do, then
auditing just the current callers is not enough, you need to account
for the unknown future (or did you audit that as well?).  If you don't
care about the future, then the assumption that the size of a buffer
or string can never overflow SSIZE_MAX is also based on carefully
auditing the Emacs code, and we can rely on it.



  reply	other threads:[~2011-04-13  9:46 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11  8:55 oops? read/write vs type of length parameter Jim Meyering
2011-04-11  9:44 ` Eli Zaretskii
2011-04-11 11:08   ` Jim Meyering
2011-04-11 11:28     ` David Kastrup
2011-04-11 11:52     ` Eli Zaretskii
2011-04-11 12:27       ` Jim Meyering
2011-04-11 12:31         ` David Kastrup
2011-04-11 21:54           ` Jim Meyering
2011-04-12  4:44             ` Eli Zaretskii
2011-04-12 13:24             ` Ted Zlatanov
2011-04-12 13:29               ` Eli Zaretskii
2011-04-12 14:47                 ` Ted Zlatanov
2011-04-12 17:00                   ` Large file support (was: oops? read/write vs type of length parameter) Eli Zaretskii
2011-04-14 20:57             ` oops? read/write vs type of length parameter Michael Welsh Duggan
2011-04-11 14:02         ` Eli Zaretskii
2011-04-11 11:40   ` Stephen J. Turnbull
2011-04-11 13:58     ` Eli Zaretskii
2011-04-12  1:16       ` Paul Eggert
2011-04-12  3:01         ` Eli Zaretskii
2011-04-12  5:06           ` Paul Eggert
2011-04-12  5:46             ` Eli Zaretskii
2011-04-12  8:19             ` Paul Eggert
2011-04-12  9:41               ` Eli Zaretskii
2011-04-12 15:53                 ` Paul Eggert
2011-04-12 16:56                   ` Eli Zaretskii
2011-04-12 23:55                   ` Juanma Barranquero
2011-04-13  5:14                   ` Paul Eggert
2011-04-13  6:31                     ` Jim Meyering
2011-04-13  6:37                     ` Eli Zaretskii
2011-04-13  8:15                       ` Paul Eggert
2011-04-13  9:46                         ` Eli Zaretskii [this message]
2011-04-13 16:06                           ` Paul Eggert
2011-04-13 17:22                             ` Eli Zaretskii
2011-04-13 19:31                               ` Paul Eggert
2011-04-13 19:59                               ` PJ Weisberg
2011-04-14  4:49                                 ` Eli Zaretskii
2011-04-13 20:02                               ` Paul Eggert
2011-04-13  6:49                     ` Eli Zaretskii
2011-04-13 14:35                     ` Ted Zlatanov
2011-04-15 13:13                       ` Ted Zlatanov
2011-04-15 16:34                         ` Paul Eggert
2011-04-15 18:20                           ` Ted Zlatanov
2011-04-15  1:29                   ` Stefan Monnier
2011-04-15  8:55                     ` Paul Eggert
2011-04-15  9:41                       ` Eli Zaretskii
2011-04-15 10:24                         ` Paul Eggert
2011-04-12 12:32             ` Davis Herring
2011-04-12 13:38               ` Eli Zaretskii
2011-04-12 15:43                 ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1Q9weZ-0005e3-Us@fencepost.gnu.org \
    --to=eliz@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=jim@meyering.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.