Commit d4ab70f2 authored by Rich Salz's avatar Rich Salz Committed by Rich Salz
Browse files

Test for NULL ptr == 0



Add a test to ensure that "char *p = NULL" is equivalent to
all-bytes-zero.

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
parent b0809bc8
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ LIBFIPS= -L.. -lfips
# Prefix for logline for each test
START= @@@ START

NPTEST=		nptest
BNTEST=		bntest
ECTEST=		ectest
ECDSATEST=	ecdsatest
@@ -80,7 +81,9 @@ SSLSKEWITH0PTEST= sslskewith0ptest.pl

TESTS=		alltests

EXE=	$(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT)  $(ECDSATEST)$(EXE_EXT) $(ECDHTEST)$(EXE_EXT) $(GMDIFFTEST)$(EXE_EXT) $(PBELUTEST)$(EXE_EXT) $(IDEATEST)$(EXE_EXT) \
EXE=	$(NPTEST)$(EXE_EXT) $(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT) \
	$(ECDSATEST)$(EXE_EXT) $(ECDHTEST)$(EXE_EXT) $(GMDIFFTEST)$(EXE_EXT) \
	$(PBELUTEST)$(EXE_EXT) $(IDEATEST)$(EXE_EXT) \
	$(MD2TEST)$(EXE_EXT)  $(MD4TEST)$(EXE_EXT) $(MD5TEST)$(EXE_EXT) $(HMACTEST)$(EXE_EXT) $(WPTEST)$(EXE_EXT) \
	$(RC2TEST)$(EXE_EXT) $(RC4TEST)$(EXE_EXT) $(RC5TEST)$(EXE_EXT) \
	$(DESTEST)$(EXE_EXT) $(SHA1TEST)$(EXE_EXT) $(SHA256TEST)$(EXE_EXT) $(SHA512TEST)$(EXE_EXT) \
@@ -98,7 +101,8 @@ EXE= $(BNTEST)$(EXE_EXT) $(ECTEST)$(EXE_EXT) $(ECDSATEST)$(EXE_EXT) $(ECDHTEST)

# $(METHTEST)$(EXE_EXT)

OBJ=	$(BNTEST).o $(ECTEST).o  $(ECDSATEST).o $(ECDHTEST).o $(GMDIFFTEST).o $(PBELUTEST).o $(IDEATEST).o \
OBJ=	$(NPTEST).o $(BNTEST).o $(ECTEST).o \
	$(ECDSATEST).o $(ECDHTEST).o $(GMDIFFTEST).o $(PBELUTEST).o $(IDEATEST).o \
	$(MD2TEST).o $(MD4TEST).o $(MD5TEST).o \
	$(HMACTEST).o $(WPTEST).o \
	$(RC2TEST).o $(RC4TEST).o $(RC5TEST).o \
@@ -111,7 +115,8 @@ OBJ= $(BNTEST).o $(ECTEST).o $(ECDSATEST).o $(ECDHTEST).o $(GMDIFFTEST).o $(PBE
	$(CONSTTIMETEST).o $(VERIFYEXTRATEST).o $(CLIENTHELLOTEST).o \
	$(PACKETTEST).o testutil.o

SRC=	$(BNTEST).c $(ECTEST).c  $(ECDSATEST).c $(ECDHTEST).c $(GMDIFFTEST).c $(PBELUTEST).c $(IDEATEST).c \
SRC=	$(NPTEST).c $(BNTEST).c $(ECTEST).c \
	$(ECDSATEST).c $(ECDHTEST).c $(GMDIFFTEST).c $(PBELUTEST).c $(IDEATEST).c \
	$(MD2TEST).c  $(MD4TEST).c $(MD5TEST).c \
	$(HMACTEST).c $(WPTEST).c \
	$(RC2TEST).c $(RC4TEST).c $(RC5TEST).c \
@@ -152,6 +157,7 @@ apps:
	@(cd ..; $(MAKE) DIRS=apps all)

alltests: \
	test_np \
	test_des test_gmdiff test_idea test_sha test_md4 test_md5 test_hmac \
	test_pbelu test_md2 test_mdc2 test_wp \
	test_rmd test_rc2 test_rc4 test_rc5 test_bf test_cast \
@@ -165,6 +171,10 @@ alltests: \
	test_constant_time test_verify_extra test_clienthello test_packet \
	test_sslvertol test_sslextension test_sslsessionticket test_sslskewith0p

test_np: $(NPTEST)$(EXE_EXT)
	@echo $(START) $@
	./$(NPTEST)

test_evp: $(EVPTEST)$(EXE_EXT) evptests.txt
	@echo $(START) $@
	../util/shlib_wrap.sh ./$(EVPTEST) evptests.txt
@@ -891,6 +901,7 @@ mdc2test.o: ../include/openssl/objects.h ../include/openssl/opensslconf.h
mdc2test.o: ../include/openssl/opensslv.h ../include/openssl/ossl_typ.h
mdc2test.o: ../include/openssl/safestack.h ../include/openssl/stack.h
mdc2test.o: ../include/openssl/symhacks.h mdc2test.c
nptest.o: nptest.c
p5_crpt2_test.o: ../e_os.h ../include/openssl/asn1.h ../include/openssl/bio.h
p5_crpt2_test.o: ../include/openssl/buffer.h ../include/openssl/conf.h
p5_crpt2_test.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h

test/nptest.c

0 → 100644
+66 −0
Original line number Diff line number Diff line
/* ====================================================================
 * Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    openssl-core@openssl.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */


#include <stdio.h>
#include <string.h>

int main()
{
    char *p = NULL;
    char bytes[sizeof(p)];

    memset(bytes, 0, sizeof bytes);
    return memcmp(&p, bytes, sizeof(bytes)) == 0 ? 0 : 1;
}