Skip to content

Commit

Permalink
Merge pull request #5656 from larsewi/violation
Browse files Browse the repository at this point in the history
CFE-4454: Fixed ODR violations in ASAN Unit Tests
  • Loading branch information
larsewi authored Dec 16, 2024
2 parents 0b53a32 + e8efa14 commit 04e8624
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/asan_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Compile and link (make)
run: make -j8 CFLAGS="-Werror -Wall -fsanitize=address" LDFLAGS="-fsanitize=address"
- name: Run unit tests
run: ASAN_OPTIONS=detect_odr_violation=0 make -C tests/unit CFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" check
run: make -C tests/unit CFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" check
4 changes: 4 additions & 0 deletions libpromises/evalfunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -10311,6 +10311,9 @@ static const FnCallArg DATATYPE_ARGS[] =

/* see fncall.h enum FnCallType */

/* In evalfunction_test.c we both include this file and link with libpromises.
* This guard makes sure we don't get a duplicate definition of this symbol */
#ifndef CFENGINE_EVALFUNCTION_TEST_C
const FnCallType CF_FNCALL_TYPES[] =
{
FnCallTypeNew("accessedbefore", CF_DATA_TYPE_CONTEXT, ACCESSEDBEFORE_ARGS, &FnCallIsAccessedBefore, "True if arg1 was accessed before arg2 (atime)",
Expand Down Expand Up @@ -10715,3 +10718,4 @@ const FnCallType CF_FNCALL_TYPES[] =

FnCallTypeNewNull()
};
#endif // CFENGINE_EVALFUNCTION_TEST_C
15 changes: 5 additions & 10 deletions tests/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ if MACOSX
XFAIL_TESTS = set_domainname_test
XFAIL_TESTS += process_test
XFAIL_TESTS += mon_processes_test
XFAIL_TESTS += rlist_test
endif

if HPUX
Expand Down Expand Up @@ -246,18 +247,13 @@ db_concurrent_test_SOURCES = db_concurrent_test.c
db_concurrent_test_LDADD = libtest.la libdb.la

lastseen_test_SOURCES = lastseen_test.c \
../../libpromises/item_lib.c \
../../libpromises/lastseen.c \
../../libntech/libutils/statistics.c
#lastseen_test_CPPFLAGS = $(libdb_la_CPPFLAGS)
lastseen_test_LDADD = libtest.la libdb.la ../../libpromises/libpromises.la
lastseen_test_LDADD = libtest.la ../../libpromises/libpromises.la

lastseen_migration_test_SOURCES = lastseen_migration_test.c \
../../libpromises/lastseen.c \
../../libntech/libutils/statistics.c \
../../libpromises/item_lib.c
lastseen_migration_test_SOURCES = lastseen_migration_test.c
#lastseen_migration_test_CPPFLAGS = $(libdb_la_CPPFLAGS)
lastseen_migration_test_LDADD = libdb.la ../../libpromises/libpromises.la
lastseen_migration_test_LDADD = ../../libpromises/libpromises.la

CLEANFILES = *.gcno *.gcda cfengine-enterprise.so

Expand Down Expand Up @@ -293,8 +289,7 @@ connection_management_test_LDADD = ../../libpromises/libpromises.la \
libtest.la \
../../cf-serverd/libcf-serverd.la

rlist_test_SOURCES = rlist_test.c \
../../libpromises/rlist.c
rlist_test_SOURCES = rlist_test.c
rlist_test_LDADD = libtest.la ../../libpromises/libpromises.la
# Workaround for object file basename conflicts, search the web for
# "automake created with both libtool and without"
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/evalfunction_test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <test.h>

/* Protect against duplicate definition of symbol CF_FNCALL_TYPES since we are
* including evalfunction.c */
#define CFENGINE_EVALFUNCTION_TEST_C

#include <eval_context.h>
#include <evalfunction.c>

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/lastseen_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,7 @@ void FatalError(ARG_UNUSED char *s, ...)
exit(42);
}

HashMethod CF_DEFAULT_DIGEST;
pthread_mutex_t *cft_output;
char VIPADDRESS[CF_MAX_IP_LEN];
RSA *PUBKEY;
bool MINUSF;

char *HashPrintSafe(ARG_UNUSED char *dst, ARG_UNUSED size_t dst_size,
ARG_UNUSED const unsigned char *digest,
Expand Down
1 change: 0 additions & 1 deletion tests/unit/rlist_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ const void *EvalContextVariableGet(const EvalContext *ctx, const VarRef *lval, D
fail();
}

pthread_mutex_t *cft_lock;
int __ThreadLock(pthread_mutex_t *name)
{
return true;
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/set_domainname_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
#include <rlist.h>
#include <enterprise_extension.h>

/* Global variables we care about */

char VFQNAME[CF_MAXVARSIZE];
char VUQNAME[CF_MAXVARSIZE / 2];
char VDOMAIN[CF_MAXVARSIZE / 2];

static struct hostent h = {
.h_name = "laptop.intra.cfengine.com"
Expand Down

0 comments on commit 04e8624

Please sign in to comment.