unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#53333: Fix for crash in ebrowse
@ 2022-01-17 22:35 Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-01-18 18:09 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-01-17 22:35 UTC (permalink / raw)
  To: 53333

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

Hello --

attached is a patch to ebrowse. Noticed a one-off write error in case of
identifiers that are too long and need escaping. The patch prevents the
write to memory outside of allocated range which on my platform caused
segfault.

Best,



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ebrowse-emacs-27.2-fix.diff --]
[-- Type: text/x-diff, Size: 974 bytes --]

Dont crash on C source code (one off error)

The fix avoids one off error in case the last character in the buffer
needs to be escaped but there is not enough space in buffer to perform
the escape.

The change just simiply ignores the character in such case.

Author: Jan Stranik <jan@stranik.org>


*** /var/home/janstranik/src/emacs-27.2/lib-src/ebrowse.c~	2021-01-28 11:52:16.000000000 -0600
--- /var/home/janstranik/src/emacs-27.2/lib-src/ebrowse.c	2021-09-24 09:31:49.136287028 -0500
***************
*** 1924,1931 ****
      {
        *--s = *--t;
  
!       if (*s == '"' || *s == '\\')
!         *--s = '\\';
      }
  
    *(matching_regexp_end_buf - 1) = '\0';
--- 1924,1937 ----
      {
        *--s = *--t;
  
!       if (*s == '"' || *s == '\\') {
!           if (s > matching_regexp_buffer)
!               *--s = '\\';
!           else {
!               s++;
!               break;
!           }
!       }
      }
  
    *(matching_regexp_end_buf - 1) = '\0';

[-- Attachment #3: Type: text/plain, Size: 18 bytes --]


-- 

Jan Stranik

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

* bug#53333: Fix for crash in ebrowse
  2022-01-17 22:35 bug#53333: Fix for crash in ebrowse Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-01-18 18:09 ` Eli Zaretskii
  2022-01-19  1:32   ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-01-18 18:09 UTC (permalink / raw)
  To: Jan Stranik; +Cc: 53333

> Date: Mon, 17 Jan 2022 17:35:36 -0500
> From:  Jan Stranik via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
> 
> attached is a patch to ebrowse. Noticed a one-off write error in case of
> identifiers that are too long and need escaping. The patch prevents the
> write to memory outside of allocated range which on my platform caused
> segfault.

Thanks, but can you explain the need for this part:

> !           else {
> !               s++;
> !               break;
> !           }
> !       }

Why do we need to advance the pointer 's' in the 'else' clause? why
not leave it alone?

Or maybe I will understand the reason if you show some simple code
that hits this problem (which would be a good thing of its own, as
we'd then have a test to add to our test suite)?





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

* bug#53333: Fix for crash in ebrowse
  2022-01-18 18:09 ` Eli Zaretskii
@ 2022-01-19  1:32   ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-01-20 11:45     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-01-19  1:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 53333

>
> Thanks, but can you explain the need for this part:
>
>> !           else {
>> !               s++;
>> !               break;
>> !           }
>> !       }
>
> Why do we need to advance the pointer 's' in the 'else' clause? why
> not leave it alone?

The identifier is copied from end to the buffer. As we are copying, we
want to escape quote and backslash characters. Normally if we encounter
any of these characters we just prepend \ to in front. If there is not
enough space in the buffer to insert the \, we should increase the s, to
back-out the character that we wanted to escape.

If we would not do that, the first character might not be escaped. If
that character were a quote, it would break the lisp expressions written
later to the BROWSE file.

> Or maybe I will understand the reason if you show some simple code
> that hits this problem (which would be a good thing of its own, as
> we'd then have a test to add to our test suite)?

I encountered this in a c++ header file with very long identifiers that
just filled the buffer but the first character had to be escaped.

-- 

Jan Stranik





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

* bug#53333: Fix for crash in ebrowse
  2022-01-19  1:32   ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-01-20 11:45     ` Eli Zaretskii
  2022-01-27 21:20       ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-01-20 11:45 UTC (permalink / raw)
  To: Jan Stranik; +Cc: 53333-done

> From: Jan Stranik <jan@stranik.org>
> Cc: 53333@debbugs.gnu.org
> Date: Tue, 18 Jan 2022 20:32:55 -0500
> 
> >
> > Thanks, but can you explain the need for this part:
> >
> >> !           else {
> >> !               s++;
> >> !               break;
> >> !           }
> >> !       }
> >
> > Why do we need to advance the pointer 's' in the 'else' clause? why
> > not leave it alone?
> 
> The identifier is copied from end to the buffer. As we are copying, we
> want to escape quote and backslash characters. Normally if we encounter
> any of these characters we just prepend \ to in front. If there is not
> enough space in the buffer to insert the \, we should increase the s, to
> back-out the character that we wanted to escape.
> 
> If we would not do that, the first character might not be escaped. If
> that character were a quote, it would break the lisp expressions written
> later to the BROWSE file.

Thanks, I installed the change on the emacs-28 branch, and I'm marking
this bug done.





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

* bug#53333: Fix for crash in ebrowse
  2022-01-20 11:45     ` Eli Zaretskii
@ 2022-01-27 21:20       ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 5+ messages in thread
From: Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-01-27 21:20 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 53333-done

>
> Thanks, I installed the change on the emacs-28 branch, and I'm marking
> this bug done.

Thank you for pushing the change.

--

Jan Stranik





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

end of thread, other threads:[~2022-01-27 21:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 22:35 bug#53333: Fix for crash in ebrowse Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-18 18:09 ` Eli Zaretskii
2022-01-19  1:32   ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-01-20 11:45     ` Eli Zaretskii
2022-01-27 21:20       ` Jan Stranik via Bug reports for GNU Emacs, the Swiss army knife of text editors

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).