emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] x-load-color-file: avoid array bounds errors (r+w)


From: Jim Meyering
Subject: [PATCH] x-load-color-file: avoid array bounds errors (r+w)
Date: Mon, 08 Jun 2009 10:45:28 +0200

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  <address@hidden>

        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 <address@hidden>
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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]