Skip to content

Commit e2304db

Browse files
authored
fix: quiet -Walloc-size-larger-than and -Wformat-truncation warnings (#436)
* fix: quiet -Walloc-size-larger-than and -Wformat-truncation warnings OPENDMARC_MAX_SHELVES_LG2 was derived from sizeof(size_t) under the assumption that OPENDMARC_HASH_SHELF is <= 32 bytes, but it actually holds a pthread_mutex_t and runs 48-72 bytes depending on platform, so the theoretical max calloc() request could exceed the allocator limit. The only real caller asks for 8192 buckets, so cap the table size at a fixed, generous bound instead. MAXHEADER was sized so that a maxed-out authservid_hdr plus a maxed-out From-domain could together exceed the malloc'd header buffer, risking silent truncation of the Authentication-Results header in pathological cases. Double it so the worst case fits. * fix: enable subdir-objects to quiet automake forward-incompat warning test_arcares and test_spf_parse pull source files from $(top_srcdir)/opendmarc/, which automake warns will become a hard error in a future release without subdir-objects enabled. Verified make check still passes (13/13) with objects now placed in a path mirroring their source tree instead of being flattened.
1 parent db07e8f commit e2304db

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

libopendmarc/opendmarc_internal.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,15 @@ typedef struct {
209209
#define OPENDMARC_MIN_SHELVES (1 << OPENDMARC_MIN_SHELVES_LG2)
210210

211211
/*
212-
* max * sizeof internal_entry must fit into size_t.
213-
* assumes internal_entry is <= 32 (2^5) bytes.
212+
* Largest table size opendmarc_hash_init() will honor. The real
213+
* caller (opendmarc_tld.c) only ever asks for 8192; this just keeps a
214+
* runaway or hostile tablesize argument from reaching calloc(). Fixed
215+
* well below any allocator limit rather than derived from sizeof(size_t),
216+
* since the size of OPENDMARC_HASH_SHELF (which includes a pthread_mutex_t)
217+
* varies by platform and a sizeof-derived bound can creep past what
218+
* calloc() will actually allocate.
214219
*/
215-
#define OPENDMARC_MAX_SHELVES_LG2 (sizeof (size_t) * 8 - 1 - 5)
220+
#define OPENDMARC_MAX_SHELVES_LG2 24
216221
#define OPENDMARC_MAX_SHELVES ((size_t)1 << OPENDMARC_MAX_SHELVES_LG2)
217222

218223
typedef struct {

libopendmarc/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
AUTOMAKE_OPTIONS = subdir-objects
12
SUBDIRS=testfiles
23
LDADD = ../libopendmarc.la $(LIBRESOLV)
34
AM_CPPFLAGS = -I.. -I../..

opendmarc/opendmarc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#define REPORTCMD_EXIT_SUPPRESSED 2 /* ReportCommand sent nothing; all recipients were suppressed by policy (e.g. NoReportsList/StaleMARC), not an error */
3838
#define JOBIDUNKNOWN "(unknown-jobid)"
3939
#define MAXARGV 65536
40-
#define MAXHEADER 4096
40+
#define MAXHEADER 8192
4141
#define TEMPFILE "/var/tmp/dmarcXXXXXX"
4242

4343
#define AUTHRESULTSHDR "Authentication-Results"

0 commit comments

Comments
 (0)