diff options
| author | Paul Eggert | 2019-08-15 02:16:26 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-15 02:17:02 -0700 |
| commit | 6cbf73b5f9f51b5e25b855bf9f521c1ef070dd4a (patch) | |
| tree | b77ce73fb6d549cebc979f72a29a27f0ced1f1b3 /src | |
| parent | 311fcab8f805cd5cc6eacfe37e97423cd73a795b (diff) | |
| download | emacs-6cbf73b5f9f51b5e25b855bf9f521c1ef070dd4a.tar.gz emacs-6cbf73b5f9f51b5e25b855bf9f521c1ef070dd4a.zip | |
Fix some fixnum overflow problems in ccl.c
* src/ccl.c (ccl_driver, Fccl_execute, Fccl_execute_on_string):
Don’t assume CCL registers fit into fixnums.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ccl.c | 35 |
1 files changed, 23 insertions, 12 deletions
| @@ -1291,7 +1291,9 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size | |||
| 1291 | : -1)); | 1291 | : -1)); |
| 1292 | h = GET_HASH_TABLE (eop); | 1292 | h = GET_HASH_TABLE (eop); |
| 1293 | 1293 | ||
| 1294 | eop = hash_lookup (h, make_fixnum (reg[RRR]), NULL); | 1294 | eop = (FIXNUM_OVERFLOW_P (reg[RRR]) |
| 1295 | ? -1 | ||
| 1296 | : hash_lookup (h, make_fixnum (reg[RRR]), NULL)); | ||
| 1295 | if (eop >= 0) | 1297 | if (eop >= 0) |
| 1296 | { | 1298 | { |
| 1297 | Lisp_Object opl; | 1299 | Lisp_Object opl; |
| @@ -1318,7 +1320,9 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size | |||
| 1318 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); | 1320 | i = CCL_DECODE_CHAR (reg[RRR], reg[rrr]); |
| 1319 | h = GET_HASH_TABLE (eop); | 1321 | h = GET_HASH_TABLE (eop); |
| 1320 | 1322 | ||
| 1321 | eop = hash_lookup (h, make_fixnum (i), NULL); | 1323 | eop = (FIXNUM_OVERFLOW_P (i) |
| 1324 | ? -1 | ||
| 1325 | : hash_lookup (h, make_fixnum (i), NULL)); | ||
| 1322 | if (eop >= 0) | 1326 | if (eop >= 0) |
| 1323 | { | 1327 | { |
| 1324 | Lisp_Object opl; | 1328 | Lisp_Object opl; |
| @@ -1990,9 +1994,13 @@ programs. */) | |||
| 1990 | error ("Length of vector REGISTERS is not 8"); | 1994 | error ("Length of vector REGISTERS is not 8"); |
| 1991 | 1995 | ||
| 1992 | for (i = 0; i < 8; i++) | 1996 | for (i = 0; i < 8; i++) |
| 1993 | ccl.reg[i] = (TYPE_RANGED_FIXNUMP (int, AREF (reg, i)) | 1997 | { |
| 1994 | ? XFIXNUM (AREF (reg, i)) | 1998 | intmax_t n; |
| 1995 | : 0); | 1999 | ccl.reg[i] = ((INTEGERP (AREF (reg, i)) |
| 2000 | && integer_to_intmax (AREF (reg, i), &n) | ||
| 2001 | && INT_MIN <= n && n <= INT_MAX) | ||
| 2002 | ? n : 0); | ||
| 2003 | } | ||
| 1996 | 2004 | ||
| 1997 | ccl_driver (&ccl, NULL, NULL, 0, 0, Qnil); | 2005 | ccl_driver (&ccl, NULL, NULL, 0, 0, Qnil); |
| 1998 | maybe_quit (); | 2006 | maybe_quit (); |
| @@ -2000,7 +2008,7 @@ programs. */) | |||
| 2000 | error ("Error in CCL program at %dth code", ccl.ic); | 2008 | error ("Error in CCL program at %dth code", ccl.ic); |
| 2001 | 2009 | ||
| 2002 | for (i = 0; i < 8; i++) | 2010 | for (i = 0; i < 8; i++) |
| 2003 | ASET (reg, i, make_fixnum (ccl.reg[i])); | 2011 | ASET (reg, i, make_int (ccl.reg[i])); |
| 2004 | return Qnil; | 2012 | return Qnil; |
| 2005 | } | 2013 | } |
| 2006 | 2014 | ||
| @@ -2059,12 +2067,15 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY | |||
| 2059 | { | 2067 | { |
| 2060 | if (NILP (AREF (status, i))) | 2068 | if (NILP (AREF (status, i))) |
| 2061 | ASET (status, i, make_fixnum (0)); | 2069 | ASET (status, i, make_fixnum (0)); |
| 2062 | if (TYPE_RANGED_FIXNUMP (int, AREF (status, i))) | 2070 | intmax_t n; |
| 2063 | ccl.reg[i] = XFIXNUM (AREF (status, i)); | 2071 | if (INTEGERP (AREF (status, i)) |
| 2072 | && integer_to_intmax (AREF (status, i), &n) | ||
| 2073 | && INT_MIN <= n && n <= INT_MAX) | ||
| 2074 | ccl.reg[i] = n; | ||
| 2064 | } | 2075 | } |
| 2065 | if (FIXNUMP (AREF (status, 8))) | 2076 | intmax_t ic; |
| 2077 | if (INTEGERP (AREF (status, 8)) && integer_to_intmax (AREF (status, 8), &ic)) | ||
| 2066 | { | 2078 | { |
| 2067 | EMACS_INT ic = XFIXNUM (AREF (status, 8)); | ||
| 2068 | if (ccl.ic < ic && ic < ccl.size) | 2079 | if (ccl.ic < ic && ic < ccl.size) |
| 2069 | ccl.ic = ic; | 2080 | ccl.ic = ic; |
| 2070 | } | 2081 | } |
| @@ -2139,8 +2150,8 @@ usage: (ccl-execute-on-string CCL-PROGRAM STATUS STRING &optional CONTINUE UNIBY | |||
| 2139 | error ("CCL program interrupted at %dth code", ccl.ic); | 2150 | error ("CCL program interrupted at %dth code", ccl.ic); |
| 2140 | 2151 | ||
| 2141 | for (i = 0; i < 8; i++) | 2152 | for (i = 0; i < 8; i++) |
| 2142 | ASET (status, i, make_fixnum (ccl.reg[i])); | 2153 | ASET (status, i, make_int (ccl.reg[i])); |
| 2143 | ASET (status, 8, make_fixnum (ccl.ic)); | 2154 | ASET (status, 8, make_int (ccl.ic)); |
| 2144 | 2155 | ||
| 2145 | val = make_specified_string ((const char *) outbuf, produced_chars, | 2156 | val = make_specified_string ((const char *) outbuf, produced_chars, |
| 2146 | outp - outbuf, NILP (unibyte_p)); | 2157 | outp - outbuf, NILP (unibyte_p)); |