Skip to content

Commit

Permalink
Avoid running off the end of a non-null-terminated string.
Browse files Browse the repository at this point in the history
Thanks to Cliff Frey for noticing this.
  • Loading branch information
kohler committed May 26, 2010
1 parent 94e8f7b commit 850cc46
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions config-linuxmodule.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions config-userlevel.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
/* Define if you have the <strings.h> 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

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 7 additions & 2 deletions lib/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 850cc46

Please sign in to comment.