unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] x-load-color-file: avoid array bounds errors (r+w)
@ 2009-06-08  8:45 Jim Meyering
  0 siblings, 0 replies; only message in thread
From: Jim Meyering @ 2009-06-08  8:45 UTC (permalink / raw)
  To: Emacs development discussions

I spotted an array bounds error in the code below.
The patch below fixes it, assuming the intent is to
accept arbitrary (including empty) names.

Note that this is in a !HAVE_X_WINDOWS block.

If no one objects, I'll commit it tomorrow.

2009-06-08  Jim Meyering  <meyering@redhat.com>

	x-load-color-file: avoid array bounds error
        x-load-color-file expects each line of input to be of the form
        "R G B name".  But if "name" is missing, it would read name[-1],
        and if that value is '\n', zero it.
        * xfaces.c (Fx_load_color_file): Handle missing color name.


From cbb822330a91336d261e808eee84c503e4b2d659 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Mon, 8 Jun 2009 08:38:07 +0200
Subject: [PATCH] x-load-color-file: avoid array bounds error

x-load-color-file expects each line of input to be of the form
"R G B name".  But if "name" is missing, it would read name[-1],
and if that value is '\n', zero it.
* xfaces.c (Fx_load_color_file): Handle missing color name.
---
 src/xfaces.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/xfaces.c b/src/xfaces.c
index 4443768..704d7a9 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -6630,7 +6630,7 @@ where R,G,B are numbers between 0 and 255 and name is an arbitrary string.  */)
 	  {
 	    char *name = buf + num;
 	    num = strlen (name) - 1;
-	    if (name[num] == '\n')
+	    if (num >= 0 && name[num] == '\n')
 	      name[num] = 0;
 	    cmap = Fcons (Fcons (build_string (name),
 #ifdef WINDOWSNT
--
1.6.3.2.322.g117de




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-06-08  8:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-08  8:45 [PATCH] x-load-color-file: avoid array bounds errors (r+w) Jim Meyering

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