From adf0fb74451bbdb57e60cb41b9d4c94c070e111a Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Wed, 19 Nov 2025 16:53:44 +0100 Subject: [PATCH 1/4] Don't merge! Signed-off-by: Lars Erik Wik --- tests/acceptance/Makefile.am | 3 +- tests/load/Makefile.am | 4 - tests/unit/Makefile.am | 157 +---------------------------------- 3 files changed, 3 insertions(+), 161 deletions(-) diff --git a/tests/acceptance/Makefile.am b/tests/acceptance/Makefile.am index 4e76f8df8e..77ebd8f744 100644 --- a/tests/acceptance/Makefile.am +++ b/tests/acceptance/Makefile.am @@ -91,7 +91,8 @@ endif # Keep the '+' in front for the command, needed for the sub-make # to run in parallel; TODO fix "make -n" not working: check-local: - + $(TESTS_ENVIRONMENT) MAKE=$(MAKE) $(srcdir)/testall + chmod 600 $(srcdir)/00_basics/03_bodies/114.cf $(srcdir)/default.cf.sub $(srcdir)/dcs.cf.sub $(srcdir)/plucked.cf.sub + $(srcdir)/testall --verbose --printlog $(srcdir)/00_basics/03_bodies/114.cf EXTRA_DIST = default.cf.sub dcs.cf.sub plucked.cf.sub run_with_server.cf.sub \ diff --git a/tests/load/Makefile.am b/tests/load/Makefile.am index 89c5762d81..1e7372fcf8 100644 --- a/tests/load/Makefile.am +++ b/tests/load/Makefile.am @@ -42,10 +42,6 @@ EXTRA_DIST = \ run_db_load.sh \ run_lastseen_threaded_load.sh -TESTS = \ - run_db_load.sh \ - run_lastseen_threaded_load.sh - check_PROGRAMS = db_load lastseen_load lastseen_threaded_load diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 3a4bb0a9d4..6b2a62022f 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -86,108 +86,9 @@ libdb_la_LIBADD = ../../libntech/libutils/libutils.la libdb_la_CFLAGS = $(AM_CFLAGS) check_PROGRAMS = \ - processes_select_test \ - arg_split_test \ - assoc_test \ - getopt_test \ - item_test \ - rlist_test \ - domainname_test \ - set_domainname_test \ - evalfunction_test \ - eval_context_test \ - regex_test \ - lastseen_test \ - lastseen_migration_test \ - changes_migration_test \ - db_test \ - db_concurrent_test \ - item_lib_test \ - crypto_symmetric_test \ - persistent_lock_test \ - package_versions_compare_test \ - files_lib_test \ - files_copy_test \ - parsemode_test \ - parser_test \ - passopenfile_test \ - policy_test \ - sort_test \ - file_name_test \ - logging_test \ - granules_test \ - scope_test \ - conversion_test \ - files_interfaces_test \ - connection_management_test \ - expand_test \ - string_expressions_test \ - var_expressions_test \ - process_terminate_unix_test \ - process_test \ - exec-config-test \ - generic_agent_test \ - syntax_test \ - sysinfo_test \ - variable_test \ - verify_databases_test \ - protocol_test \ - mon_cpu_test \ - mon_load_test \ - mon_processes_test \ - mustache_test \ - class_test \ - key_test \ - cf_upgrade_test \ - matching_test \ - strlist_test \ - addr_lib_test \ - policy_server_test \ - split_process_line_test \ - new_packages_promise_test \ iteration_test -if HAVE_AVAHI_CLIENT -if HAVE_AVAHI_COMMON -check_PROGRAMS += \ - findhub_test \ - avahi_config_test -endif -endif - -if !NT -check_PROGRAMS += redirection_test -noinst_PROGRAMS = redirection_test_stub - -redirection_test_stub_SOURCES = redirection_test_stub.c -endif - -check_SCRIPTS = dynamic_dependency_test.sh \ - tar_portability_test.sh - -if WITH_INIT_D_SCRIPT -check_SCRIPTS += init_script_test.sh -endif - -EXTRA_DIST += $(check_SCRIPTS) - -TESTS = $(check_PROGRAMS) $(check_SCRIPTS) - -if MACOSX -XFAIL_TESTS = set_domainname_test -XFAIL_TESTS += process_test -XFAIL_TESTS += mon_processes_test -XFAIL_TESTS += rlist_test -endif - -if AIX -XFAIL_TESTS = rlist_test -endif - -if HPUX -XFAIL_TESTS = mon_load_test # Redmine #3569 -endif - +TESTS = $(check_PROGRAMS) processes_select_test_SOURCES = processes_select_test.c processes_select_test_LDADD = libtest.la ../../libpromises/libpromises.la @@ -199,17 +100,6 @@ TESTS_ENVIRONMENT = DYLD_FORCE_FLAT_NAMESPACE=yes conversion_test_SOURCES = conversion_test.c ../../libpromises/conversion.c -if !BUILTIN_EXTENSIONS -check_PROGRAMS += enterprise_extension_test - -enterprise_extension_test_SOURCES = enterprise_extension_test.c - -check_LTLIBRARIES += cfengine-enterprise.la -cfengine_enterprise_la_SOURCES = enterprise_extension_test_lib.c -cfengine_enterprise_la_LDFLAGS = $(AM_LDFLAGS) \ - -avoid-version -module -shared -export-dynamic -rpath / -EXTRA_enterprise_extension_test_DEPENDENCIES = cfengine-enterprise.la -endif set_domainname_test_SOURCES = set_domainname_test.c set_domainname_test_LDADD = libtest.la ../../libpromises/libpromises.la @@ -306,44 +196,8 @@ rlist_test_CPPFLAGS = $(AM_CPPFLAGS) process_test_LDADD = libtest.la ../../libpromises/libpromises.la -if LINUX - -check_PROGRAMS += linux_process_test - -linux_process_test_SOURCES = linux_process_test.c \ - ../../libpromises/process_unix.c \ - ../../libpromises/process_linux.c \ - ../../libntech/libutils/file_lib.c -linux_process_test_LDADD = libtest.la ../../libntech/libutils/libutils.la - -endif - -if AIX - -check_PROGRAMS += aix_process_test -# We need to use -Wl,-bexpall when linking tests binaries on AIX -# because they provide dummy versions of some standard functions. -set_domainname_test_LDFLAGS = -Wl,-bexpall -evalfunction_test_LDFLAGS = -Wl,-bexpall -aix_process_test_SOURCES = aix_process_test.c \ - ../../libpromises/process_unix.c \ - ../../libpromises/process_aix.c \ - ../../libntech/libutils/file_lib.c -aix_process_test_LDADD = libtest.la ../../libntech/libutils/libutils.la - -endif - -if SOLARIS -check_PROGRAMS += solaris_process_test -solaris_process_test_SOURCES = solaris_process_test.c \ - ../../libpromises/process_unix.c \ - ../../libpromises/process_solaris.c \ - ../../libntech/libutils/file_lib.c -solaris_process_test_LDADD = libtest.la ../../libntech/libutils/libutils.la - -endif process_terminate_unix_test_SOURCES = process_terminate_unix_test.c \ ../../libpromises/process_unix.c @@ -399,14 +253,5 @@ cf_upgrade_test_SOURCES = cf_upgrade_test.c \ cf_upgrade_test_CPPFLAGS = -I$(top_srcdir)/cf-upgrade -I$(top_srcdir)/libntech/libutils -I$(top_srcdir) cf_upgrade_test_LDADD = libtest.la ../../libntech/libcompat/libcompat.la -if !NT -check_PROGRAMS += nfs_test -nfs_test_SOURCES = nfs_test.c -nfs_test_LDADD = ../../libpromises/libpromises.la libtest.la - -init_script_test_helper_SOURCES = init_script_test_helper.c -init_script_test.sh: init_script_test_helper -CLEANFILES += init_script_test_helper -endif EXTRA_DIST += init_script_test_helper.c EXTRA_DIST += init_script_test.sh From 5c7c3701721a7c4045f6b64d0b7a38f4f9c7be0c Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 20 Nov 2025 10:32:42 +0100 Subject: [PATCH 2/4] Fixed variadic argument alignment bug in StatFile on HP-UX IA-64 On HP-UX IA-64, mixing 32-bit (%d) and 64-bit (%jd/%ju) format specifiers in variadic arguments causes stack misalignment. In StatFile(), cf_makeholes, cf_ino, and cf_nlink were passed as uncast 32-bit integers among 64-bit arguments, causing all subsequent values (including cf_size) to be read from incorrect stack positions. This resulted in the client receiving a corrupted file size value (e.g., 212668465 instead of 821 bytes), triggering false "file corrupted in transit" errors during file copy operations. Fixed by casting cf_makeholes, cf_ino, and cf_nlink to (intmax_t) and changing their format specifiers from %d to %jd, ensuring consistent 64-bit alignment for all variadic arguments after the first parameter. Ticket: ENT-13508 Changelog: Title Signed-off-by: Lars Erik Wik --- cf-serverd/server_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cf-serverd/server_common.c b/cf-serverd/server_common.c index 916bbdffcc..c665335eb1 100644 --- a/cf-serverd/server_common.c +++ b/cf-serverd/server_common.c @@ -864,11 +864,11 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename) (intmax_t) cfst.cf_atime, (intmax_t) cfst.cf_mtime); snprintf(sendbuffer, CF_MSGSIZE, - "OK: %d %ju %ju %ju %ju %jd %jd %jd %jd %d %d %d %jd", + "OK: %d %ju %ju %ju %ju %jd %jd %jd %jd %jd %jd %jd %jd", cfst.cf_type, (uintmax_t) cfst.cf_mode, (uintmax_t) cfst.cf_lmode, (uintmax_t) cfst.cf_uid, (uintmax_t) cfst.cf_gid, (intmax_t) cfst.cf_size, (intmax_t) cfst.cf_atime, (intmax_t) cfst.cf_mtime, (intmax_t) cfst.cf_ctime, - cfst.cf_makeholes, cfst.cf_ino, cfst.cf_nlink, (intmax_t) cfst.cf_dev); + (intmax_t) cfst.cf_makeholes, (intmax_t) cfst.cf_ino, (intmax_t) cfst.cf_nlink, (intmax_t) cfst.cf_dev); SendTransaction(conn->conn_info, sendbuffer, 0, CF_DONE); From 338efb328ccf7423efd9ac87be41910fc40787c3 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 20 Nov 2025 11:59:58 +0100 Subject: [PATCH 3/4] Debugging Ticket: None Changelog: None Signed-off-by: Lars Erik Wik --- cf-serverd/server_common.c | 6 +++++- libcfnet/stat_cache.c | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cf-serverd/server_common.c b/cf-serverd/server_common.c index c665335eb1..1a706672a4 100644 --- a/cf-serverd/server_common.c +++ b/cf-serverd/server_common.c @@ -857,7 +857,10 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename) /* send as plain text */ - Log(LOG_LEVEL_DEBUG, "OK: type = %d, mode = %jo, lmode = %jo, " + Log(LOG_LEVEL_INFO, "ENT-13508: statbuf.st_size = %jd, cfst.cf_size = %jd", + (intmax_t) statbuf.st_size, (intmax_t) cfst.cf_size); + + Log(LOG_LEVEL_INFO, "OK: type = %d, mode = %jo, lmode = %jo, " "uid = %ju, gid = %ju, size = %jd, atime=%jd, mtime = %jd", cfst.cf_type, (uintmax_t) cfst.cf_mode, (uintmax_t) cfst.cf_lmode, (uintmax_t) cfst.cf_uid, (uintmax_t) cfst.cf_gid, (intmax_t) cfst.cf_size, @@ -870,6 +873,7 @@ int StatFile(ServerConnectionState *conn, char *sendbuffer, char *ofilename) (intmax_t) cfst.cf_atime, (intmax_t) cfst.cf_mtime, (intmax_t) cfst.cf_ctime, (intmax_t) cfst.cf_makeholes, (intmax_t) cfst.cf_ino, (intmax_t) cfst.cf_nlink, (intmax_t) cfst.cf_dev); + Log(LOG_LEVEL_INFO, "ENT-13508: sendbuffer = '%s'", sendbuffer); SendTransaction(conn->conn_info, sendbuffer, 0, CF_DONE); memset(sendbuffer, 0, CF_MSGSIZE); diff --git a/libcfnet/stat_cache.c b/libcfnet/stat_cache.c index 2e2dd797e8..35a1211943 100644 --- a/libcfnet/stat_cache.c +++ b/libcfnet/stat_cache.c @@ -33,6 +33,7 @@ #include /* Log */ #include /* EncryptString */ #include /* ProgrammingError */ +#include static void NewStatCache(Stat *data, AgentConnection *conn) { @@ -226,6 +227,8 @@ int cf_remote_stat(AgentConnection *conn, bool encrypt, const char *file, Stat cfst; + Log(LOG_LEVEL_INFO, "ENT-13508: Received STAT response: '%s'", recvbuffer); + ret = StatParseResponse(recvbuffer, &cfst); if (!ret) { @@ -234,6 +237,8 @@ int cf_remote_stat(AgentConnection *conn, bool encrypt, const char *file, return -1; } + Log(LOG_LEVEL_INFO, "ENT-13508: Parsed cf_size = %jd", (intmax_t) cfst.cf_size); + // If remote path is symbolic link, receive actual path here int recv_len = ReceiveTransaction(conn->conn_info, recvbuffer, NULL); if (recv_len == -1) @@ -358,6 +363,8 @@ bool StatParseResponse(const char *const buf, Stat *const statbuf) assert(buf != NULL); assert(statbuf != NULL); + Log(LOG_LEVEL_INFO, "%s", buf); + // use intmax_t here to provide enough space for large values coming over the protocol intmax_t d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12 = 0, d13 = 0; int res = sscanf(buf, "OK:" @@ -402,5 +409,7 @@ bool StatParseResponse(const char *const buf, Stat *const statbuf) statbuf->cf_nlink = d12; statbuf->cf_dev = (dev_t)d13; + Log(LOG_LEVEL_INFO, "ENT-13508: Size of file %jd", (intmax_t) statbuf->cf_size); + return true; } From 4ae7a51ceae3bf34c74e61681c9e501a8a3ea49d Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 20 Nov 2025 13:20:06 +0100 Subject: [PATCH 4/4] uio Ticket: None Changelog: None Signed-off-by: Lars Erik Wik --- cf-agent/verify_files_utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cf-agent/verify_files_utils.c b/cf-agent/verify_files_utils.c index 6a195e3e18..8c6b4b4e29 100644 --- a/cf-agent/verify_files_utils.c +++ b/cf-agent/verify_files_utils.c @@ -1119,6 +1119,14 @@ static PromiseResult VerifyCopy(EvalContext *ctx, return PROMISE_RESULT_FAIL; } + Log(LOG_LEVEL_INFO, "ENT-13508: After stat of '%s': st_size = %jd, sizeof(struct stat) = %zu, sizeof(off_t) = %zu", + source, (intmax_t) ssb.st_size, sizeof(struct stat), sizeof(off_t)); + + unsigned char *stat_size_bytes = (unsigned char *)&ssb.st_size; + Log(LOG_LEVEL_INFO, "ENT-13508: Raw bytes of ssb.st_size after stat: %02x %02x %02x %02x %02x %02x %02x %02x", + stat_size_bytes[0], stat_size_bytes[1], stat_size_bytes[2], stat_size_bytes[3], + stat_size_bytes[4], stat_size_bytes[5], stat_size_bytes[6], stat_size_bytes[7]); + PromiseResult result = PROMISE_RESULT_NOOP; if (ssb.st_nlink > 1) /* Preserve hard link structure when copying */ { @@ -1803,6 +1811,14 @@ bool CopyRegularFile(EvalContext *ctx, const char *source, const char *dest, con return false; } + Log(LOG_LEVEL_INFO, "ENT-13508: Comparing sizes: new_stat.st_size = %jd, sstat->st_size = %jd, &sstat = %p, &sstat->st_size = %p", + (intmax_t) new_stat.st_size, (intmax_t) sstat->st_size, (void*)sstat, (void*)&sstat->st_size); + + unsigned char *size_bytes = (unsigned char *)&sstat->st_size; + Log(LOG_LEVEL_INFO, "ENT-13508: Raw bytes of sstat->st_size (sizeof=%zu): %02x %02x %02x %02x %02x %02x %02x %02x", + sizeof(sstat->st_size), size_bytes[0], size_bytes[1], size_bytes[2], size_bytes[3], + size_bytes[4], size_bytes[5], size_bytes[6], size_bytes[7]); + if ((S_ISREG(new_stat.st_mode)) && (new_stat.st_size != sstat->st_size)) { RecordFailure(ctx, pp, attr,