unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Use of memcmp in font.c
@ 2008-06-09 21:55 Chong Yidong
  2008-06-11  1:07 ` Kenichi Handa
  0 siblings, 1 reply; 3+ messages in thread
From: Chong Yidong @ 2008-06-09 21:55 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: emacs-devel

Is the use of memcmp in font.c:1384 safe?  It seems to me that if the
string being parsed ends early, we'll get a segmentation fault.

  /* Now parse ":KEY=VAL" patterns.  Store known keys and values in
     extra, copy unknown ones to COPY.  It is stored in extra slot by
     the key QCfc_unknown_spec.  */
  while (*p0)
    {
      Lisp_Object key, val;
      int prop;

      for (p1 = p0 + 1; *p1 && *p1 != '=' && *p1 != ':'; p1++);
      if (*p1 != '=')
	{
	  /* Must be an enumerated value.  */
	  val = font_intern_prop (p0 + 1, p1 - p0 - 1);
	  if (memcmp (p0 + 1, "light", 5) == 0
	      || memcmp (p0 + 1, "medium", 6) == 0
  .....




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

* Re: Use of memcmp in font.c
  2008-06-09 21:55 Use of memcmp in font.c Chong Yidong
@ 2008-06-11  1:07 ` Kenichi Handa
  2008-06-11  1:12   ` Miles Bader
  0 siblings, 1 reply; 3+ messages in thread
From: Kenichi Handa @ 2008-06-11  1:07 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

In article <87ve0iqnnq.fsf@stupidchicken.com>, Chong Yidong <cyd@stupidchicken.com> writes:

> Is the use of memcmp in font.c:1384 safe?  It seems to me that if the
> string being parsed ends early, we'll get a segmentation fault.

>   /* Now parse ":KEY=VAL" patterns.  Store known keys and values in
>      extra, copy unknown ones to COPY.  It is stored in extra slot by
>      the key QCfc_unknown_spec.  */
>   while (*p0)
>     {
>       Lisp_Object key, val;
>       int prop;

>       for (p1 = p0 + 1; *p1 && *p1 != '=' && *p1 != ':'; p1++);
>       if (*p1 != '=')
> 	{
> 	  /* Must be an enumerated value.  */
> 	  val = font_intern_prop (p0 + 1, p1 - p0 - 1);
> 	  if (memcmp (p0 + 1, "light", 5) == 0
> 	      || memcmp (p0 + 1, "medium", 6) == 0
>   .....

I've thought that memcmp doesn't check bytes after the first
non-matching byte and thus the above are safe because p0 is
null-terminated.

---
Kenichi Handa
handa@ni.aist.go.jp




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

* Re: Use of memcmp in font.c
  2008-06-11  1:07 ` Kenichi Handa
@ 2008-06-11  1:12   ` Miles Bader
  0 siblings, 0 replies; 3+ messages in thread
From: Miles Bader @ 2008-06-11  1:12 UTC (permalink / raw)
  To: Kenichi Handa; +Cc: Chong Yidong, emacs-devel

Kenichi Handa <handa@m17n.org> writes:
> I've thought that memcmp doesn't check bytes after the first
> non-matching byte and thus the above are safe because p0 is
> null-terminated.

Probably many implementations don't, but I'm not sure that's
guaranteed...  [e.g., they may do comparisons more than one byte at a
time.]

-Miles

-- 
Fast, small, soon; pick any 2.




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

end of thread, other threads:[~2008-06-11  1:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-09 21:55 Use of memcmp in font.c Chong Yidong
2008-06-11  1:07 ` Kenichi Handa
2008-06-11  1:12   ` Miles Bader

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