From 82998a4eb191a1ad8f7736b862ff573b34e0908c Mon Sep 17 00:00:00 2001 From: Dan Mahoney Date: Wed, 22 Jul 2026 00:32:55 -0700 Subject: [PATCH] libopendkim: fix -Wpointer-sign warnings in header-name arrays and dkim_get_header() Addresses part of issue #361 (150 clang -Wpointer-sign warnings across libopendkim and opendkim). Two changes account for 38 of the 150: - dkim_should_signhdrs[], dkim_should_not_signhdrs[], and dkim_required_signhdrs[] were declared const u_char *[] but initialized from ordinary string literals, warning once per entry. Retyped to const char *[] to match. - dkim_get_header() took u_char *name but is called almost exclusively with string literals. Retyped to char *name, adding a cast at its one remaining u_char *-typed call site (dkiml_mbs[]). No behavior change (char and unsigned char share representation on every platform this builds for). Verified with a clang -Wpointer-sign build (150 -> 112 unique warnings) and `make check` (174/174 passing). The remaining ~112 warnings are scattered single-site mismatches needing individual judgment; left for a follow-up. --- CHANGES-202605.md | 1 + libopendkim/dkim.c | 16 ++++++++-------- libopendkim/dkim.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGES-202605.md b/CHANGES-202605.md index a1a06e2e..f1efe68a 100644 --- a/CHANGES-202605.md +++ b/CHANGES-202605.md @@ -174,6 +174,7 @@ A systematic audit of memory and resource leaks (issue #272) produced fixes acro - **Python 3 Twisted**: Replaced deprecated `defer.returnValue()` with plain `return` in contrib/repute. (#237) - **Compiler warning cleanup** (`-Wincompatible-pointer-types`, `-Wformat-truncation`): `entry_name` in the `-V` output path declared `const char *` to match `dkim_nametable_first`/`next` signatures; `snprintf` call sites in `dkim-util.c`, `opendkim.c`, and `opendkim-genzone.c` given explicit `%.*s` width bounds or larger buffers. (#360, issue #359) - **cppcheck static analysis cleanup**: A grab-bag of small findings from a `cppcheck --enable=warning,style,performance,portability` pass: a dead `ret == -1` recheck duplicated across `libvbr/vbr.c` and `librbl/rbl.c`'s DNS query paths; a `%zd`/`%zu` format string mismatch (and a typo) in `dkim-test.c`'s key-comparison error message; a `size_t` underflow in `dkim_sign()` where `dkim_base64_decode()`'s `int` return (-1 on error) was assigned directly into the `size_t` `dkim_keylen` field; an uninitialized-looking `end` pointer in the "t"/"x" tag validation in `dkim_process_set()`; a dead `if (!first)` conditional in `dkim_getsighdr_d()`'s tag-wrapping loop; and three redundant bounds-check clauses in `dkim_base32_encode()`'s unrolled loop. (#426) +- **`-Wpointer-sign` cleanup, part 1**: A clang build (issue #361) reports 150 `char *`/`u_char *` signedness-mismatch warnings across libopendkim and opendkim. This addresses the two highest-yield sources (38 of the 150) with no behavior change: `dkim_should_signhdrs[]`, `dkim_should_not_signhdrs[]`, and `dkim_required_signhdrs[]` were declared `const u_char *[]` but initialized from ordinary string literals, warning once per entry; retyped to `const char *[]` to match. `dkim_get_header()` took `u_char *name` but is called almost exclusively with string literals; retyped to `char *name`, with a cast added at its one remaining `u_char *`-typed call site (`dkiml_mbs[]`). The remaining ~112 warnings are scattered single-site mismatches needing individual judgment and are left for a follow-up. --- diff --git a/libopendkim/dkim.c b/libopendkim/dkim.c index 910ae332..eabd735b 100644 --- a/libopendkim/dkim.c +++ b/libopendkim/dkim.c @@ -214,7 +214,7 @@ void dkim_error (DKIM *, const char *, ...); #define DKIM_ISLWSP(x) ((x) == 011 || (x) == 013 || (x) == 014 || (x) == 040) /* recommended list of headers to sign, from RFC6376 Section 5.4 */ -const u_char *dkim_should_signhdrs[] = +const char *dkim_should_signhdrs[] = { "from", "reply-to", @@ -240,7 +240,7 @@ const u_char *dkim_should_signhdrs[] = }; /* recommended list of headers not to sign, from RFC6376 Section 5.4 */ -const u_char *dkim_should_not_signhdrs[] = +const char *dkim_should_not_signhdrs[] = { "return-path", "received", @@ -250,7 +250,7 @@ const u_char *dkim_should_not_signhdrs[] = }; /* required list of headers to sign */ -const u_char *dkim_required_signhdrs[] = +const char *dkim_required_signhdrs[] = { "from", NULL @@ -1361,7 +1361,7 @@ dkim_set_getudata(DKIM_SET *set) */ static struct dkim_header * -dkim_get_header(DKIM *dkim, u_char *name, size_t namelen, int inst) +dkim_get_header(DKIM *dkim, char *name, size_t namelen, int inst) { size_t len; struct dkim_header *hdr; @@ -1370,7 +1370,7 @@ dkim_get_header(DKIM *dkim, u_char *name, size_t namelen, int inst) assert(name != NULL); if (namelen == 0) - len = strlen((char *) name); + len = strlen(name); else len = namelen; @@ -1378,7 +1378,7 @@ dkim_get_header(DKIM *dkim, u_char *name, size_t namelen, int inst) { if (hdr->hdr_namelen == len && strncasecmp((char *) hdr->hdr_text, - (char *) name, len) == 0) + name, len) == 0) { if (inst == 0) return hdr; @@ -4151,7 +4151,7 @@ dkim_eom_verify(DKIM *dkim, _Bool *testkey) u_char *domain; u_char *user; - hdr = dkim_get_header(dkim, (u_char *) DKIM_FROMHEADER, + hdr = dkim_get_header(dkim, DKIM_FROMHEADER, DKIM_FROMHEADER_LEN, 0); if (hdr == NULL) { @@ -6162,7 +6162,7 @@ dkim_sig_process(DKIM *dkim, DKIM_SIGINFO *sig) for (c = 0; dkim->dkim_libhandle->dkiml_mbs[c] != NULL; c++) { if (dkim_get_header(dkim, - dkim->dkim_libhandle->dkiml_mbs[c], + (char *) dkim->dkim_libhandle->dkiml_mbs[c], 0, 0) != NULL && !dkim_sig_hdrsigned(sig, dkim->dkim_libhandle->dkiml_mbs[c])) diff --git a/libopendkim/dkim.h b/libopendkim/dkim.h index 178b4930..0756d796 100644 --- a/libopendkim/dkim.h +++ b/libopendkim/dkim.h @@ -1981,10 +1981,10 @@ extern const char *dkim_getsslbuf (DKIM *dkim); extern const char *dkim_sig_getsslbuf (DKIM_SIGINFO *sig); /* list of headers that should be signed, per RFC6376 Section 5.4 */ -extern const u_char *dkim_should_signhdrs[]; +extern const char *dkim_should_signhdrs[]; /* list of headers that should not be signed, per RFC6376 Section 5.4 */ -extern const u_char *dkim_should_not_signhdrs[]; +extern const char *dkim_should_not_signhdrs[]; /* ** DKIM_CODE_TO_NAME -- translate a mnemonic code to its name