unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: juntaka via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 47718@debbugs.gnu.org
Subject: bug#47718: Fix epa-file-insert-file-contents substring error
Date: Mon, 12 Apr 2021 04:20:13 +0000	[thread overview]
Message-ID: <i2Idj93dKv_iWjD_HjyrknK8Cml1tBL-OD-RrhGheKIPHsg4m90TIWpj5lsNqd90evVv0-BU0NlGJIKnMjU-6Ldt8rTObWi8ugVOjgryCPg=@protonmail.com> (raw)

[-- 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


             reply	other threads:[~2021-04-12  4:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  4:20 juntaka via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-04-12  8:14 ` bug#47718: Fix epa-file-insert-file-contents substring error 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

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='i2Idj93dKv_iWjD_HjyrknK8Cml1tBL-OD-RrhGheKIPHsg4m90TIWpj5lsNqd90evVv0-BU0NlGJIKnMjU-6Ldt8rTObWi8ugVOjgryCPg=@protonmail.com' \
    --to=bug-gnu-emacs@gnu.org \
    --cc=47718@debbugs.gnu.org \
    --cc=juntaka@protonmail.com \
    /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 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).