Files
dbbccc5263 fix: extract core safety fixes from #597 (#621)
Extracted from #597 into a focused core correctness and memory-safety
change.

This checks startup allocations, bounds full log lines and query
construction, frees settings result sets on NULL-row paths, caches the
configured timestamp format, replaces advancing snprintf cursors with a
bounded append contract, fixes remote batch boundary loss, and converts
delimited hexadecimal OctetStrings without overflow. poller_output and
remote status pushes use the cross-vendor VALUES() form until #590
supplies an independently detected main-server capability.

Behavior worth calling out:
- colon/dash-delimited hexadecimal values that were previously stored as
zero now convert correctly
- values wider than 64 bits become U and count as collection errors
instead of producing undefined numeric conversion
- remote batches flush before the boundary-triggering row and refuse
truncated statements

Verification on macOS arm64:
- warning-enabled C99 configure/build
- forced make -B check on the final tree: 6 pass, 1 expected skip
- the skipped allocation-failure integration uses Linux LD_PRELOAD and
runs in Linux CI
- full VPATH make distcheck passed earlier in this branch
- mandatory independent pre-push review: PASS

Closes #564
Closes #565
Closes #566
Closes #567
Closes #588
Refs #590
Refs #597

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: TheWitness <copilot@users.noreply.github.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-09-23 10:19:42 -04:00

79 lines
2.1 KiB
Makefile

# Unit test Makefile for spine/tests/unit
#
# The test binaries are self-contained: each one carries a copy of the routine
# under test so it links without MySQL, Net-SNMP or the spine globals. Keep
# those copies byte-identical to the shipped source, or the tests stop being
# regression guards.
#
# Usage:
# make -- build and run
# make build -- build only
# make clean -- remove build artefacts
#
# test_linked exercises the full production object set and is intentionally
# driven by the top-level Automake suite, which supplies those dependencies.
CC ?= cc
PKG_CONFIG ?= pkg-config
BINDIR := bin
SPINE_ROOT := ../..
# cmocka via pkg-config, with a plain -lcmocka fallback for platforms that
# ship the library without a .pc file.
# test_util_strings.c pulls in common.h, which needs the MySQL and Net-SNMP
# headers. Discover them the same way configure does rather than hardcoding
# a prefix.
MYSQL_CFLAGS := $(shell mysql_config --include 2>/dev/null)
MYSQL_LIBS := $(shell mysql_config --libs 2>/dev/null)
NETSNMP_CFLAGS := $(shell net-snmp-config --base-cflags 2>/dev/null)
CMOCKA_CFLAGS := $(shell $(PKG_CONFIG) --cflags cmocka 2>/dev/null)
CMOCKA_LIBS := $(shell $(PKG_CONFIG) --libs cmocka 2>/dev/null)
ifeq ($(strip $(CMOCKA_LIBS)),)
CMOCKA_LIBS := -lcmocka
endif
CFLAGS ?= -O0 -g
CFLAGS += \
-std=c99 \
-D_DEFAULT_SOURCE \
-I$(SPINE_ROOT) \
-I$(SPINE_ROOT)/src/core \
-I$(SPINE_ROOT)/config \
$(CMOCKA_CFLAGS) \
$(MYSQL_CFLAGS) \
$(NETSNMP_CFLAGS) \
-Wall \
-Wextra \
-Wno-unused-parameter
LDLIBS := $(CMOCKA_LIBS) $(MYSQL_LIBS)
BUILD_FIXES := $(BINDIR)/test_build_fixes
SAFETY_FIXES := $(BINDIR)/test_safety_fixes
STRINGS := $(BINDIR)/test_util_strings
UTIL_PATHS := $(BINDIR)/test_util_paths
TARGETS := $(BUILD_FIXES) $(SAFETY_FIXES) $(STRINGS) $(UTIL_PATHS)
.PHONY: all build run clean
all: run
build: $(TARGETS)
$(BINDIR):
mkdir -p $(BINDIR)
$(BINDIR)/%: %.c | $(BINDIR)
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
run: $(TARGETS)
@rc=0; for t in $(TARGETS); do \
echo "== $$t"; \
$$t || rc=1; \
done; exit $$rc
clean:
rm -rf $(BINDIR)