diff options
| author | Dmitry Antipov | 2014-06-25 16:11:08 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2014-06-25 16:11:08 +0400 |
| commit | 51e12e8e9411e5d050c36ef6d8777445a5497972 (patch) | |
| tree | 3473f0b720f0c6bcb4d8f42d9bf230675c46087d /src | |
| parent | 5697ca55cb79817a6704c344cc76d866ee2e1699 (diff) | |
| download | emacs-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/ChangeLog | 11 | ||||
| -rw-r--r-- | src/coding.c | 15 | ||||
| -rw-r--r-- | src/composite.c | 35 | ||||
| -rw-r--r-- | src/fns.c | 24 | ||||
| -rw-r--r-- | src/lisp.h | 3 |
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 @@ | |||
| 1 | 2014-06-25 Dmitry Antipov <dmantipov@yandex.ru> | 1 | 2014-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 | |||
| 12 | 2014-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 | ||
| 9092 | DEFUN ("unencodable-char-position", Funencodable_char_position, | 9092 | DEFUN ("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. |
| 9095 | Return position of first un-encodable character in a region. | ||
| 9096 | START and END specify the region and CODING-SYSTEM specifies the | 9095 | START and END specify the region and CODING-SYSTEM specifies the |
| 9097 | encoding to check. Return nil if CODING-SYSTEM does encode the region. | 9096 | encoding to check. Return nil if CODING-SYSTEM does encode the region. |
| 9098 | 9097 | ||
| @@ -9102,8 +9101,9 @@ list of positions. | |||
| 9102 | 9101 | ||
| 9103 | If optional 5th argument STRING is non-nil, it is a string to search | 9102 | If optional 5th argument STRING is non-nil, it is a string to search |
| 9104 | for un-encodable characters. In that case, START and END are indexes | 9103 | for un-encodable characters. In that case, START and END are indexes |
| 9105 | to the string. */) | 9104 | to 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 | |||
| 1684 | frame, or nil for the selected frame's terminal device. | 1684 | frame, or nil for the selected frame's terminal device. |
| 1685 | 1685 | ||
| 1686 | If the optional 4th argument STRING is not nil, it is a string | 1686 | If the optional 4th argument STRING is not nil, it is a string |
| 1687 | containing the target characters between indices FROM and TO. | 1687 | containing the target characters between indices FROM and TO, |
| 1688 | Otherwise FROM and TO are character positions in current buffer; | 1688 | which are treated as in `substring'. Otherwise FROM and TO are |
| 1689 | they can be in either order, and can be integers or markers. | 1689 | character positions in current buffer; they can be in either order, |
| 1690 | and can be integers or markers. | ||
| 1690 | 1691 | ||
| 1691 | A glyph-string is a vector containing information about how to display | 1692 | A glyph-string is a vector containing information about how to display |
| 1692 | a specific character sequence. The format is: | 1693 | a 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 | ||
| 1798 | Compose text between indices START and END of STRING. | 1794 | Compose text between indices START and END of STRING, where |
| 1799 | Optional 4th and 5th arguments are COMPONENTS and MODIFICATION-FUNC | 1795 | START and END are treated as in `substring'. Optional 4th |
| 1796 | and 5th arguments are COMPONENTS and MODIFICATION-FUNC | ||
| 1800 | for the composition. See `compose-string' for more details. */) | 1797 | for 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 | ||
| @@ -50,8 +50,6 @@ static Lisp_Object Qcodeset, Qdays, Qmonths, Qpaper; | |||
| 50 | static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512; | 50 | static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512; |
| 51 | 51 | ||
| 52 | static bool internal_equal (Lisp_Object, Lisp_Object, int, bool, Lisp_Object); | 52 | static bool internal_equal (Lisp_Object, Lisp_Object, int, bool, Lisp_Object); |
| 53 | static void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, | ||
| 54 | ptrdiff_t, EMACS_INT *, EMACS_INT *); | ||
| 55 | 53 | ||
| 56 | DEFUN ("identity", Fidentity, Sidentity, 1, 1, 0, | 54 | DEFUN ("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 | ||
| 1117 | static void | 1114 | void |
| 1118 | validate_subarray (Lisp_Object array, Lisp_Object from, Lisp_Object to, | 1115 | validate_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. | |||
| 1206 | With one argument, just copy STRING without its properties. */) | 1202 | With 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 | ||
| 4639 | static Lisp_Object | 4633 | static Lisp_Object |
| 4640 | secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) | 4634 | secure_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 *); | |||
| 3464 | ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, | 3464 | ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, |
| 3465 | EMACS_UINT); | 3465 | EMACS_UINT); |
| 3466 | extern struct hash_table_test hashtest_eql, hashtest_equal; | 3466 | extern struct hash_table_test hashtest_eql, hashtest_equal; |
| 3467 | 3467 | extern void validate_subarray (Lisp_Object, Lisp_Object, Lisp_Object, | |
| 3468 | ptrdiff_t, ptrdiff_t *, ptrdiff_t *); | ||
| 3468 | extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, | 3469 | extern Lisp_Object substring_both (Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 3469 | ptrdiff_t, ptrdiff_t); | 3470 | ptrdiff_t, ptrdiff_t); |
| 3470 | extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); | 3471 | extern Lisp_Object merge (Lisp_Object, Lisp_Object, Lisp_Object); |