all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
@ 2014-08-31 19:50 Ivan Shmakov
  2022-05-11 15:22 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Ivan Shmakov @ 2014-08-31 19:50 UTC (permalink / raw)
  To: 18370

Package:  emacs
Severity: minor

	As currently implemented, insert-file-contents disallows not
	only (as per (elisp.info) Reading from Files) the case of either
	‘visit’ or ‘replace’ arguments being non-nil, but also when
	non-nil are either ‘beg’ or ‘end’ (or both):

  3506	  /* This code will need to be changed in order to work on named
  3507	     pipes, and it's probably just not worth it.  So we should at
  3508	     least signal an error.  */
  3509	  if (!S_ISREG (st.st_mode))
  3510	    {
  3511	      not_regular = 1;
⋯
  3516	      if (! NILP (replace) || ! NILP (beg) || ! NILP (end))
  3517		xsignal2 (Qfile_error,
  3518			  build_string ("not a regular file"), orig_filename);
  3519	    }

	This, however, precludes the use of insert-file-contents not
	only on named pipes, but also on /dev/cdrom, /dev/random, and
	the like, – for (and especially in the case of the latter) the
	‘end’ argument gets rather essential here, as otherwise the
	function is likely to read much more than the caller will be
	able to handle at any single time.

	Instead, I’d suggest that ‘end’ is always allowed, and ‘beg’ is
	allowed when the file in question is /seekable/, – which, ISTR,
	is possible to check beforehand (lseek (fd, 0, SEEK_CUR) < 0?)

	From a glance over the code, this new behavior wouldn’t be all
	that hard to implement (some not_regular checks will have to be
	replaced with the ones against beg_offset, end_offset, etc.),
	but from what I read, – it’s already going to be more than I can
	test right now.  So no .diff this time, alas.

-- 
FSF associate member #7257  http://boycottsystemd.org/  … 3013 B6A0 230E 334A





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
  2014-08-31 19:50 bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files Ivan Shmakov
@ 2022-05-11 15:22 ` Lars Ingebrigtsen
  2022-06-11 12:40   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-11 15:22 UTC (permalink / raw)
  To: Ivan Shmakov; +Cc: 18370

Ivan Shmakov <ivan@siamics.net> writes:

> 	As currently implemented, insert-file-contents disallows not
> 	only (as per (elisp.info) Reading from Files) the case of either
> 	‘visit’ or ‘replace’ arguments being non-nil, but also when
> 	non-nil are either ‘beg’ or ‘end’ (or both):

[...]

> 	This, however, precludes the use of insert-file-contents not
> 	only on named pipes, but also on /dev/cdrom, /dev/random, and
> 	the like, – for (and especially in the case of the latter) the
> 	‘end’ argument gets rather essential here, as otherwise the
> 	function is likely to read much more than the caller will be
> 	able to handle at any single time.
>
> 	Instead, I’d suggest that ‘end’ is always allowed, and ‘beg’ is
> 	allowed when the file in question is /seekable/, – which, ISTR,
> 	is possible to check beforehand (lseek (fd, 0, SEEK_CUR) < 0?)
>
> 	From a glance over the code, this new behavior wouldn’t be all
> 	that hard to implement (some not_regular checks will have to be
> 	replaced with the ones against beg_offset, end_offset, etc.),
> 	but from what I read, – it’s already going to be more than I can
> 	test right now.  So no .diff this time, alas.

(I'm going through old bug reports that unfortunately weren't resolved
at the time.)

Simple test case:

(insert-file-contents "/dev/urandom" nil nil 10)

This still fails in Emacs 29, and it would indeed be nice if it worked.
I seem to remember this being discussed previously, and that...  er...
no, I can't really recall anything more than that.

Does anybody see any good reasons why we shouldn't allow this?  If not,
I can take a stab at implementing it...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
  2022-05-11 15:22 ` Lars Ingebrigtsen
@ 2022-06-11 12:40   ` Lars Ingebrigtsen
  2022-06-12  7:11     ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-11 12:40 UTC (permalink / raw)
  To: Ivan Shmakov; +Cc: 18370

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Simple test case:
>
> (insert-file-contents "/dev/urandom" nil nil 10)
>
> This still fails in Emacs 29, and it would indeed be nice if it worked.
> I seem to remember this being discussed previously, and that...  er...
> no, I can't really recall anything more than that.
>
> Does anybody see any good reasons why we shouldn't allow this?  If not,
> I can take a stab at implementing it...

There were no objections, so I've now added this to Emacs 29.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
  2022-06-11 12:40   ` Lars Ingebrigtsen
@ 2022-06-12  7:11     ` Juri Linkov
  2022-06-12 10:19       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2022-06-12  7:11 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 18370

>> Simple test case:
>>
>> (insert-file-contents "/dev/urandom" nil nil 10)
>>
>> This still fails in Emacs 29, and it would indeed be nice if it worked.
>> I seem to remember this being discussed previously, and that...  er...
>> no, I can't really recall anything more than that.
>>
>> Does anybody see any good reasons why we shouldn't allow this?  If not,
>> I can take a stab at implementing it...
>
> There were no objections, so I've now added this to Emacs 29.

Maybe this is related to bug#9800, still unfixed after this change.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files
  2022-06-12  7:11     ` Juri Linkov
@ 2022-06-12 10:19       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-06-12 10:19 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 18370

Juri Linkov <juri@linkov.net> writes:

> Maybe this is related to bug#9800, still unfixed after this change.

I think it's somewhat unrelated -- the /proc files are "regular" files,
they just tend to "grow" while reading.  I think the solution sketched
in that bug report sounds OK.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-12 10:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-31 19:50 bug#18370: insert-file-contents: forbids also beg, end for non-regular (special) files Ivan Shmakov
2022-05-11 15:22 ` Lars Ingebrigtsen
2022-06-11 12:40   ` Lars Ingebrigtsen
2022-06-12  7:11     ` Juri Linkov
2022-06-12 10:19       ` Lars Ingebrigtsen

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.