diff --git a/config-linuxmodule.h.in b/config-linuxmodule.h.in index 9c50fcd742..511d9c0cc7 100644 --- a/config-linuxmodule.h.in +++ b/config-linuxmodule.h.in @@ -115,6 +115,9 @@ /* Define if you have the skb_recycle function. */ #undef HAVE_SKB_RECYCLE +/* Define if you have the strnlen function. */ +#define HAVE_STRNLEN 1 + /* Define to 1 if Linux defines the type 'uintptr_t'. */ #undef HAVE_UINTPTR_T_LINUXMODULE diff --git a/config-userlevel.h.in b/config-userlevel.h.in index b71565a18b..2396c3147e 100644 --- a/config-userlevel.h.in +++ b/config-userlevel.h.in @@ -132,6 +132,9 @@ /* Define if you have the header file. */ #undef HAVE_STRINGS_H +/* Define if you have the strnlen function. */ +#undef HAVE_STRNLEN + /* Define if you have the strtoul function. */ #undef HAVE_STRTOUL diff --git a/configure b/configure index 55544ad2e3..2b07e1adb3 100755 --- a/configure +++ b/configure @@ -6473,7 +6473,7 @@ fi done -for ac_func in random snprintf strtoul tcgetpgrp vsnprintf +for ac_func in random snprintf strnlen strtoul tcgetpgrp vsnprintf do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.in b/configure.in index 63b7e132d3..ec366335e7 100644 --- a/configure.in +++ b/configure.in @@ -407,7 +407,7 @@ dnl AC_LANG_C AC_REPLACE_FUNCS(strerror) -AC_CHECK_FUNCS(random snprintf strtoul tcgetpgrp vsnprintf) +AC_CHECK_FUNCS(random snprintf strnlen strtoul tcgetpgrp vsnprintf) AC_LANG_CPLUSPLUS diff --git a/lib/error.cc b/lib/error.cc index 7616873746..b56823b760 100644 --- a/lib/error.cc +++ b/lib/error.cc @@ -487,8 +487,13 @@ ErrorHandler::vxformat(int default_flags, const char *s, va_list val) if (flags & cf_alternate_form) { strstore = String(s1).printable(); len = strstore.length(); - } else - len = strlen(s1); + } else { +#if HAVE_STRNLEN + len = (precision >= 0 ? strnlen(s, precision) : strlen(s)); +#else + len = strlen(s1); // XXX might touch uninitialized memory +#endif + } // adjust length for precision if (precision >= 0 && precision < len)