unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6855: 24.0.50; Bug in tool bar label handling
@ 2010-08-14 12:04 Johan Bockgård
  2010-08-15  8:20 ` Jan Djärv
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2010-08-14 12:04 UTC (permalink / raw)
  To: 6855


There are some bugs in the handling of tool bar labels that can cause
Emacs to crash.



### gtkutil.c: update_frame_tool_bar ###

    char *label = SSDATA (PROP (TOOL_BAR_ITEM_LABEL));

Here we take string data out.



### keyboard.c: parse_tool_bar_item ###

      else if (EQ (key, QClabel))
        {
          /* `:label LABEL-STRING'.  */
          PROP (TOOL_BAR_ITEM_LABEL) = value;
          have_label = 1;
        }

But here we put an arbitrary object in.


...

  if (!have_label)

...
      char buf[64];
      EMACS_INT max_lbl = 2*tool_bar_max_label_size;
      Lisp_Object new_lbl;

      if (strlen (caption) < max_lbl && caption[0] != '\0')
        {
          strcpy (buf, caption);

tool-bar-max-label-size is a user variable, so this can mean a buffer
overflow.


...
      if (SCHARS (new_lbl) <= tool_bar_max_label_size)
        PROP (TOOL_BAR_ITEM_LABEL) = new_lbl;

If we came here but the branch is not taken, the label will be nil,
not a string.





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

* bug#6855: 24.0.50; Bug in tool bar label handling
  2010-08-14 12:04 bug#6855: 24.0.50; Bug in tool bar label handling Johan Bockgård
@ 2010-08-15  8:20 ` Jan Djärv
  2010-08-15  8:51   ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Jan Djärv @ 2010-08-15  8:20 UTC (permalink / raw)
  To: Johan Bockgård; +Cc: 6855-done


Johan Bockgård skrev 2010-08-14 14.04:
>
> There are some bugs in the handling of tool bar labels that can cause
> Emacs to crash.
>
>
>
> ### gtkutil.c: update_frame_tool_bar ###
>
>      char *label = SSDATA (PROP (TOOL_BAR_ITEM_LABEL));
>
> Here we take string data out.
>
>
>
> ### keyboard.c: parse_tool_bar_item ###
>
>        else if (EQ (key, QClabel))
>          {
>            /* `:label LABEL-STRING'.  */
>            PROP (TOOL_BAR_ITEM_LABEL) = value;
>            have_label = 1;
>          }
>
> But here we put an arbitrary object in.
>

We kind of assume people do the sensible thing and put in strings.  It is the
same as for help and image.  If Emacs crashes because somebody didn't put
in a string, that is actually a good thing IMHO.  The error becomes very
apparent then.

>
> ...
>
>    if (!have_label)
>
> ...
>        char buf[64];
>        EMACS_INT max_lbl = 2*tool_bar_max_label_size;
>        Lisp_Object new_lbl;
>
>        if (strlen (caption)<  max_lbl&&  caption[0] != '\0')
>          {
>            strcpy (buf, caption);
>
> tool-bar-max-label-size is a user variable, so this can mean a buffer
> overflow.
>
>
> ...
>        if (SCHARS (new_lbl)<= tool_bar_max_label_size)
>          PROP (TOOL_BAR_ITEM_LABEL) = new_lbl;
>
> If we came here but the branch is not taken, the label will be nil,
> not a string.
>

I have checked in a fix for those two.

Thanks,

	Jan D.








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

* bug#6855: 24.0.50; Bug in tool bar label handling
  2010-08-15  8:20 ` Jan Djärv
@ 2010-08-15  8:51   ` Andreas Schwab
  2010-08-15 10:21     ` Jan Djärv
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2010-08-15  8:51 UTC (permalink / raw)
  To: 6855

Jan Djärv <jan.h.d@swipnet.se> writes:

> We kind of assume people do the sensible thing and put in strings.  It is the
> same as for help and image.  If Emacs crashes because somebody didn't put
> in a string, that is actually a good thing IMHO.  The error becomes very
> apparent then.

I don't agree.  Emacs should be robust against type mismatches, crashing
is the worst possible reaction.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#6855: 24.0.50; Bug in tool bar label handling
  2010-08-15  8:51   ` Andreas Schwab
@ 2010-08-15 10:21     ` Jan Djärv
  2010-08-15 10:37       ` Andreas Schwab
  2010-08-15 11:41       ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Jan Djärv @ 2010-08-15 10:21 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: 6855



Andreas Schwab skrev 2010-08-15 10.51:
> Jan Djärv<jan.h.d@swipnet.se>  writes:
>
>> We kind of assume people do the sensible thing and put in strings.  It is the
>> same as for help and image.  If Emacs crashes because somebody didn't put
>> in a string, that is actually a good thing IMHO.  The error becomes very
>> apparent then.
>
> I don't agree.  Emacs should be robust against type mismatches, crashing
> is the worst possible reaction.

If the documentation states that one should use STRING, and somebody puts in 
nil or a lambda expression or a symbol, that is a usage error.  Being robust 
against this kind of error by ignoring the faulty input just hides the error 
and makes people think it is OK to misuse things.  Better then to crash, that 
way action is usually taken at once.  Hidden errors can linger for years...

	Jan D.





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

* bug#6855: 24.0.50; Bug in tool bar label handling
  2010-08-15 10:21     ` Jan Djärv
@ 2010-08-15 10:37       ` Andreas Schwab
  2010-08-15 11:41       ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Schwab @ 2010-08-15 10:37 UTC (permalink / raw)
  To: Jan Djärv; +Cc: 6855

Jan Djärv <jan.h.d@swipnet.se> writes:

> If the documentation states that one should use STRING, and somebody puts
> in nil or a lambda expression or a symbol, that is a usage error.

Sure.  But crashing is a bug.

> Better then to crash

No, never.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."





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

* bug#6855: 24.0.50; Bug in tool bar label handling
  2010-08-15 10:21     ` Jan Djärv
  2010-08-15 10:37       ` Andreas Schwab
@ 2010-08-15 11:41       ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2010-08-15 11:41 UTC (permalink / raw)
  To: Jan Djärv; +Cc: 6855, schwab

> Date: Sun, 15 Aug 2010 12:21:37 +0200
> From: Jan Djärv <jan.h.d@swipnet.se>
> Cc: 6855@debbugs.gnu.org
> 
> If the documentation states that one should use STRING, and somebody puts in 
> nil or a lambda expression or a symbol, that is a usage error.  Being robust 
> against this kind of error by ignoring the faulty input just hides the error 
> and makes people think it is OK to misuse things.  Better then to crash, that 
> way action is usually taken at once.  Hidden errors can linger for years...

Crash or hide are not the only alternatives.  You can signal an error,
for instance.  Sometimes doing so is not a good idea, like in the
middle of redisplay (because displaying the error message reenters
redisplay again, and you have an infinite loop on your hands).  For
these situations, the solution is to display something prominent and
acutely visible instead of the invalid data, so that it stands out and
catches the user's eye.  For example, if the menu item is bad, display
something like "!!??GARBLED ITEM??!!" instead.

In general, I agree with Andreas: it is better not to crash, if we can
avoid that with a reasonable effort.





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

end of thread, other threads:[~2010-08-15 11:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-14 12:04 bug#6855: 24.0.50; Bug in tool bar label handling Johan Bockgård
2010-08-15  8:20 ` Jan Djärv
2010-08-15  8:51   ` Andreas Schwab
2010-08-15 10:21     ` Jan Djärv
2010-08-15 10:37       ` Andreas Schwab
2010-08-15 11:41       ` Eli Zaretskii

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