-
Notifications
You must be signed in to change notification settings - Fork 298
Open
Labels
Description
OS: arch linux (tested also on ubuntu 18 container, and VM of mint 17 )
Step to reproduce:
- Install AFL:
wget http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz
tar xzf afl-latest.tgz
cd afl*
make && sudo make install
- Download OpENer
- Configure OpENer by running
./setup_posix_fuzz_afl.shin OpENer/bin/posix/ - Run
make
Results in following errors:
/home/username/Code/enip_tools/OpENer/source/src/ports/POSIX/main.c:283:9: error: implicit declaration of func tion ‘__AFL_LOOP’ [-Wimplicit-function-declaration]
1 283 | while(__AFL_LOOP(100000) ) { 2 | ^~~~~~~~~~
3 /home/username/Code/enip_tools/OpENer/source/src/ports/POSIX/main.c:297:59: warning: conversion to ‘size_t’ {a ka ‘long unsigned int’} from ‘ssize_t’ {aka ‘long int’} may change the sign of the result [-Wsign-conversion]
4 297 | received_size, 5 | ^~~~~~~~~~~~~
6 /home/username/Code/enip_tools/OpENer/source/src/ports/POSIX/main.c:299:59: error: passing argument 5 of ‘Hand leReceivedExplictTcpData’ from incompatible pointer type [-Wincompatible-pointer-types]
7 299 | &from_address,
8 | ^~~~~~~~~~~~~
9 | |
10 | struct sockaddr_in *
11
- Fixing it with following:
index 38a3bec51..4cbc5f297 100644
--- a/source/src/ports/POSIX/main.c
+++ b/source/src/ports/POSIX/main.c
@@ -16,6 +16,13 @@
#include <limits.h>
#endif
+#ifndef __AFL_LOOP
+#define __AFL_LOOP(x) (x)
+#endif
+
+
+
+
#include "generic_networkhandler.h"
#include "opener_api.h"
#include "cipethernetlink.h"
@@ -292,7 +299,7 @@ static void fuzzHandlePacketFlow(void) {
receive_buffer,
received_size,
&remaining_bytes,
- &from_address,
+ (struct sockaddr *)&from_address,
&outgoing_message);
}
}
- After this fix there seems to be linker issues:
❯ make [17:28:14]
[ 11% ] Built target Utils
[ 20% ] Built target ENET_ENCAP
[ 63% ] Built target CIP
[ 70% ] Built target PLATFORM_GENERIC
[ 79% ] Built target POSIXPLATFORM
[ 90% ] Built target NVDATA
[ 95% ] Built target SAMPLE_APP
[ 97% ] Linking C executable OpENer
afl-cc 2.57b by <lcamtuf@google.com>
/usr/bin/ld: ../../cip/libCIP.a(cipioconnection.c.o): warning: relocation against `g_network_status' in read-only section `.text'
/usr/bin/ld: ../../cip/libCIP.a(cipconnectionmanager.c.o): in function `ForwardOpenRoutine':
/home/username/Code/enip_tools/OpENer/source/src/cip/cipconnectionmanager.c:631:(.text+0x2ab6): undefined reference to `g_network_status'
/usr/bin/ld: /home/username/Code/enip_tools/OpENer/source/src/cip/cipconnectionmanager.c:631:(.text+0x2ac6): undefined reference to `g_network_status'
/usr/bin/ld: ../../cip/libCIP.a(cipconnectionmanager.c.o): in function `CloseConnection':
/home/username/Code/enip_tools/OpENer/source/src/cip/cipconnectionmanager.c:1693:(.text+0x544b): undefined reference to `CloseUdpSocket'
/usr/bin/ld: /home/username/Code/enip_tools/OpENer/source/src/cip/cipconnectionmanager.c:1696:(.text+0x5460): undefined reference to `CloseUdpSocket'
/usr/bin/ld: ../../cip/libCIP.a(cipioconnection.c.o): in function `SendConnectedData':
/home/username/Code/enip_tools/OpENer/source/src/cip/cipioconnection.c:908:(.text+0x76f): undefined reference to `SendUdpData'
/usr/bin/ld: ../../cip/libCIP.a(cipioconnection.c.o): in function `CloseCommunicationChannelsAndRemoveFromActiveConnectionsList':
/home/username/Code/enip_tools/OpENer/source/src/cip/cipioconnection.c:1035:(.text+0xf69): undefined reference to `CloseUdpSocket'
/usr/bin/ld: /home/username/Code/enip_tools/OpENer/source/src/cip/cipioconnection.c:1030:(.text+0x1011): undefined reference to `CloseUdpSocket'
/usr/bin/ld: ../../cip/libCIP.a(cipioconnection.c.o): in function `OpenConsumingPointToPointConnection':
/home/username/Code/enip_tools/OpENer/source/src/cip/cipioconnection.c:419:(.text+0x21b0): undefined reference to `SetQos'
`