Skip to content

Commit

Permalink
config-time __attribute_format_wprintf check
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Aug 27, 2020
1 parent eac37ae commit a46518a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,19 @@ AX_GCC_FUNC_ATTRIBUTE(returns_nonnull)
AX_GCC_FUNC_ATTRIBUTE(format_wprintf)
AX_GCC_FUNC_ATTRIBUTE(format_wscanf)

if test x$ax_cv_have_func_attribute_format_wprintf = xyes; then
HAVE_ATTRIBUTE_FORMAT_WPRINTF=1
else
HAVE_ATTRIBUTE_FORMAT_WPRINTF=0
fi
if test x$ax_cv_have_func_attribute_format_wscanf = xyes; then
HAVE_ATTRIBUTE_FORMAT_WSCANF=1
else
HAVE_ATTRIBUTE_FORMAT_WSCANF=0
fi
AC_SUBST(HAVE_ATTRIBUTE_FORMAT_WPRINTF)
AC_SUBST(HAVE_ATTRIBUTE_FORMAT_WSCANF)

builtins_chk="memcpy memmove memset strcpy strncpy strcat strncat
printf sprintf snprintf swprintf
vfprintf vfwprintf vsprintf vsnprintf"
Expand Down
5 changes: 3 additions & 2 deletions include/safe_str_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*
* October 2008, Bo Berry
* September 2017, Reini Urban
* August 2020, Reini Urban
*
* Copyright (c) 2008-2011, 2013 by Cisco Systems, Inc.
* Copyright (c) 2017-2018 by Reini Urban
* Copyright (c) 2017-2018, 2020 by Reini Urban
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
Expand Down Expand Up @@ -155,7 +156,7 @@ char * strtok_s(char *_Str,const char *_Delim,char **_Context); */
/* now __STDC_WANT_LIB_EXT1__ >= 1 compatible */
#ifdef SAFECLIB_HAVE_C99
EXTERN int _sprintf_s_chk(char *restrict dest, const rsize_t dmax,
const size_t destbos, const char *restrict fmt, ...)
const size_t destbos, const char *restrict fmt, ...)
__attribute_format__(printf,4,5) BOS_CHK(dest) BOS_FMT(fmt);
#define sprintf_s(dest, dmax, ...) \
_sprintf_s_chk(dest, dmax, BOS(dest), __VA_ARGS__)
Expand Down
36 changes: 24 additions & 12 deletions include/safe_types.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,42 @@ typedef int errno_t;
# define restrict __restrict
#endif

#endif /* __KERNEL__ */

/* C11 appendix K types - specific for bounds checking */
#ifndef _RSIZE_T /* PGI */
typedef size_t rsize_t;
#endif

#ifndef RSIZE_MAX
#define RSIZE_MAX (~(rsize_t)0) /* leave here for completeness */
#endif

#ifdef __GNUC__ /* also clang and icc */

#define __attribute_format__(type, index, check) \
__attribute__((format(type, index, check)))
/* stalled since 2008 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64862
/* Stalled since 2008 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64862
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38308 */
#if @HAVE_ATTRIBUTE_FORMAT_WPRINTF@
#define __attribute_format_wprintf(index, check) \
/* __attribute__((format(__wprintf__, index, check))) */
#define __attribute_format_wscanf(index, check) \
/* __attribute__((format(__wscanf__, index, check))) */
__attribute__((format(__wprintf__, index, check)))
#else
#define __attribute_format__(type, index, check)
#define __attribute_format_wprintf(index, check)
#endif
#if @HAVE_ATTRIBUTE_FORMAT_WSCANF@
#define __attribute_format_wscanf(index, check) \
__attribute__((format(__wscanf__, index, check)))
#else
#define __attribute_format_wscanf(index, check)
#endif

#endif /* __KERNEL__ */
#else

/* C11 appendix K types - specific for bounds checking */
#ifndef _RSIZE_T /* PGI */
typedef size_t rsize_t;
#endif
#define __attribute_format__(type, index, check)
#define __attribute_format_wprintf(index, check)
#define __attribute_format_wscanf(index, check)

#ifndef RSIZE_MAX
#define RSIZE_MAX (~(rsize_t)0) /* leave here for completeness */
#endif

#ifdef __cplusplus
Expand Down

0 comments on commit a46518a

Please sign in to comment.