2 * (part of complex test harness, not of the library)
3 * - routines used for fuzzing (a kind of playback)
5 * This file is part of adns, which is
6 * Copyright (C) 1997-2000,2003,2006,2014-2016 Ian Jackson
7 * Copyright (C) 2014 Mark Wooding
8 * Copyright (C) 1999-2000,2003,2006 Tony Finch
9 * Copyright (C) 1991 Massachusetts Institute of Technology
10 * (See the file INSTALL for full details.)
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software Foundation.
28 * - command line arguments
37 extern int Hmain(int argc, char **argv);
39 FILE *Hfopen(const char *path, const char *mode) {
40 /* we do not allow adns to open any files */
48 static FILE *t_stdin, *stdoutcopy;
51 static int bail(const char *msg) {
52 fprintf(stderr,"adns fuzz client: %s\n", msg);
55 static int baile(const char *msg) {
56 fprintf(stderr,"adns fuzz client: %s: %s\n", msg, strerror(errno));
60 static void chkin(void) {
61 if (ferror(stdin)) baile("read stdin");
62 if (feof(stdin)) bail("eof on stdin");
65 static int getint(int max) {
69 int r = scanf("%d%c", &val, &c);
71 if (r != 2 || c != '\n') bail("bad input format: not integer");
72 if (val < 0 || val > max) bail("bad input format: wrong value");
76 static void getnl(void) {
80 if (c != '\n') bail("bad input format: expected newline");
83 int Ttestinputfd(void) {
88 fprintf(stdoutcopy,"rc=%d\n",rv);
89 if (ferror(stdoutcopy) || fclose(stdoutcopy)) baile("flush rc msg");
94 int main(int argc, char **argv) {
98 bail("usage: *_fuzz (no arguments)");
100 int stdoutcopyfd= dup(1);
101 if (stdoutcopyfd<0) baile("dup 1 again");
102 stdoutcopy= fdopen(stdoutcopyfd,"w");
103 if (!stdoutcopy) baile("fdopen 1 again");
106 if (!t_argc) bail("too few arguments");
107 t_argv = calloc(t_argc+1, sizeof(*t_argv));
108 for (i=0; i<t_argc; i++) {
110 t_argv[i] = calloc(1, l+1);
111 fread(t_argv[i], 1,l, stdin);
125 if (ferror(t_stdin) || fflush(t_stdin)) baile("write/flush t_stdin");
126 if (fseek(stdin, 0, SEEK_CUR)) baile("seek-flush stdin");
127 t_sys_fd = dup(0); if (t_sys_fd < 0) baile("dup stdin");
128 if (dup2(fileno(t_stdin), 0)) baile("dup2 t_stdin");
129 if (fseek(stdin, 0, SEEK_SET)) baile("rewind t_stdin");
131 int estatus = Hmain(t_argc, t_argv);
135 void Tmallocshutdown(void) { }
136 void *Hmalloc(size_t s) { assert(s); return malloc(s); }
137 void *Hrealloc(void *p, size_t s) { assert(s); return realloc(p,s); }
138 void Hfree(void *p) { free(p); }