shithub: fuzz

Download patch

ref: 6426bdf8e02d9028cf1b8df715f93c7126686cb4
parent: 7c68bebb0cb78ad5a83607b3fbdfa5f254b16abe
author: seh <seh@localhost>
date: Sat Nov 10 09:50:27 EST 2018

make working build ;; add lget ;; convert mkinput to fuzz

--- a/fuzz.h
+++ b/fuzz.h
@@ -108,6 +108,6 @@
 /* == Function prototypes == */
 
 // input.c
-void* mkinput(caller*);
+void	fuzz(caller*);
 
 #endif
--- a/input.c
+++ b/input.c
@@ -1,8 +1,10 @@
 #include "fuzz.h"
 
+void hjsync(void);
+
 // Procedurally generate input to syscall
-void*
-mkinput(caller *sc)
+void
+fuzz(caller *sc)
 {
 	// TODO
 	switch(sc->c) {
@@ -20,12 +22,10 @@
 			// with this call, pass the address of the input so that
 			// it's value is directly modified by the input generator
 
-			(sc->List)->
-
-			// open file and write to sync disk
-			File* hjfs = fopen("/srv/hjfs.cmd", "w");
-			fprintf(hjfs, "sync");
+			//(sc->List)->
 			
+			hjsync();
+			
 			// execute the call
 			break;
 		case sc_create :		//	create(char* : int : ulong);
@@ -88,7 +88,6 @@
 		default :
 			exits("Unknown system call!");
 	}
-	return nil;
 }
 
 // Init callnames here, is extern in fuzz.h
@@ -160,3 +159,14 @@
 "sysname",
 "werrstr"
 };
+
+
+// Syncs the disk in hjfs
+void
+hjsync()
+{
+	// open file and write to sync disk
+	int hjfs = open("/srv/hjfs.cmd", OWRITE);
+	fprint(hjfs, "sync");
+	close(hjfs);
+}
--- a/list.c
+++ b/list.c
@@ -85,3 +85,21 @@
 	}
 	return dat;
 }
+
+// Gets a list element by "index" -- ArrayList style
+void*
+lget(List *l, int index)
+{
+	// Out of bounds check
+	if(index < 0 || index >= l->size)
+		return nil;
+
+	int i;
+	Node* n = l->root;
+	for(i = 0; i < l->size; i++, n = n->next)
+		if(i == index)
+			return n->dat;
+
+	// Should never happen
+	return nil;
+}
--- a/list.h
+++ b/list.h
@@ -17,7 +17,7 @@
 
 struct List {
 	Node*	root;
-	int	size;
+	int		size;
 };
 
 // Create a new list
@@ -28,5 +28,8 @@
 
 // Search → delete from a list
 void* ldel(List*, void*, int(*comp)(void *, void *));
+
+// Access elements of a list by 'index'
+void* lget(List*, int);
 
 #endif
--- a/main.c
+++ b/main.c
@@ -46,7 +46,11 @@
 	
 	// Operate for the desired number of rounds, -1 is infinite
 	for(i = 0; i < nrounds || nrounds < 0; i++){
-		
+		int j;
+		for(j = 0; j < tofuzz.size; j++){
+			// <Log here>
+			fuzz((caller*)lget(&tofuzz, j)); // Fuzz (this syncs the disk)
+		}
 	}
 
 	exits(nil);
--- a/mutate.h
+++ b/mutate.h
@@ -5,7 +5,7 @@
 
 void mut_uint(uint* in_val);
 
-void mut_char(char* in_val)
+void mut_char(char* in_val);
 
 void mut_char_star();
 
@@ -23,11 +23,11 @@
 
 void mut_void_star();
 
-void mut_IOchunk(IOchunk* in_val)
+void mut_IOchunk(IOchunk* in_val);
 
 void mut_IOchunk_star();
 
-void mut_dir(dir* in_val)
+void mut_dir(Dir* in_val);
 
 void mut_dir_star();