Add fuzzing stuff
This commit is contained in:
		
							parent
							
								
									03ffca3544
								
							
						
					
					
						commit
						8d9ab31b79
					
				
					 3 changed files with 38 additions and 0 deletions
				
			
		
							
								
								
									
										4
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -22,6 +22,10 @@ ethsock.o: ethsock.c nmrpd.h | |||
| main.o: main.c nmrpd.h | ||||
| 	$(CC) $(CFLAGS) -c -o main.o main.c | ||||
| 
 | ||||
| fuzz: clean | ||||
| 	CC=afl-gcc CFLAGS=-DNMRPFLASH_FUZZ make nmrpflash | ||||
| 	mv nmrpflash fuzz | ||||
| 
 | ||||
| clean: | ||||
| 	rm -f nmrp.o tftp.o main.o ethsock.o nmrpflash | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										2
									
								
								main.c
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								main.c
									
										
									
									
									
								
							|  | @ -254,12 +254,14 @@ int main(int argc, char **argv) | |||
| 		return 1; | ||||
| 	} | ||||
| 
 | ||||
| #ifndef NMRPFLASH_FUZZ | ||||
| 	if (!list && ((!args.file_local && !args.tftpcmd) || !args.intf /*|| !args.ipaddr*/)) { | ||||
| 		usage(stderr); | ||||
| 		return 1; | ||||
| 	} | ||||
| 
 | ||||
| 	require_admin(); | ||||
| #endif | ||||
| 	val = !list ? nmrp_do(&args) : ethsock_list_all(); | ||||
| 
 | ||||
| out: | ||||
|  |  | |||
							
								
								
									
										32
									
								
								nmrp.c
									
										
									
									
									
								
							
							
						
						
									
										32
									
								
								nmrp.c
									
										
									
									
									
								
							|  | @ -266,6 +266,35 @@ static inline void msg_init(struct nmrp_msg *msg, uint16_t code) | |||
| 	msg->code = code; | ||||
| } | ||||
| 
 | ||||
| #ifdef NMRPFLASH_FUZZ | ||||
| #define ethsock_create(a, b) ethsock_create_fake(a, b) | ||||
| #define ethsock_get_hwaddr(a) ethsock_get_hwaddr_fake(a) | ||||
| #define ethsock_recv(a, b, c) ethsock_recv_fake(a, b, c) | ||||
| #define ethsock_send(a, b, c) (0) | ||||
| #define ethsock_set_timeout(a, b) (0) | ||||
| #define ethsock_ip_add(a, b, c, d) (0) | ||||
| #define ethsock_ip_del(a, b) (0) | ||||
| #define ethsock_close(a) (0) | ||||
| #define tftp_put(a) (0) | ||||
| 
 | ||||
| static struct ethsock* ethsock_create_fake(const char *intf, uint16_t protocol) | ||||
| { | ||||
| 	return (struct ethsock*)1; | ||||
| } | ||||
| 
 | ||||
| static uint8_t *ethsock_get_hwaddr_fake(struct ethsock* sock) | ||||
| { | ||||
| 	static uint8_t hwaddr[6]; | ||||
| 	memset(hwaddr, 0xfa, 6); | ||||
| 	return hwaddr; | ||||
| } | ||||
| 
 | ||||
| static ssize_t ethsock_recv_fake(struct ethsock *sock, void *buf, size_t len) | ||||
| { | ||||
| 	return read(STDIN_FILENO, buf, len); | ||||
| } | ||||
| #endif | ||||
| 
 | ||||
| static int pkt_send(struct ethsock *sock, struct nmrp_pkt *pkt) | ||||
| { | ||||
| 	size_t len = ntohs(pkt->msg.len) + sizeof(pkt->eh); | ||||
|  | @ -532,6 +561,9 @@ int nmrp_do(struct nmrpd_args *args) | |||
| 				printf("\nNo response after 60 seconds. Bailing out.\n"); | ||||
| 				goto out; | ||||
| 			} | ||||
| #ifdef NMRPFLASH_FUZZ | ||||
| 			goto out; | ||||
| #endif | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue