Commit 0d5383e5 authored by Vitezslav Kriz's avatar Vitezslav Kriz Committed by Daniel Salzman

afl: getenv call only once

parent 6f7d2cad
......@@ -131,6 +131,7 @@ src/dnssec/tests/kasp_dir_file.c
src/dnssec/tests/kasp_store.c
src/dnssec/tests/key.c
src/dnssec/tests/key_algorithm.c
src/dnssec/tests/key_ds.c
src/dnssec/tests/keyid.c
src/dnssec/tests/keystore_pkcs8.c
src/dnssec/tests/keystore_pkcs8_dir.c
......@@ -485,6 +486,9 @@ src/zscanner/tests/tests.h
src/zscanner/tests/zscanner-tool.c
tests-fuzz/Makefile.am
tests-fuzz/packet.c
tests-fuzz/wrap/server.c
tests-fuzz/wrap/tcp-handler.c
tests-fuzz/wrap/udp-handler.c
tests/Makefile.am
tests/acl.c
tests/base32hex.c
......
......@@ -19,8 +19,7 @@
#include <stdio.h>
#include <signal.h>
#include "libknot/errcode.h"
#include "libknot/packet/pkt.h"
#include "libknot/libknot.h"
int main(void)
{
......
......@@ -23,7 +23,7 @@
extern void udp_master_init_stdio(server_t *server);
int server_reconfigure(conf_t *conf, void* data)
int server_reconfigure(conf_t *conf, void *data)
{
log_info("AFL, Wrap server_reconfigure()");
int ret = _orig_server_reconfigure(conf, data);
......
......@@ -14,12 +14,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Udp handler listen on stdin and send to stdout.
* To use this handler initialize it with udp_master_init_stdin.
*/
#include <stdbool.h>
#include "knot/server/udp-handler.c"
#include "knot/common/debug.h"
......@@ -27,11 +28,12 @@ struct udp_stdin {
struct iovec iov[NBUFS];
uint8_t buf[NBUFS][KNOT_WIRE_MAX_PKTSIZE];
struct sockaddr_storage addr;
bool afl_persistent;
};
static void next(void)
static inline void next(struct udp_stdin *rq)
{
if (getenv("AFL_PERSISTENT")) {
if (rq->afl_persistent) {
raise(SIGSTOP);
} else {
exit(0);
......@@ -47,10 +49,12 @@ static void *udp_stdin_init(void)
rq->iov[i].iov_len = KNOT_WIRE_MAX_PKTSIZE;
}
struct sockaddr_in * a = (struct sockaddr_in *) &rq->addr;
a->sin_family=AF_INET;
struct sockaddr_in *a = (struct sockaddr_in *)&rq->addr;
a->sin_family = AF_INET;
a->sin_addr.s_addr = IN_LOOPBACKNET;
a->sin_port = 42;
rq->afl_persistent = getenv("AFL_PERSISTENT") != NULL;
return rq;
}
......@@ -62,12 +66,12 @@ static int udp_stdin_deinit(void *d)
static int udp_stdin_recv(int fd, void *d)
{
struct udp_stdin *rq = (struct udp_stdin *) d;
struct udp_stdin *rq = (struct udp_stdin *)d;
rq->iov[RX].iov_len = fread(rq->iov[RX].iov_base,
1, KNOT_WIRE_MAX_PKTSIZE, stdin);
if (rq->iov[RX].iov_len == 0) {
next();
next(rq);
}
return rq->iov[RX].iov_len;
......@@ -75,15 +79,15 @@ static int udp_stdin_recv(int fd, void *d)
static int udp_stdin_handle(udp_context_t *ctx, void *d)
{
struct udp_stdin *rq = (struct udp_stdin *) d;
struct udp_stdin *rq = (struct udp_stdin *)d;
udp_handle(ctx, STDIN_FILENO, &rq->addr, &rq->iov[RX], &rq->iov[TX]);
return 0;
}
static int udp_stdin_send(void *d)
{
struct udp_stdin *rq = (struct udp_stdin *) d;
next();
struct udp_stdin *rq = (struct udp_stdin *)d;
next(rq);
return 0;
}
......@@ -95,7 +99,7 @@ void udp_master_init_stdio(server_t *server) {
log_info("AFL, UDP handler listen on stdin");
// register our dummy interface to server
iface_t * ifc = malloc(sizeof(iface_t));
iface_t *ifc = malloc(sizeof(iface_t));
ifc->fd[RX] = STDIN_FILENO;
ifc->fd[TX] = STDOUT_FILENO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment