diff options
| author | Paul Eggert | 2019-11-26 13:53:41 -0800 |
|---|---|---|
| committer | Paul Eggert | 2019-11-26 13:57:00 -0800 |
| commit | cffa5703b95fba3624dc54db5e693bae559eac5f (patch) | |
| tree | 7ac0719a3db6a29399ed4389ff27f1d0aeb211e5 /m4 | |
| parent | 75b41a38dd0735fe63457e12741656c63972d3ce (diff) | |
| download | emacs-cffa5703b95fba3624dc54db5e693bae559eac5f.tar.gz emacs-cffa5703b95fba3624dc54db5e693bae559eac5f.zip | |
etags: remove some arbitrary limits
etags had undefined behavior if input files, lines, tags, etc.,
had more than INT_MAX bytes. Clean up the usage of integer types
to fix the overflow errors I found.
* admin/merge-gnulib (GNULIB_MODULES): Add mempcpy.
* lib-src/etags.c: Include inttypes.h, intprops.h.
(memcpyz): New function. Use it to simplify several occurrences
of memcpy followed by storing a trailing '\0'.
(xnew): Use xnmalloc, to catch overflow on integer multiplication.
(xrnew): Change last arg to multiplier. The type is not needed.
All callers changed.
(node, lineno, charno, linecharno, invalidcharno, make_tag):
(pfnote, add_node, number_len, C_symtype, lbz, Makefile_targets)
(readline):
Use intmax_t for line numbers and character positions, instead of
int or long.
(linebuffer, make_tag, pfnote, total_size_of_entries, put_entry)
(in_word_set, C_symtype, token, cstack, pushclass_above):
(popclass_above, write_classname, consider_token, C_entries)
(Ruby_functions, Makefile_targets, Lua_functions, TeX_commands)
(TeX_decode_env, erlang_func, erlang_attribute, erlang_atom)
(substitute, regex_tag_multiline, nocase_tail, readline_interval)
(readline, savenstr, concat, etags_getcwd, relative_filename)
(linebuffer_setlen):
Use ptrdiff_t for object sizes, instead of int or long or unsigned
or size_t.
(write_classname, C_entries):
Avoid sprintf, as the result could exceed INT_MAX bytes
and then behavior goes haywire.
(main): Use int, instead of unsigned, for argv counts.
(get_language_from_filename): Use bool for boolean.
(Ruby_functions): Prefer strcpy to memcpy when copying "=".
(linebuffer_setlen): Use ‘if’ instead of ‘while’.
(memory_full, xnmalloc, xnrealloc): New functions.
(xmalloc): Use memory_full, and take a ptrdiff_t instead of a size_t.
(xrealloc): Remove; no longer needed.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/mempcpy.c, m4/mempcpy.m4: New files, copied from Gnulib.
Diffstat (limited to 'm4')
| -rw-r--r-- | m4/gnulib-comp.m4 | 9 | ||||
| -rw-r--r-- | m4/mempcpy.m4 | 26 |
2 files changed, 35 insertions, 0 deletions
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 625c2211665..baf9511aca7 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 | |||
| @@ -118,6 +118,7 @@ AC_DEFUN([gl_EARLY], | |||
| 118 | # Code from module malloca: | 118 | # Code from module malloca: |
| 119 | # Code from module manywarnings: | 119 | # Code from module manywarnings: |
| 120 | # Code from module memmem-simple: | 120 | # Code from module memmem-simple: |
| 121 | # Code from module mempcpy: | ||
| 121 | # Code from module memrchr: | 122 | # Code from module memrchr: |
| 122 | # Code from module minmax: | 123 | # Code from module minmax: |
| 123 | # Code from module mkostemp: | 124 | # Code from module mkostemp: |
| @@ -327,6 +328,12 @@ AC_DEFUN([gl_INIT], | |||
| 327 | AC_LIBOBJ([memmem]) | 328 | AC_LIBOBJ([memmem]) |
| 328 | fi | 329 | fi |
| 329 | gl_STRING_MODULE_INDICATOR([memmem]) | 330 | gl_STRING_MODULE_INDICATOR([memmem]) |
| 331 | gl_FUNC_MEMPCPY | ||
| 332 | if test $HAVE_MEMPCPY = 0; then | ||
| 333 | AC_LIBOBJ([mempcpy]) | ||
| 334 | gl_PREREQ_MEMPCPY | ||
| 335 | fi | ||
| 336 | gl_STRING_MODULE_INDICATOR([mempcpy]) | ||
| 330 | gl_FUNC_MEMRCHR | 337 | gl_FUNC_MEMRCHR |
| 331 | if test $ac_cv_func_memrchr = no; then | 338 | if test $ac_cv_func_memrchr = no; then |
| 332 | AC_LIBOBJ([memrchr]) | 339 | AC_LIBOBJ([memrchr]) |
| @@ -954,6 +961,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 954 | lib/md5.c | 961 | lib/md5.c |
| 955 | lib/md5.h | 962 | lib/md5.h |
| 956 | lib/memmem.c | 963 | lib/memmem.c |
| 964 | lib/mempcpy.c | ||
| 957 | lib/memrchr.c | 965 | lib/memrchr.c |
| 958 | lib/minmax.h | 966 | lib/minmax.h |
| 959 | lib/mkostemp.c | 967 | lib/mkostemp.c |
| @@ -1094,6 +1102,7 @@ AC_DEFUN([gl_FILE_LIST], [ | |||
| 1094 | m4/mbstate_t.m4 | 1102 | m4/mbstate_t.m4 |
| 1095 | m4/md5.m4 | 1103 | m4/md5.m4 |
| 1096 | m4/memmem.m4 | 1104 | m4/memmem.m4 |
| 1105 | m4/mempcpy.m4 | ||
| 1097 | m4/memrchr.m4 | 1106 | m4/memrchr.m4 |
| 1098 | m4/minmax.m4 | 1107 | m4/minmax.m4 |
| 1099 | m4/mkostemp.m4 | 1108 | m4/mkostemp.m4 |
diff --git a/m4/mempcpy.m4 b/m4/mempcpy.m4 new file mode 100644 index 00000000000..b6090eed285 --- /dev/null +++ b/m4/mempcpy.m4 | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | # mempcpy.m4 serial 11 | ||
| 2 | dnl Copyright (C) 2003-2004, 2006-2007, 2009-2019 Free Software Foundation, | ||
| 3 | dnl Inc. | ||
| 4 | dnl This file is free software; the Free Software Foundation | ||
| 5 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 6 | dnl with or without modifications, as long as this notice is preserved. | ||
| 7 | |||
| 8 | AC_DEFUN([gl_FUNC_MEMPCPY], | ||
| 9 | [ | ||
| 10 | dnl Persuade glibc <string.h> to declare mempcpy(). | ||
| 11 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) | ||
| 12 | |||
| 13 | dnl The mempcpy() declaration in lib/string.in.h uses 'restrict'. | ||
| 14 | AC_REQUIRE([AC_C_RESTRICT]) | ||
| 15 | |||
| 16 | AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) | ||
| 17 | AC_CHECK_FUNCS([mempcpy]) | ||
| 18 | if test $ac_cv_func_mempcpy = no; then | ||
| 19 | HAVE_MEMPCPY=0 | ||
| 20 | fi | ||
| 21 | ]) | ||
| 22 | |||
| 23 | # Prerequisites of lib/mempcpy.c. | ||
| 24 | AC_DEFUN([gl_PREREQ_MEMPCPY], [ | ||
| 25 | : | ||
| 26 | ]) | ||