opnsense-src/sys/modules/dtrace/dtrace/Makefile
Bryan Drewery f222a6b886 dtrace: Fix /"string" == NULL/ comparisons using an uninitialized value.
A test of this is funcs/tst.strtok.d which has this filter:

    BEGIN
    /(this->field = strtok(this->str, ",")) == NULL/
    {
            exit(1);
    }
The test will randomly fail with exit status of 1 indicating that this->field
was NULL even though printing it out shows it is not.

This is compiled to the DTrace instruction set:
    // Pushed arguments not shown here
    // call strtok() and set result into %r1
    07: 2f001f01    call DIF_SUBR(31), %r1          ! strtok
    // set thread local scalar this->field from %r1
    08: 39050101    stls %r1, DT_VAR(1281)          ! DT_VAR(1281) = "field"
    // Prepare for the == comparison
    // Set right side of %r2 to NULL
    09: 25000102    setx DT_INTEGER[1], %r2         ! 0x0
    // string compare %r1 (strtok result) to %r2
    10: 27010200    scmp %r1, %r2

In this case only %r1 is loaded with a string limit set to lim1.  %r2 being
NULL does not get loaded and does not set lim2.  Then we call dtrace_strncmp()
with MIN(lim1, lim2) resulting in passing 0 and comparing neither side.
dtrace_strncmp() handles this case fine and it already has been while
being lucky with what lim2 was [un]initialized as.

Reviewed by:	markj, Don Morris <dgmorris AT earthlink.net>
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D27671
2021-01-08 14:37:17 -08:00

65 lines
1.6 KiB
Makefile

# $FreeBSD$
SYSDIR?= ${SRCTOP}/sys
ARCHDIR= ${MACHINE_CPUARCH}
.PATH: ${SYSDIR}/cddl/contrib/opensolaris/uts/common/dtrace
.PATH: ${SYSDIR}/cddl/compat/opensolaris/kern
.PATH: ${SYSDIR}/cddl/kern
.PATH: ${SYSDIR}/cddl/dev/dtrace
.PATH: ${SYSDIR}/cddl/dev/dtrace/${ARCHDIR}
KMOD= dtrace
SRCS= dtrace.c \
dtrace_xoroshiro128_plus.c \
dtrace_asm.S \
dtrace_subr.c
.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
.PATH: ${SYSDIR}/cddl/dev/dtrace/x86
SRCS+= dis_tables.c \
instr_size.c
CFLAGS+= -I${SYSDIR}/cddl/contrib/opensolaris/uts/intel \
-I${SYSDIR}/cddl/dev/dtrace/x86
.endif
CFLAGS+= ${OPENZFS_CFLAGS}
SRCS+= bus_if.h device_if.h vnode_if.h
# Needed for dtrace_asm.S
DPSRCS+= assym.inc
# These are needed for assym.inc
SRCS+= opt_kstack_pages.h opt_nfs.h opt_hwpmc_hooks.h
#This is needed for dtrace.c
SRCS += opensolaris_taskq.c
.if ${MACHINE_CPUARCH} == "i386"
SRCS+= opt_apic.h
.endif
CFLAGS+= -I${SYSDIR}/cddl/compat/opensolaris \
-I${SYSDIR}/cddl/dev/dtrace \
-I${SYSDIR}/cddl/dev/dtrace/${ARCHDIR} \
-I${SYSDIR}/cddl/contrib/opensolaris/uts/common \
-I${SYSDIR}/cddl/contrib/opensolaris/uts/common/dtrace \
-I${SYSDIR}/cddl/contrib/opensolaris/common/util \
-I${SYSDIR} -DDIS_MEM
EXPORT_SYMS= dtrace_register \
dtrace_unregister \
dtrace_probe_lookup
dtrace_asm.o: assym.inc
.include <bsd.kmod.mk>
CFLAGS+= -include ${SYSDIR}/cddl/compat/opensolaris/sys/debug_compat.h
CFLAGS.dtrace_asm.S+= -D_SYS_ERRNO_H_ -D_SYS_PARAM_H_ -DLOCORE
CWARNFLAGS+= ${OPENZFS_CWARNFLAGS}
CWARNFLAGS+= -Wno-parentheses
CWARNFLAGS+= -Wno-cast-qual
CWARNFLAGS+= -Wno-unused