Commit cffa5703 authored by Paul Eggert's avatar Paul Eggert

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.
parent 75b41a38
Pipeline #4172 failed with stage
in 68 minutes and 48 seconds
......@@ -37,7 +37,7 @@ GNULIB_MODULES='
filemode filevercmp flexmember fpieee fstatat fsusage fsync
getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog
ieee754-h ignore-value intprops largefile lstat
manywarnings memmem-simple memrchr minmax mkostemp mktime nstrftime
manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime
pathmax pipe2 pselect pthread_sigmask putenv
qcopy-acl readlink readlinkat regex
sig2str socklen stat-time std-gnu11 stdalign stddef stdio
......
This diff is collapsed.
......@@ -116,6 +116,7 @@
# lstat \
# manywarnings \
# memmem-simple \
# mempcpy \
# memrchr \
# minmax \
# mkostemp \
......@@ -2027,6 +2028,17 @@ EXTRA_libgnu_a_SOURCES += memmem.c
endif
## end gnulib module memmem-simple
## begin gnulib module mempcpy
ifeq (,$(OMIT_GNULIB_MODULE_mempcpy))
EXTRA_DIST += mempcpy.c
EXTRA_libgnu_a_SOURCES += mempcpy.c
endif
## end gnulib module mempcpy
## begin gnulib module memrchr
ifeq (,$(OMIT_GNULIB_MODULE_memrchr))
......
/* Copy memory area and return pointer after last written byte.
Copyright (C) 2003, 2007, 2009-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <string.h>
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
void *
mempcpy (void *dest, const void *src, size_t n)
{
return (char *) memcpy (dest, src, n) + n;
}
......@@ -118,6 +118,7 @@ AC_DEFUN([gl_EARLY],
# Code from module malloca:
# Code from module manywarnings:
# Code from module memmem-simple:
# Code from module mempcpy:
# Code from module memrchr:
# Code from module minmax:
# Code from module mkostemp:
......@@ -327,6 +328,12 @@ AC_DEFUN([gl_INIT],
AC_LIBOBJ([memmem])
fi
gl_STRING_MODULE_INDICATOR([memmem])
gl_FUNC_MEMPCPY
if test $HAVE_MEMPCPY = 0; then
AC_LIBOBJ([mempcpy])
gl_PREREQ_MEMPCPY
fi
gl_STRING_MODULE_INDICATOR([mempcpy])
gl_FUNC_MEMRCHR
if test $ac_cv_func_memrchr = no; then
AC_LIBOBJ([memrchr])
......@@ -954,6 +961,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/md5.c
lib/md5.h
lib/memmem.c
lib/mempcpy.c
lib/memrchr.c
lib/minmax.h
lib/mkostemp.c
......@@ -1094,6 +1102,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/mbstate_t.m4
m4/md5.m4
m4/memmem.m4
m4/mempcpy.m4
m4/memrchr.m4
m4/minmax.m4
m4/mkostemp.m4
......
# mempcpy.m4 serial 11
dnl Copyright (C) 2003-2004, 2006-2007, 2009-2019 Free Software Foundation,
dnl Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_MEMPCPY],
[
dnl Persuade glibc <string.h> to declare mempcpy().
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
dnl The mempcpy() declaration in lib/string.in.h uses 'restrict'.
AC_REQUIRE([AC_C_RESTRICT])
AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
AC_CHECK_FUNCS([mempcpy])
if test $ac_cv_func_mempcpy = no; then
HAVE_MEMPCPY=0
fi
])
# Prerequisites of lib/mempcpy.c.
AC_DEFUN([gl_PREREQ_MEMPCPY], [
:
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment