GNU bug report logs - #34769
Bug in emacs 26.1 gdb-send match-string applied after non-matching string-match

Previous Next

Package: emacs;

Reported by: Tobias Zawada <i_inbox <at> tn-home.de>

Date: Wed, 6 Mar 2019 15:59:01 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 34769 in the body.
You can then email your comments to 34769 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#34769; Package emacs. (Wed, 06 Mar 2019 15:59:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tobias Zawada <i_inbox <at> tn-home.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 06 Mar 2019 15:59:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tobias Zawada <i_inbox <at> tn-home.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Bug in emacs 26.1 gdb-send match-string applied after non-matching
 string-match
Date: Wed, 6 Mar 2019 12:27:03 +0100 (CET)
Dear Emacs maintainers,

At the end of gdb-send one finds the following lines:

  (let* ((control-command-p (string-match gdb-control-commands-regexp string))
         (command-arg (match-string 3 string))

It is wrong to call (match-string 3 string) if (string-match gdb-control-commands-regexp string) returned nil.
The doc of match-string says:
"Return string of text matched by last search."
That means match-string only returns sensible results if the last match was successful.

Possible correction:

  (let* ((control-command-p (string-match gdb-control-commands-regexp string))
         (command-arg (and control-command-p (match-string 3 string)))


System info:
GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2018-05-29

Best regards,
Tobias




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34769; Package emacs. (Wed, 06 Mar 2019 18:19:02 GMT) Full text and rfc822 format available.

Message #8 received at 34769 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tobias Zawada <i_inbox <at> tn-home.de>
Cc: 34769 <at> debbugs.gnu.org
Subject: Re: bug#34769: Bug in emacs 26.1 gdb-send match-string applied after
 non-matching string-match
Date: Wed, 06 Mar 2019 20:18:07 +0200
> Date: Wed, 6 Mar 2019 12:27:03 +0100 (CET)
> From: Tobias Zawada <i_inbox <at> tn-home.de>
> 
> At the end of gdb-send one finds the following lines:
> 
>   (let* ((control-command-p (string-match gdb-control-commands-regexp string))
>          (command-arg (match-string 3 string))
> 
> It is wrong to call (match-string 3 string) if (string-match gdb-control-commands-regexp string) returned nil.
> The doc of match-string says:
> "Return string of text matched by last search."
> That means match-string only returns sensible results if the last match was successful.

That is true, and a cleanup is a good idea.  But please note that the
undefined results are not used if control-command-p is nil, so the
issue is not that serious.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#34769; Package emacs. (Wed, 06 Mar 2019 21:03:02 GMT) Full text and rfc822 format available.

Message #11 received at 34769 <at> debbugs.gnu.org (full text, mbox):

From: Tobias Zawada <i_inbox <at> tn-home.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 34769 <at> debbugs.gnu.org
Subject: Re: bug#34769: Bug in emacs 26.1 gdb-send match-string applied
 after non-matching string-match
Date: Wed, 6 Mar 2019 21:10:54 +0100 (CET)
Dear Eli,
thanks for looking into this.

> > It is wrong to call (match-string 3 string) if (string-match gdb-control-commands-regexp string) returned nil.
> ...
> That is true, and a cleanup is a good idea. But please note that the
> undefined results are not used if control-command-p is nil, so the
> issue is not that serious.

The match data is that one of the previous successful matching operation.
One gets an args-out-of-range signal if the indexes in the match data are larger than the width of the string argument to match-string. That is how I discovered the error.

A reconstruction with gdb-send is too involved.
Instead I demonstrate the effect with the following orgmode source code block inclusive results:

#+BEGIN_SRC emacs-lisp
(string-match "\\(1\\) *\\(2\\)" "1          2")
(string-match "\\(3 \\(4\\)\\)" "1 2")
(append
 (match-data)
 (condition-case err
     (match-string 2 "1 2")
     (error (list err))))
#+END_SRC

#+RESULTS:
| 0 | 12 | 0 | 1 | 11 | 12 | (args-out-of-range 1 2 11 12) |

Best regards,
Tobias




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Thu, 07 Mar 2019 15:19:01 GMT) Full text and rfc822 format available.

Notification sent to Tobias Zawada <i_inbox <at> tn-home.de>:
bug acknowledged by developer. (Thu, 07 Mar 2019 15:19:02 GMT) Full text and rfc822 format available.

Message #16 received at 34769-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Tobias Zawada <i_inbox <at> tn-home.de>
Cc: 34769-done <at> debbugs.gnu.org
Subject: Re: bug#34769: Bug in emacs 26.1 gdb-send match-string applied
 after non-matching string-match
Date: Thu, 07 Mar 2019 17:18:20 +0200
> Date: Wed, 6 Mar 2019 21:10:54 +0100 (CET)
> From: Tobias Zawada <i_inbox <at> tn-home.de>
> Cc: 34769 <at> debbugs.gnu.org
> 
> Dear Eli,
> thanks for looking into this.
> 
> > > It is wrong to call (match-string 3 string) if (string-match gdb-control-commands-regexp string) returned nil.
> > ...
> > That is true, and a cleanup is a good idea. But please note that the
> > undefined results are not used if control-command-p is nil, so the
> > issue is not that serious.
> 
> The match data is that one of the previous successful matching operation.
> One gets an args-out-of-range signal if the indexes in the match data are larger than the width of the string argument to match-string. That is how I discovered the error.

You are right; I've now fixed this on the emacs-26 branch.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 05 Apr 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 35 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.