From: Hans-Bernhard B. <br...@us...> - 2009-04-10 14:16:47
|
Update of /cvsroot/cscope/cscope In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4099 Modified Files: aclocal.m4 ChangeLog config.h.in configure configure.in Makefile.in Added Files: acinclude.m4 Log Message: Replace all usage of (v)sprintf by (v)snprintf. Supply and use optional replacement snprintf on systems that don't have it. --- NEW FILE --- # $Id: acinclude.m4,v 1.1 2009/04/10 13:39:22 broeker Exp $ # Copyright (c) 2008 Holger Weiss <ho...@jh...>. # # This code may freely be used, modified and/or redistributed for any purpose. # It would be nice if additions and fixes to this file (including trivial code # cleanups) would be sent back in order to let me include them in the version # available at <http://www.jhweiss.de/software/snprintf.html>. However, this is # not a requirement for using or redistributing (possibly modified) versions of # this file, nor is leaving this notice intact mandatory. # HW_HEADER_STDARG_H # ------------------ # Define HAVE_STDARG_H to 1 if <stdarg.h> is available. AC_DEFUN([HW_HEADER_STDARG_H], [ AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used. AC_CHECK_HEADERS_ONCE([stdarg.h]) ])# HW_HEADER_STDARG_H # HW_HEADER_VARARGS_H # ------------------- # Define HAVE_VARARGS_H to 1 if <varargs.h> is available. AC_DEFUN([HW_HEADER_VARARGS_H], [ AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used. AC_CHECK_HEADERS_ONCE([varargs.h]) ])# HW_HEADER_VARARGS_H # HW_FUNC_VA_COPY # --------------- # Set $hw_cv_func_va_copy to "yes" or "no". Define HAVE_VA_COPY to 1 if # $hw_cv_func_va_copy is set to "yes". Note that it's "unspecified whether # va_copy and va_end are macros or identifiers declared with external linkage." # (C99: 7.15.1, 1) Therefore, the presence of va_copy(3) cannot simply "be # tested with #ifdef", as suggested by the Autoconf manual (5.5.1). AC_DEFUN([HW_FUNC_VA_COPY], [ AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H. AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H. AC_CACHE_CHECK([for va_copy], [hw_cv_func_va_copy], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#if HAVE_STDARG_H #include <stdarg.h> #elif HAVE_VARARGS_H #include <varargs.h> #endif]], [[va_list ap, aq; va_copy(aq, ap);]])], [hw_cv_func_va_copy=yes], [hw_cv_func_va_copy=no], [hw_cv_func_va_copy=no])]) AS_IF([test "$hw_cv_func_va_copy" = yes], [AC_DEFINE([HAVE_VA_COPY], [1], [Define to 1 if you have the `va_copy' function or macro.])]) ])# HW_FUNC_VA_COPY # HW_FUNC___VA_COPY # ----------------- # Set $hw_cv_func___va_copy to "yes" or "no". Define HAVE___VA_COPY to 1 if # $hw_cv_func___va_copy is set to "yes". AC_DEFUN([HW_FUNC___VA_COPY], [ AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H. AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H. AC_CACHE_CHECK([for __va_copy], [hw_cv_func___va_copy], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#if HAVE_STDARG_H #include <stdarg.h> #elif HAVE_VARARGS_H #include <varargs.h> #endif]], [[va_list ap, aq; __va_copy(aq, ap);]])], [hw_cv_func___va_copy=yes], [hw_cv_func___va_copy=no], [hw_cv_func___va_copy=no])]) AS_IF([test "$hw_cv_func___va_copy" = yes], [AC_DEFINE([HAVE___VA_COPY], [1], [Define to 1 if you have the `__va_copy' function or macro.])]) ])# HW_FUNC___VA_COPY # HW_FUNC_VSNPRINTF # ----------------- # Set $hw_cv_func_vsnprintf and $hw_cv_func_vsnprintf_c99 to "yes" or "no", # respectively. Define HAVE_VSNPRINTF to 1 only if $hw_cv_func_vsnprintf_c99 # is set to "yes". Otherwise, define vsnprintf to rpl_vsnprintf and make sure # the replacement function will be built. AC_DEFUN([HW_FUNC_VSNPRINTF], [ AC_PREREQ([2.60])dnl 2.59 should work if some AC_TYPE_* macros are replaced. AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H. AC_CHECK_FUNC([vsnprintf], [hw_cv_func_vsnprintf=yes], [hw_cv_func_vsnprintf=no]) AS_IF([test "$hw_cv_func_vsnprintf" = yes], [AC_CACHE_CHECK([whether vsnprintf is C99 compliant], [hw_cv_func_vsnprintf_c99], [AC_RUN_IFELSE( [AC_LANG_PROGRAM( [[#if HAVE_STDARG_H #include <stdarg.h> #endif #include <stdio.h> static int testprintf(char *buf, size_t size, const char *format, ...) { int result; va_list ap; va_start(ap, format); result = vsnprintf(buf, size, format, ap); va_end(ap); return result; }]], [[char buf[43]; if (testprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 || testprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 || buf[0] != 'T' || buf[3] != '\0') return 1;]])], [hw_cv_func_vsnprintf_c99=yes], [hw_cv_func_vsnprintf_c99=no], [hw_cv_func_vsnprintf_c99=no])])], [hw_cv_func_snprintf_c99=no]) AS_IF([test "$hw_cv_func_vsnprintf_c99" = yes], [AC_DEFINE([HAVE_VSNPRINTF], [1], [Define to 1 if you have a C99 compliant `vsnprintf' function.])], [AC_DEFINE([vsnprintf], [rpl_vsnprintf], [Define to rpl_vsnprintf if the replacement function should be used.]) AC_CHECK_HEADERS([inttypes.h locale.h stddef.h stdint.h]) AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep], [], [], [#include <locale.h>]) AC_TYPE_LONG_DOUBLE AC_TYPE_LONG_LONG_INT AC_TYPE_UNSIGNED_LONG_LONG_INT AC_TYPE_SIZE_T AC_TYPE_INTMAX_T AC_TYPE_UINTMAX_T AC_TYPE_UINTPTR_T AC_CHECK_TYPES([ptrdiff_t]) AC_CHECK_FUNCS([localeconv]) _HW_FUNC_XPRINTF_REPLACE]) ])# HW_FUNC_VSNPRINTF # HW_FUNC_SNPRINTF # ---------------- # Set $hw_cv_func_snprintf and $hw_cv_func_snprintf_c99 to "yes" or "no", # respectively. Define HAVE_SNPRINTF to 1 only if $hw_cv_func_snprintf_c99 # is set to "yes". Otherwise, define snprintf to rpl_snprintf and make sure # the replacement function will be built. AC_DEFUN([HW_FUNC_SNPRINTF], [ AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our snprintf(3) calls vsnprintf(3). AC_CHECK_FUNC([snprintf], [hw_cv_func_snprintf=yes], [hw_cv_func_snprintf=no]) AS_IF([test "$hw_cv_func_snprintf" = yes], [AC_CACHE_CHECK([whether snprintf is C99 compliant], [hw_cv_func_snprintf_c99], [AC_RUN_IFELSE( [AC_LANG_PROGRAM([[#include <stdio.h>]], [[char buf[43]; if (snprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 || snprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 || buf[0] != 'T' || buf[3] != '\0') return 1;]])], [hw_cv_func_snprintf_c99=yes], [hw_cv_func_snprintf_c99=no], [hw_cv_func_snprintf_c99=no])])], [hw_cv_func_snprintf_c99=no]) AS_IF([test "$hw_cv_func_snprintf_c99" = yes], [AC_DEFINE([HAVE_SNPRINTF], [1], [Define to 1 if you have a C99 compliant `snprintf' function.])], [AC_DEFINE([snprintf], [rpl_snprintf], [Define to rpl_snprintf if the replacement function should be used.]) _HW_FUNC_XPRINTF_REPLACE]) ])# HW_FUNC_SNPRINTF # HW_FUNC_VASPRINTF # ----------------- # Set $hw_cv_func_vasprintf to "yes" or "no". Define HAVE_VASPRINTF to 1 if # $hw_cv_func_vasprintf is set to "yes". Otherwise, define vasprintf to # rpl_vasprintf and make sure the replacement function will be built. AC_DEFUN([HW_FUNC_VASPRINTF], [ AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our vasprintf(3) calls vsnprintf(3). AC_CHECK_FUNCS([vasprintf], [hw_cv_func_vasprintf=yes], [hw_cv_func_vasprintf=no]) AS_IF([test "$hw_cv_func_vasprintf" = no], [AC_DEFINE([vasprintf], [rpl_vasprintf], [Define to rpl_vasprintf if the replacement function should be used.]) AC_CHECK_HEADERS([stdlib.h]) HW_FUNC_VA_COPY AS_IF([test "$hw_cv_func_va_copy" = no], [HW_FUNC___VA_COPY]) _HW_FUNC_XPRINTF_REPLACE]) ])# HW_FUNC_VASPRINTF # HW_FUNC_ASPRINTF # ---------------- # Set $hw_cv_func_asprintf to "yes" or "no". Define HAVE_ASPRINTF to 1 if # $hw_cv_func_asprintf is set to "yes". Otherwise, define asprintf to # rpl_asprintf and make sure the replacement function will be built. AC_DEFUN([HW_FUNC_ASPRINTF], [ AC_REQUIRE([HW_FUNC_VASPRINTF])dnl Our asprintf(3) calls vasprintf(3). AC_CHECK_FUNCS([asprintf], [hw_cv_func_asprintf=yes], [hw_cv_func_asprintf=no]) AS_IF([test "$hw_cv_func_asprintf" = no], [AC_DEFINE([asprintf], [rpl_asprintf], [Define to rpl_asprintf if the replacement function should be used.]) _HW_FUNC_XPRINTF_REPLACE]) ])# HW_FUNC_ASPRINTF # _HW_FUNC_XPRINTF_REPLACE # ------------------------ # Arrange for building snprintf.c. Must be called if one or more of the # functions provided by snprintf.c are needed. AC_DEFUN([_HW_FUNC_XPRINTF_REPLACE], [ AS_IF([test "x$_hw_cv_func_xprintf_replace_done" != xyes], [AC_C_CONST HW_HEADER_STDARG_H AC_LIBOBJ([snprintf]) _hw_cv_func_xprintf_replace_done=yes]) ])# _HW_FUNC_XPRINTF_REPLACE dnl vim: set joinspaces textwidth=80: Index: aclocal.m4 =================================================================== RCS file: /cvsroot/cscope/cscope/aclocal.m4,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** aclocal.m4 30 Sep 2006 17:31:14 -0000 1.8 --- aclocal.m4 10 Apr 2009 13:39:22 -0000 1.9 *************** *** 870,871 **** --- 870,872 ---- ]) # _AM_PROG_TAR + m4_include([acinclude.m4]) Index: ChangeLog =================================================================== RCS file: /cvsroot/cscope/cscope/ChangeLog,v retrieving revision 1.177 retrieving revision 1.178 diff -C2 -r1.177 -r1.178 *** ChangeLog 30 Jun 2008 21:36:48 -0000 1.177 --- ChangeLog 10 Apr 2009 13:39:22 -0000 1.178 *************** *** 1,2 **** --- 1,27 ---- + 2009-04-10 Hans-Bernhard Broeker <br...@ph...> + + * src/snprintf.c: Replacement implementation for missing snprintf + and vsprintf, from www.jhweiss.de. + + * acinclude: New macros to optionally activate a replacement for + missing snprintf and vsprintf, from www.jhweiss.de. + + * configure.in: Call new macros for snprintf and vsprintf. Drop + AC_FUNC_LSTAT in turn, since it would have required a replacement + implementation for lstat(). + + * src/Makefile.am (cscope_LDADD): Added LIBOBJS to automatically + include snprintf.o in the build if and only if needed. + + * configure, config.h.in, aclocal.m4, Makefile.in, + contrib/Makefile.in, doc/Makefile.in, src/Makefile.in: + Regenerated. + + * src/global.h: Add prototypes for replacement snprintf and + vsnprintf. + + * src/*.c: Replace all calls of sprintf by snprintf to avoid + possible buffer overflows. + 2008-06-30 Hans-Bernhard Broeker <br...@ph...> Index: config.h.in =================================================================== RCS file: /cvsroot/cscope/cscope/config.h.in,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** config.h.in 30 Jun 2008 21:36:48 -0000 1.19 --- config.h.in 10 Apr 2009 13:39:22 -0000 1.20 *************** *** 7,10 **** --- 7,13 ---- #undef HAS_CURSES + /* Define to 1 if you have the `asprintf' function. */ + #undef HAVE_ASPRINTF + /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. */ *************** *** 23,26 **** --- 26,32 ---- #undef HAVE_GETCWD + /* Define to 1 if the system has the type `intmax_t'. */ + #undef HAVE_INTMAX_T + /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H *************** *** 32,42 **** #undef HAVE_LIBREGEX /* Define to 1 if you have the `lstat' function. */ #undef HAVE_LSTAT - /* Define to 1 if `lstat' has the bug that it succeeds when given the - zero-length file name argument. */ - #undef HAVE_LSTAT_EMPTY_STRING_BUG - /* Define to 1 if you have the `memcpy' function. */ #undef HAVE_MEMCPY --- 38,56 ---- #undef HAVE_LIBREGEX + /* Define to 1 if you have the `localeconv' function. */ + #undef HAVE_LOCALECONV + + /* Define to 1 if you have the <locale.h> header file. */ + #undef HAVE_LOCALE_H + + /* Define to 1 if the system has the type `long double'. */ + #undef HAVE_LONG_DOUBLE + + /* Define to 1 if the system has the type `long long int'. */ + #undef HAVE_LONG_LONG_INT + /* Define to 1 if you have the `lstat' function. */ #undef HAVE_LSTAT /* Define to 1 if you have the `memcpy' function. */ #undef HAVE_MEMCPY *************** *** 51,54 **** --- 65,71 ---- #undef HAVE_NDIR_H + /* Define to 1 if the system has the type `ptrdiff_t'. */ + #undef HAVE_PTRDIFF_T + /* Define to 1 if you have the `regcmp' function. */ #undef HAVE_REGCMP *************** *** 66,72 **** #undef HAVE_SIGSETJMP ! /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H --- 83,95 ---- #undef HAVE_SIGSETJMP ! /* Define to 1 if you have a C99 compliant `snprintf' function. */ #undef HAVE_SNPRINTF + /* Define to 1 if you have the <stdarg.h> header file. */ + #undef HAVE_STDARG_H + + /* Define to 1 if you have the <stddef.h> header file. */ + #undef HAVE_STDDEF_H + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H *************** *** 87,90 **** --- 110,119 ---- #undef HAVE_STRING_H + /* Define to 1 if `decimal_point' is member of `struct lconv'. */ + #undef HAVE_STRUCT_LCONV_DECIMAL_POINT + + /* Define to 1 if `thousands_sep' is member of `struct lconv'. */ + #undef HAVE_STRUCT_LCONV_THOUSANDS_SEP + /* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. */ *************** *** 107,114 **** #undef HAVE_SYS_WINDOW_H /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H ! /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF --- 136,161 ---- #undef HAVE_SYS_WINDOW_H + /* Define to 1 if the system has the type `uintmax_t'. */ + #undef HAVE_UINTMAX_T + + /* Define to 1 if the system has the type `uintptr_t'. */ + #undef HAVE_UINTPTR_T + /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H ! /* Define to 1 if the system has the type `unsigned long long int'. */ ! #undef HAVE_UNSIGNED_LONG_LONG_INT ! ! /* Define to 1 if you have the <varargs.h> header file. */ ! #undef HAVE_VARARGS_H ! ! /* Define to 1 if you have the `vasprintf' function. */ ! #undef HAVE_VASPRINTF ! ! /* Define to 1 if you have the `va_copy' function or macro. */ ! #undef HAVE_VA_COPY ! ! /* Define to 1 if you have a C99 compliant `vsnprintf' function. */ #undef HAVE_VSNPRINTF *************** *** 116,122 **** #undef HAVE__SETMODE ! /* Define to 1 if `lstat' dereferences a symlink specified with a trailing ! slash. */ ! #undef LSTAT_FOLLOWS_SLASHED_SYMLINK /* We're using some variant of Linux */ --- 163,168 ---- #undef HAVE__SETMODE ! /* Define to 1 if you have the `__va_copy' function or macro. */ ! #undef HAVE___VA_COPY /* We're using some variant of Linux */ *************** *** 176,182 **** --- 222,235 ---- #undef YYTEXT_POINTER + /* Define to rpl_asprintf if the replacement function should be used. */ + #undef asprintf + /* Define to empty if `const' does not conform to ANSI C. */ #undef const + /* Define to the widest signed integer type if <stdint.h> and <inttypes.h> do + not define. */ + #undef intmax_t + /* Define to `int' if <sys/types.h> does not define. */ #undef mode_t *************** *** 187,188 **** --- 240,258 ---- /* Define to `unsigned int' if <sys/types.h> does not define. */ #undef size_t + + /* Define to rpl_snprintf if the replacement function should be used. */ + #undef snprintf + + /* Define to the widest unsigned integer type if <stdint.h> and <inttypes.h> + do not define. */ + #undef uintmax_t + + /* Define to the type of an unsigned integer type wide enough to hold a + pointer, if such a type exists, and if the system does not define it. */ + #undef uintptr_t + + /* Define to rpl_vasprintf if the replacement function should be used. */ + #undef vasprintf + + /* Define to rpl_vsnprintf if the replacement function should be used. */ + #undef vsnprintf Index: configure =================================================================== RCS file: /cvsroot/cscope/cscope/configure,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -r1.30 -r1.31 *** configure 30 Jun 2008 21:36:48 -0000 1.30 --- configure 10 Apr 2009 13:39:22 -0000 1.31 *************** *** 614,617 **** --- 614,618 ---- #endif" + ac_header_list= ac_subst_vars='SHELL PATH_SEPARATOR *************** *** 1686,1689 **** --- 1687,1692 ---- fi [...4686 lines suppressed...] + + + + + + + case " $LIBOBJS " in + *" snprintf.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS snprintf.$ac_objext" + ;; + esac + + _hw_cv_func_xprintf_replace_done=yes + fi + + + fi + Index: configure.in =================================================================== RCS file: /cvsroot/cscope/cscope/configure.in,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -r1.34 -r1.35 *** configure.in 30 Sep 2006 17:31:14 -0000 1.34 --- configure.in 10 Apr 2009 13:39:23 -0000 1.35 *************** *** 402,408 **** AC_TYPE_SIGNAL AC_CHECK_FUNCS(strchr memcpy memset setmode _setmode) ! AC_CHECK_FUNCS(getcwd regcmp regcomp strerror vsnprintf snprintf lstat) AC_CHECK_FUNCS(fixkeypad) ! AC_FUNC_LSTAT case "$host_os" in --- 402,411 ---- AC_TYPE_SIGNAL AC_CHECK_FUNCS(strchr memcpy memset setmode _setmode) ! AC_CHECK_FUNCS(getcwd regcmp regcomp strerror lstat) AC_CHECK_FUNCS(fixkeypad) ! HW_FUNC_SNPRINTF ! HW_FUNC_VSNPRINTF ! HW_FUNC_ASPRINTF ! HW_FUNC_VASPRINTF case "$host_os" in Index: Makefile.in =================================================================== RCS file: /cvsroot/cscope/cscope/Makefile.in,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -r1.10 -r1.11 *** Makefile.in 30 Jun 2008 21:36:48 -0000 1.10 --- Makefile.in 10 Apr 2009 13:39:23 -0000 1.11 *************** *** 44,48 **** subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ! am__aclocal_m4_deps = $(top_srcdir)/configure.in am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) --- 44,49 ---- subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ! am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ ! $(top_srcdir)/configure.in am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) |