unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47718: Fix epa-file-insert-file-contents substring error
@ 2021-04-12  4:20 juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-04-12  8:14 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-04-12  4:20 UTC (permalink / raw)
  To: 47718

[-- Attachment #1: Type: text/plain, Size: 235 bytes --]

Hi

I think substring occurs error when TO is longer than its content.
This patch will fix the substring bug in epa-file-insert-file-contents.

The last commit this line was 2008, so no one seems not using it, though ;)

Thanks,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-args-out-of-range-error-in-epa-file-insert-file-.patch --]
[-- Type: text/x-patch; name=0001-Fix-args-out-of-range-error-in-epa-file-insert-file-.patch, Size: 1165 bytes --]

From da85a87962cad14fb6dee231fe019fadafa1107e Mon Sep 17 00:00:00 2001
From: Junya Takahashi <jutakat@gmail.com>
Date: Mon, 12 Apr 2021 13:09:35 +0900
Subject: [PATCH] Fix args-out-of-range error in epa-file-insert-file-contents

Fix error below:

$ echo -n test > test
$ gpg -c test
elisp> (epa-file-insert-file-contents "test.gpg" nil 0 5)
       ;; => Args out of range: "test", 0, 5
---
 lisp/epa-file.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/epa-file.el b/lisp/epa-file.el
index e46e3684c8..33bf5adabe 100644
--- a/lisp/epa-file.el
+++ b/lisp/epa-file.el
@@ -198,7 +198,9 @@ epa-file-insert-file-contents
                       (mapcar #'car (epg-context-result-for
                                      context 'encrypted-to)))
 	  (if (or beg end)
-	      (setq string (substring string (or beg 0) end)))
+              (setq string (substring string
+                                      (or beg 0)
+                                      (and end (min end (length string))))))
 	  (save-excursion
 	    ;; If visiting, bind off buffer-file-name so that
 	    ;; file-locking will not ask whether we should
-- 
2.31.1


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

end of thread, other threads:[~2021-04-13  7:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-12  4:20 bug#47718: Fix epa-file-insert-file-contents substring error juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-12  8:14 ` Lars Ingebrigtsen
2021-04-12 11:57   ` Eli Zaretskii
2021-04-12 12:57     ` juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-12 13:23       ` Eli Zaretskii
2021-04-13  0:27         ` juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-13  7:01     ` Lars Ingebrigtsen
2021-04-12 12:51   ` juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-04-13  7:02     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).