aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-06-25 16:11:08 +0400
committerDmitry Antipov2014-06-25 16:11:08 +0400
commit51e12e8e9411e5d050c36ef6d8777445a5497972 (patch)
tree3473f0b720f0c6bcb4d8f42d9bf230675c46087d /src
parent5697ca55cb79817a6704c344cc76d866ee2e1699 (diff)
downloademacs-51e12e8e9411e5d050c36ef6d8777445a5497972.tar.gz
emacs-51e12e8e9411e5d050c36ef6d8777445a5497972.zip
Consistently use validate_subarray to verify substring.
* fns.c (validate_substring): Not static any more. Adjust to use ptrdiff_t, not EMACS_INT, becase string and vector limits can't exceed ptrdiff_t even if EMACS_INT is wider. * lisp.h (validate_subarray): Add prototype. * coding.c (Fundecodable_char_position): * composite.c (Fcomposition_get_gstring, Fcompose_string_internal): Use validate_subarray. Adjust comment to mention substring.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/coding.c15
-rw-r--r--src/composite.c35
-rw-r--r--src/fns.c24
-rw-r--r--src/lisp.h3
5 files changed, 41 insertions, 47 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index fc47fbc8978..24b8e711420 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,16 @@
12014-06-25 Dmitry Antipov <dmantipov@yandex.ru> 12014-06-25 Dmitry Antipov <dmantipov@yandex.ru>
2 2
3 Consistently use validate_subarray to verify substring.
4 * fns.c (validate_substring): Not static any more. Adjust to
5 use ptrdiff_t, not EMACS_INT, becase string and vector limits
6 can't exceed ptrdiff_t even if EMACS_INT is wider.
7 * lisp.h (validate_subarray): Add prototype.
8 * coding.c (Fundecodable_char_position):
9 * composite.c (Fcomposition_get_gstring, Fcompose_string_internal):
10 Use validate_subarray. Adjust comment to mention substring.
11
122014-06-25 Dmitry Antipov <dmantipov@yandex.ru>
13
3 Do not allow out-of-range character position in Fcompare_strings. 14 Do not allow out-of-range character position in Fcompare_strings.
4 * fns.c (validate_subarray): Add prototype. 15 * fns.c (validate_subarray): Add prototype.
5 (Fcompare_substring): Use validate_subarray to check ranges. 16 (Fcompare_substring): Use validate_subarray to check ranges.
diff --git a/src/coding.c b/src/coding.c
index 16dc37a3f20..79f116fc618 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -9091,8 +9091,7 @@ DEFUN ("find-coding-systems-region-internal",
9091 9091
9092DEFUN ("unencodable-char-position", Funencodable_char_position, 9092DEFUN ("unencodable-char-position", Funencodable_char_position,
9093 Sunencodable_char_position, 3, 5, 0, 9093 Sunencodable_char_position, 3, 5, 0,
9094 doc: /* 9094 doc: /* Return position of first un-encodable character in a region.
9095Return position of first un-encodable character in a region.
9096START and END specify the region and CODING-SYSTEM specifies the 9095START and END specify the region and CODING-SYSTEM specifies the
9097encoding to check. Return nil if CODING-SYSTEM does encode the region. 9096encoding to check. Return nil if CODING-SYSTEM does encode the region.
9098 9097
@@ -9102,8 +9101,9 @@ list of positions.
9102 9101
9103If optional 5th argument STRING is non-nil, it is a string to search 9102If optional 5th argument STRING is non-nil, it is a string to search
9104for un-encodable characters. In that case, START and END are indexes 9103for un-encodable characters. In that case, START and END are indexes
9105to the string. */) 9104to the string and treated as in `substring'. */)
9106 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object count, Lisp_Object string) 9105 (Lisp_Object start, Lisp_Object end, Lisp_Object coding_system,
9106 Lisp_Object count, Lisp_Object string)
9107{ 9107{
9108 EMACS_INT n; 9108 EMACS_INT n;
9109 struct coding_system coding; 9109 struct coding_system coding;
@@ -9140,12 +9140,7 @@ to the string. */)
9140 else 9140 else
9141 { 9141 {
9142 CHECK_STRING (string); 9142 CHECK_STRING (string);
9143 CHECK_NATNUM (start); 9143 validate_subarray (string, start, end, SCHARS (string), &from, &to);
9144 CHECK_NATNUM (end);
9145 if (! (XINT (start) <= XINT (end) && XINT (end) <= SCHARS (string)))
9146 args_out_of_range_3 (string, start, end);
9147 from = XINT (start);
9148 to = XINT (end);
9149 if (! STRING_MULTIBYTE (string)) 9144 if (! STRING_MULTIBYTE (string))
9150 return Qnil; 9145 return Qnil;
9151 p = SDATA (string) + string_char_to_byte (string, from); 9146 p = SDATA (string) + string_char_to_byte (string, from);
diff --git a/src/composite.c b/src/composite.c
index 5e14ad037a6..66a20759ec6 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1684,9 +1684,10 @@ Otherwise (for terminal display), FONT-OBJECT must be a terminal ID, a
1684frame, or nil for the selected frame's terminal device. 1684frame, or nil for the selected frame's terminal device.
1685 1685
1686If the optional 4th argument STRING is not nil, it is a string 1686If the optional 4th argument STRING is not nil, it is a string
1687containing the target characters between indices FROM and TO. 1687containing the target characters between indices FROM and TO,
1688Otherwise FROM and TO are character positions in current buffer; 1688which are treated as in `substring'. Otherwise FROM and TO are
1689they can be in either order, and can be integers or markers. 1689character positions in current buffer; they can be in either order,
1690and can be integers or markers.
1690 1691
1691A glyph-string is a vector containing information about how to display 1692A glyph-string is a vector containing information about how to display
1692a specific character sequence. The format is: 1693a specific character sequence. The format is:
@@ -1742,15 +1743,10 @@ should be ignored. */)
1742 } 1743 }
1743 else 1744 else
1744 { 1745 {
1745 CHECK_NATNUM (from);
1746 CHECK_NATNUM (to);
1747 CHECK_STRING (string); 1746 CHECK_STRING (string);
1747 validate_subarray (string, from, to, SCHARS (string), &frompos, &topos);
1748 if (! STRING_MULTIBYTE (string)) 1748 if (! STRING_MULTIBYTE (string))
1749 error ("Attempt to shape unibyte text"); 1749 error ("Attempt to shape unibyte text");
1750 if (! (XINT (from) <= XINT (to) && XINT (to) <= SCHARS (string)))
1751 args_out_of_range_3 (string, from, to);
1752 frompos = XFASTINT (from);
1753 topos = XFASTINT (to);
1754 frombyte = string_char_to_byte (string, frompos); 1750 frombyte = string_char_to_byte (string, frompos);
1755 } 1751 }
1756 1752
@@ -1795,21 +1791,18 @@ DEFUN ("compose-string-internal", Fcompose_string_internal,
1795 Scompose_string_internal, 3, 5, 0, 1791 Scompose_string_internal, 3, 5, 0,
1796 doc: /* Internal use only. 1792 doc: /* Internal use only.
1797 1793
1798Compose text between indices START and END of STRING. 1794Compose text between indices START and END of STRING, where
1799Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC 1795START and END are treated as in `substring'. Optional 4th
1796and 5th arguments are COMPONENTS and MODIFICATION-FUNC
1800for the composition. See `compose-string' for more details. */) 1797for the composition. See `compose-string' for more details. */)
1801 (Lisp_Object string, Lisp_Object start, Lisp_Object end, Lisp_Object components, Lisp_Object modification_func) 1798 (Lisp_Object string, Lisp_Object start, Lisp_Object end,
1799 Lisp_Object components, Lisp_Object modification_func)
1802{ 1800{
1803 CHECK_STRING (string); 1801 ptrdiff_t from, to;
1804 CHECK_NUMBER (start);
1805 CHECK_NUMBER (end);
1806 1802
1807 if (XINT (start) < 0 || 1803 CHECK_STRING (string);
1808 XINT (start) > XINT (end) 1804 validate_subarray (string, start, end, SCHARS (string), &from, &to);
1809 || XINT (end) > SCHARS (string)) 1805 compose_text (from, to, components, modification_func, string);
1810 args_out_of_range (start, end);
1811
1812 compose_text (XINT (start), XINT (end), components, modification_func, string);
1813 return string; 1806 return string;
1814} 1807}
1815 1808
diff --git a/src/fns.c b/src/fns.c
index 85e9f482fc1..9bc854a9c79 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -50,8 +50,6 @@ static Lisp_Object Qcodeset, Qdays, Qmonths, Qpaper;
50static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512; 50static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512;
51 51
52static bool internal_equal (Lisp_Object, Lisp_Object, int, bool, Lisp_Object); 52static bool internal_equal (Lisp_Object, Lisp_Object, int, bool, Lisp_Object);
53static void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
54 ptrdiff_t, EMACS_INT *, EMACS_INT *);
55 53
56DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0, 54DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0,
57 doc: /* Return the argument unchanged. */) 55 doc: /* Return the argument unchanged. */)
@@ -250,8 +248,7 @@ If string STR1 is greater, the value is a positive number N;
250 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, 248 (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2,
251 Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case) 249 Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case)
252{ 250{
253 EMACS_INT from1, to1, from2, to2; 251 ptrdiff_t from1, to1, from2, to2, i1, i1_byte, i2, i2_byte;
254 ptrdiff_t i1, i1_byte, i2, i2_byte;
255 252
256 CHECK_STRING (str1); 253 CHECK_STRING (str1);
257 CHECK_STRING (str2); 254 CHECK_STRING (str2);
@@ -1114,9 +1111,9 @@ Elements of ALIST that are not conses are also shared. */)
1114 Count negative values backwards from the end. 1111 Count negative values backwards from the end.
1115 Set *IFROM and *ITO to the two indexes used. */ 1112 Set *IFROM and *ITO to the two indexes used. */
1116 1113
1117static void 1114void
1118validate_subarray (Lisp_Object array, Lisp_Object from, Lisp_Object to, 1115validate_subarray (Lisp_Object array, Lisp_Object from, Lisp_Object to,
1119 ptrdiff_t size, EMACS_INT *ifrom, EMACS_INT *ito) 1116 ptrdiff_t size, ptrdiff_t *ifrom, ptrdiff_t *ito)
1120{ 1117{
1121 EMACS_INT f, t; 1118 EMACS_INT f, t;
1122 1119
@@ -1165,8 +1162,7 @@ With one argument, just copy STRING (with properties, if any). */)
1165 (Lisp_Object string, Lisp_Object from, Lisp_Object to) 1162 (Lisp_Object string, Lisp_Object from, Lisp_Object to)
1166{ 1163{
1167 Lisp_Object res; 1164 Lisp_Object res;
1168 ptrdiff_t size; 1165 ptrdiff_t size, ifrom, ito;
1169 EMACS_INT ifrom, ito;
1170 1166
1171 if (STRINGP (string)) 1167 if (STRINGP (string))
1172 size = SCHARS (string); 1168 size = SCHARS (string);
@@ -1206,9 +1202,7 @@ If FROM or TO is negative, it counts from the end.
1206With one argument, just copy STRING without its properties. */) 1202With one argument, just copy STRING without its properties. */)
1207 (Lisp_Object string, register Lisp_Object from, Lisp_Object to) 1203 (Lisp_Object string, register Lisp_Object from, Lisp_Object to)
1208{ 1204{
1209 ptrdiff_t size; 1205 ptrdiff_t from_char, to_char, from_byte, to_byte, size;
1210 EMACS_INT from_char, to_char;
1211 ptrdiff_t from_byte, to_byte;
1212 1206
1213 CHECK_STRING (string); 1207 CHECK_STRING (string);
1214 1208
@@ -4637,12 +4631,12 @@ returns nil, then (funcall TEST x1 x2) also returns nil. */)
4637/* ALGORITHM is a symbol: md5, sha1, sha224 and so on. */ 4631/* ALGORITHM is a symbol: md5, sha1, sha224 and so on. */
4638 4632
4639static Lisp_Object 4633static Lisp_Object
4640secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) 4634secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start,
4635 Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror,
4636 Lisp_Object binary)
4641{ 4637{
4642 int i; 4638 int i;
4643 ptrdiff_t size; 4639 ptrdiff_t size, start_char = 0, start_byte, end_char = 0, end_byte;
4644 EMACS_INT start_char = 0, end_char = 0;
4645 ptrdiff_t start_byte, end_byte;
4646 register EMACS_INT b, e; 4640 register EMACS_INT b, e;
4647 register struct buffer *bp; 4641 register struct buffer *bp;
4648 EMACS_INT temp; 4642 EMACS_INT temp;
diff --git a/src/lisp.h b/src/lisp.h
index 2c53282cf14..fb832b80940 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3464,7 +3464,8 @@ ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *);
3464ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, 3464ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object,
3465 EMACS_UINT); 3465 EMACS_UINT);
3466extern struct hash_table_test hashtest_eql, hashtest_equal; 3466extern struct hash_table_test hashtest_eql, hashtest_equal;
3467 3467extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object,
3468 ptrdiff_t, ptrdiff_t *, ptrdiff_t *);
3468extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, 3469extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t,
3469 ptrdiff_t, ptrdiff_t); 3470 ptrdiff_t, ptrdiff_t);
3470extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); 3471extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object);