From d6286f09c92b303c9b23a463fa40ae3684b9bbd2 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 19 Nov 2016 18:19:10 +0000 Subject: [PATCH] regress: Introduce hnonfuzz.c and Ttestinputfd We are going to want to build a fuzzer target binary which will be very like a playback binary, but provides a bit more wrapping. For now we introduce hnonfuzz.o and link it into all the currently-generated executables. To make it not be an empty translation unit, combine this with: Break out Ttestinputfd from hplayback.c.m4. Neither of these changes produce any functional change. (Ttestinputfd ends up linked into *_record as well as *_playback but this is of no consequence.) Signed-off-by: Ian Jackson --- regress/Makefile.in | 8 ++++---- regress/harness.h.m4 | 1 + regress/hnonfuzz.c | 34 ++++++++++++++++++++++++++++++++++ regress/hplayback.c.m4 | 6 ++---- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 regress/hnonfuzz.c diff --git a/regress/Makefile.in b/regress/Makefile.in index a6df8bb..67f867c 100644 --- a/regress/Makefile.in +++ b/regress/Makefile.in @@ -40,7 +40,7 @@ HARNLOBJS= hcommon.o $(REDIRLIBOBJS) TARGETS= $(addsuffix _record, $(CLIENTS)) \ $(addsuffix _playback, $(CLIENTS)) ADH_OBJS= adh-main_c.o adh-opts_c.o adh-query_c.o -ALL_OBJS= $(HARNLOBJS) dtest.o hrecord.o hplayback.o +ALL_OBJS= $(HARNLOBJS) dtest.o hrecord.o hplayback.o hnonfuzz.o .PRECIOUS: $(AUTOCSRCS) $(AUTOCHDRS) @@ -57,10 +57,10 @@ check-%: case-%.sys LINK_CMD= $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ -%_record: %_c.o hrecord.o $(HARNLOBJS) +%_record: %_c.o hrecord.o hnonfuzz.o $(HARNLOBJS) $(LINK_CMD) -%_playback: %_c.o hplayback.o $(HARNLOBJS) +%_playback: %_c.o hplayback.o hnonfuzz.o $(HARNLOBJS) $(LINK_CMD) .SECONDARY: $(addsuffix _c.o, $(filter-out adnshost, $(CLIENTS))) @@ -73,7 +73,7 @@ LINK_CMD= $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ # # See also Savannah #29620, http://savannah.gnu.org/bugs/index.php?29620 -adnshost_%: $(ADH_OBJS) h%.o $(HARNLOBJS) +adnshost_%: $(ADH_OBJS) h%.o hnonfuzz.o $(HARNLOBJS) $(LINK_CMD) %_d.o: $(srcdir)/../src/%.c hredirect.h diff --git a/regress/harness.h.m4 b/regress/harness.h.m4 index cc589a5..1c602d9 100644 --- a/regress/harness.h.m4 +++ b/regress/harness.h.m4 @@ -73,5 +73,6 @@ extern const struct Terrno { const char *n; int v; } Terrnos[]; void Texit(int rv) NONRETURNING; void Tallocshutdown(void); +int Ttestinputfd(void); #endif diff --git a/regress/hnonfuzz.c b/regress/hnonfuzz.c new file mode 100644 index 0000000..89876a9 --- /dev/null +++ b/regress/hnonfuzz.c @@ -0,0 +1,34 @@ +/* nhonfuzz.c + * (part of complex test harness, not of the library) + * - routines used for record and playback but not for fuzzing + * + * This file is part of adns, which is + * Copyright (C) 1997-2000,2003,2006,2014-2016 Ian Jackson + * Copyright (C) 2014 Mark Wooding + * Copyright (C) 1999-2000,2003,2006 Tony Finch + * Copyright (C) 1991 Massachusetts Institute of Technology + * (See the file INSTALL for full details.) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation. + */ + +#include + +#include "harness.h" + +int Ttestinputfd(void) { + const char *fdstr= getenv("ADNS_TEST_IN_FD"); + if (!fdstr) return -1; + return atoi(fdstr); +} diff --git a/regress/hplayback.c.m4 b/regress/hplayback.c.m4 index b3c45c6..fb4295c 100644 --- a/regress/hplayback.c.m4 +++ b/regress/hplayback.c.m4 @@ -69,16 +69,14 @@ static void Pcheckinput(void) { } void Tensurerecordfile(void) { - const char *fdstr; int fd; int chars; unsigned long sec, usec; if (Tinputfile) return; Tinputfile= stdin; - fdstr= getenv("ADNS_TEST_IN_FD"); - if (fdstr) { - fd= atoi(fdstr); + fd = Ttestinputfd(); + if (fd >= 0) { Tinputfile= fdopen(fd,"r"); if (!Tinputfile) Tfailed("fdopen ADNS_TEST_IN_FD"); } setvbuf(Tinputfile,0,_IONBF,0); -- 2.30.2