# are not warning-free for one or another reason. If you manage to fix one of
# these cases, please remember to remove respective exemption below to help any
# later warnings in the same matrix subset trigger an error.
-# shellcheck disable=SC2006
-case `os_id`/"$CMAKE" in
-FreeBSD-*/yes)
- case `cc_id` in
- clang-*)
- # tcpdump.c:2434:32: error: '_Generic' is a C11 extension
- # [-Werror,-Wc11-extensions]
- # tcpdump.c:2439:26: error: '_Generic' is a C11 extension
- # [-Werror,-Wc11-extensions]
- # tcpdump.c:2443:9: error: '_Generic' is a C11 extension
- # [-Werror,-Wc11-extensions]
- TCPDUMP_TAINTED=yes
- ;;
- esac
- ;;
-esac
+
+# (There are no exemptions right now.)
+
# shellcheck disable=SC2006
[ "$TCPDUMP_TAINTED" != yes ] && CFLAGS=`cc_werr_cflags`
DIAG_DO_PRAGMA(clang diagnostic ignored "-Wdeprecated-declarations")
#define DIAG_ON_DEPRECATION \
DIAG_DO_PRAGMA(clang diagnostic pop)
+
+ /*
+ * Clang supports the generic C11 extension even if run with the -std=gnu99
+ * flag, which leads FreeBSD <sys/cdefs.h> to use the extension, which
+ * results in Clang emitting a -Wc11-extensions warning. The warning is not
+ * documented in the user manual, but it happens with Clang 10.0.1 on
+ * FreeBSD 12.2, so let's use that as a reference.
+ */
+ #if ND_IS_AT_LEAST_CLANG_VERSION(10,0)
+ #define DIAG_OFF_C11_EXTENSIONS \
+ DIAG_DO_PRAGMA(clang diagnostic push) \
+ DIAG_DO_PRAGMA(clang diagnostic ignored "-Wc11-extensions")
+ #define DIAG_ON_C11_EXTENSIONS \
+ DIAG_DO_PRAGMA(clang diagnostic pop)
+ #endif
#elif ND_IS_AT_LEAST_GNUC_VERSION(4,2)
/* GCC apparently doesn't complain about ORing enums together. */
#define DIAG_OFF_ASSIGN_ENUM
DIAG_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
#define DIAG_ON_DEPRECATION \
DIAG_DO_PRAGMA(GCC diagnostic pop)
+ /*
+ * GCC supports -Wc99-c11-compat since version 5.1.0, but the warning does
+ * not trigger for now, so let's just leave it be.
+ */
#else
#define DIAG_OFF_ASSIGN_ENUM
#define DIAG_ON_ASSIGN_ENUM
#define DIAG_ON_DEPRECATION
#endif
+#ifndef DIAG_OFF_C11_EXTENSIONS
+#define DIAG_OFF_C11_EXTENSIONS
+#endif
+#ifndef DIAG_ON_C11_EXTENSIONS
+#define DIAG_ON_C11_EXTENSIONS
+#endif
+
#endif /* _diag_control_h */
#endif
if (Cflag != 0 || Gflag != 0) {
#ifdef HAVE_CAPSICUM
- dumpinfo.WFileName = strdup(basename(WFileName));
+ /*
+ * basename() and dirname() may modify their input buffer
+ * and they do since FreeBSD 12.0, but they didn't before.
+ * Hence use the return value only, but always assume the
+ * input buffer has been modified and would need to be
+ * reset before the next use.
+ */
+ char *WFileName_copy;
+
+ if ((WFileName_copy = strdup(WFileName)) == NULL) {
+ error("Unable to allocate memory for file %s",
+ WFileName);
+ }
+ DIAG_OFF_C11_EXTENSIONS
+ dumpinfo.WFileName = strdup(basename(WFileName_copy));
+ DIAG_ON_C11_EXTENSIONS
if (dumpinfo.WFileName == NULL) {
error("Unable to allocate memory for file %s",
WFileName);
}
- dumpinfo.dirfd = open(dirname(WFileName),
+ free(WFileName_copy);
+
+ if ((WFileName_copy = strdup(WFileName)) == NULL) {
+ error("Unable to allocate memory for file %s",
+ WFileName);
+ }
+ DIAG_OFF_C11_EXTENSIONS
+ char *WFileName_dirname = dirname(WFileName_copy);
+ DIAG_ON_C11_EXTENSIONS
+ dumpinfo.dirfd = open(WFileName_dirname,
O_DIRECTORY | O_RDONLY);
if (dumpinfo.dirfd < 0) {
error("unable to open directory %s",
- dirname(WFileName));
+ WFileName_dirname);
}
+ free(WFileName_dirname);
+ free(WFileName_copy);
+
cap_rights_init(&rights, CAP_CREATE, CAP_FCNTL,
CAP_FTRUNCATE, CAP_LOOKUP, CAP_SEEK, CAP_WRITE);
if (cap_rights_limit(dumpinfo.dirfd, &rights) < 0 &&