aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2010-01-09 17:32:47 -0500
committerChong Yidong2010-01-09 17:32:47 -0500
commite398c61cb14ef89632fa28fe97b98c71695d6ccc (patch)
tree9d0188c11c4277105eda2b82be4dcc335fd8b4fc /src
parent4d9bbfa616fb135ff54a63fcd965923d48ca64f1 (diff)
downloademacs-e398c61cb14ef89632fa28fe97b98c71695d6ccc.tar.gz
emacs-e398c61cb14ef89632fa28fe97b98c71695d6ccc.zip
Fix bounds checking for text properties in `format' (Bug#5306).
* intervals.h, textprop.c (extend_property_ranges): Return value and args changed. Discard properties that begin at or after the new end (Bug#5306). * editfns.c (Fformat): Caller changed.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/editfns.c4
-rw-r--r--src/intervals.h2
-rw-r--r--src/textprop.c35
4 files changed, 35 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5b69f08c733..60ea0cf622c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
12010-01-09 Chong Yidong <cyd@stupidchicken.com> 12010-01-09 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * intervals.h, textprop.c (extend_property_ranges): Return value
4 and args changed. Discard properties that begin at or after the
5 new end (Bug#5306).
6
7 * editfns.c (Fformat): Caller changed.
8
3 * nsterm.m (ns_set_default_prefs): Delete function. 9 * nsterm.m (ns_set_default_prefs): Delete function.
4 (syms_of_nsterm): Initialize ns_command_modifier, 10 (syms_of_nsterm): Initialize ns_command_modifier,
5 ns_control_modifier, ns_function_modifier, ns_antialias_text, and 11 ns_control_modifier, ns_function_modifier, ns_antialias_text, and
diff --git a/src/editfns.c b/src/editfns.c
index cb302f7b1e7..58e13b1ed7c 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -4177,8 +4177,8 @@ usage: (format STRING &rest OBJECTS) */)
4177 len = make_number (SCHARS (args[n])); 4177 len = make_number (SCHARS (args[n]));
4178 new_len = make_number (info[n].end - info[n].start); 4178 new_len = make_number (info[n].end - info[n].start);
4179 props = text_property_list (args[n], make_number (0), len, Qnil); 4179 props = text_property_list (args[n], make_number (0), len, Qnil);
4180 extend_property_ranges (props, len, new_len); 4180 props = extend_property_ranges (props, new_len);
4181 /* If successive arguments have properites, be sure that 4181 /* If successive arguments have properties, be sure that
4182 the value of `composition' property be the copy. */ 4182 the value of `composition' property be the copy. */
4183 if (n > 1 && info[n - 1].end) 4183 if (n > 1 && info[n - 1].end)
4184 make_composition_value_copy (props); 4184 make_composition_value_copy (props);
diff --git a/src/intervals.h b/src/intervals.h
index d1b43ee3498..59832c9664f 100644
--- a/src/intervals.h
+++ b/src/intervals.h
@@ -335,7 +335,7 @@ extern void set_text_properties_1 P_ ((Lisp_Object, Lisp_Object,
335Lisp_Object text_property_list P_ ((Lisp_Object, Lisp_Object, Lisp_Object, 335Lisp_Object text_property_list P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
336 Lisp_Object)); 336 Lisp_Object));
337int add_text_properties_from_list P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); 337int add_text_properties_from_list P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
338void extend_property_ranges P_ ((Lisp_Object, Lisp_Object, Lisp_Object)); 338Lisp_Object extend_property_ranges P_ ((Lisp_Object, Lisp_Object));
339Lisp_Object get_char_property_and_overlay P_ ((Lisp_Object, Lisp_Object, 339Lisp_Object get_char_property_and_overlay P_ ((Lisp_Object, Lisp_Object,
340 Lisp_Object, Lisp_Object*)); 340 Lisp_Object, Lisp_Object*));
341extern int text_property_stickiness P_ ((Lisp_Object prop, Lisp_Object pos, 341extern int text_property_stickiness P_ ((Lisp_Object prop, Lisp_Object pos,
diff --git a/src/textprop.c b/src/textprop.c
index 3df5cc9204d..afeaa2b1040 100644
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -2028,24 +2028,41 @@ add_text_properties_from_list (object, list, delta)
2028 2028
2029 2029
2030 2030
2031/* Modify end-points of ranges in LIST destructively. LIST is a list 2031/* Modify end-points of ranges in LIST destructively, and return the
2032 as returned from text_property_list. Change end-points equal to 2032 new list. LIST is a list as returned from text_property_list.
2033 OLD_END to NEW_END. */ 2033 Discard properties that begin at or after NEW_END, and limit
2034 end-points to NEW_END. */
2034 2035
2035void 2036Lisp_Object
2036extend_property_ranges (list, old_end, new_end) 2037extend_property_ranges (list, new_end)
2037 Lisp_Object list, old_end, new_end; 2038 Lisp_Object list, new_end;
2038{ 2039{
2039 for (; CONSP (list); list = XCDR (list)) 2040 Lisp_Object prev = Qnil, head = list;
2041 int max = XINT (new_end);
2042
2043 for (; CONSP (list); prev = list, list = XCDR (list))
2040 { 2044 {
2041 Lisp_Object item, end; 2045 Lisp_Object item, beg, end;
2042 2046
2043 item = XCAR (list); 2047 item = XCAR (list);
2048 beg = XCAR (item);
2044 end = XCAR (XCDR (item)); 2049 end = XCAR (XCDR (item));
2045 2050
2046 if (EQ (end, old_end)) 2051 if (XINT (beg) >= max)
2052 {
2053 /* The start-point is past the end of the new string.
2054 Discard this property. */
2055 if (EQ (head, list))
2056 head = XCDR (list);
2057 else
2058 XSETCDR (prev, XCDR (list));
2059 }
2060 else if (XINT (end) > max)
2061 /* The end-point is past the end of the new string. */
2047 XSETCAR (XCDR (item), new_end); 2062 XSETCAR (XCDR (item), new_end);
2048 } 2063 }
2064
2065 return head;
2049} 2066}
2050 2067
2051 2068