1
0

added more code

This commit is contained in:
Andrew W
2022-08-28 16:12:16 -05:00
parent 5a2894ed1b
commit 7dabaef6f6
2345 changed files with 1343530 additions and 0 deletions

8
CPE455/lab07/Makefile Normal file
View File

@ -0,0 +1,8 @@
CC := afl-gcc
CFLAGS := -Wno-unused-result
all: crashy.c
$(CC) $(CFLAGS) -o crashy crashy.c
clean:
rm crashy

BIN
CPE455/lab07/crashy Executable file

Binary file not shown.

83
CPE455/lab07/crashy.c Normal file
View File

@ -0,0 +1,83 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *fp;
unsigned int sz, len, ptr;
char *buffer;
char type;
char tmp_char;
int tmp_int;
char *tmp_string;
if(argc != 2) {
fprintf(stderr, "Usage: %s <inputfile>\n", argv[0]);
return 1;
}
fp = fopen(argv[1], "r");
if(!fp) {
fprintf(stderr, "Failed to open '%s'\n", argv[1]);
return 1;
}
fseek(fp, 0, SEEK_END);
sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
buffer = malloc(sz);
if(!buffer) {
fprintf(stderr, "Failed to allocate %d bytes of memory\n", sz);
return 1;
}
fread(buffer, sizeof(char), sz, fp);
ptr = 0;
while(ptr < sz) {
type = buffer[ptr++];
switch(type) {
case '\x01': // integer
tmp_int = *(int *)(buffer + ptr);
ptr += sizeof(int);
printf("i: 0x%08x\n", tmp_int);
break;
case '\x02': // char
tmp_char = buffer[ptr++];
printf("c: 0x%02x\n", (unsigned char)tmp_char);
break;
case '\x03': // string
len = *(int *)(buffer + ptr);
ptr += sizeof(int);
tmp_string = malloc(len);
if(!tmp_string) {
fprintf(stderr, "Failed to allocate %d bytes of memory\n", len);
return 1;
}
strcpy(tmp_string, (buffer + ptr));
printf("s: %s\n", tmp_string);
ptr += len;
break;
case '\x04': // comment
printf("#: %s\n", (buffer + ptr));
while(*(buffer + ptr++) != '\x00');
break;
case '\xff': // END
return 0;
default:
fprintf(stderr, "Unknown data type '%c'\n", type);
}
}
}

View File

@ -0,0 +1,88 @@
-: 0:Source:crashy.c
-: 0:Graph:crashy.gcno
-: 0:Data:crashy.gcda
-: 0:Runs:9
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:#include <stdlib.h>
-: 3:#include <string.h>
-: 4:
9: 5:int main(int argc, char *argv[]) {
-: 6:
-: 7: FILE *fp;
-: 8: unsigned int sz, len, ptr;
-: 9: char *buffer;
-: 10: char type;
-: 11: char tmp_char;
-: 12: int tmp_int;
-: 13: char *tmp_string;
-: 14:
9: 15: if(argc != 2) {
1: 16: fprintf(stderr, "Usage: %s <inputfile>\n", argv[0]);
1: 17: return 1;
-: 18: }
-: 19:
8: 20: fp = fopen(argv[1], "r");
8: 21: if(!fp) {
1: 22: fprintf(stderr, "Failed to open '%s'\n", argv[1]);
1: 23: return 1;
-: 24: }
-: 25:
7: 26: fseek(fp, 0, SEEK_END);
7: 27: sz = ftell(fp);
7: 28: fseek(fp, 0, SEEK_SET);
-: 29:
7: 30: buffer = malloc(sz);
7: 31: if(!buffer) {
1: 32: fprintf(stderr, "Failed to allocate %d bytes of memory\n", sz);
1: 33: return 1;
-: 34: }
-: 35:
6: 36: fread(buffer, sizeof(char), sz, fp);
-: 37:
6: 38: ptr = 0;
31: 39: while(ptr < sz) {
-: 40:
25: 41: type = buffer[ptr++];
25: 42: switch(type) {
-: 43:
-: 44: case '\x01': // integer
8: 45: tmp_int = *(int *)(buffer + ptr);
8: 46: ptr += sizeof(int);
8: 47: printf("i: 0x%08x\n", tmp_int);
8: 48: break;
-: 49:
-: 50: case '\x02': // char
5: 51: tmp_char = buffer[ptr++];
5: 52: printf("c: 0x%02x\n", (unsigned char)tmp_char);
5: 53: break;
-: 54:
-: 55: case '\x03': // string
6: 56: len = *(int *)(buffer + ptr);
6: 57: ptr += sizeof(int);
6: 58: tmp_string = malloc(len);
6: 59: if(!tmp_string) {
1: 60: fprintf(stderr, "Failed to allocate %d bytes of memory\n", len);
1: 61: return 1;
-: 62: }
5: 63: strcpy(tmp_string, (buffer + ptr));
5: 64: printf("s: %s\n", tmp_string);
5: 65: ptr += len;
5: 66: break;
-: 67:
-: 68: case '\x04': // comment
1: 69: printf("#: %s\n", (buffer + ptr));
1: 70: while(*(buffer + ptr++) != '\x00');
1: 71: break;
-: 72:
-: 73: case '\xff': // END
5: 74: return 0;
-: 75:
-: 76: default:
#####: 77: fprintf(stderr, "Unknown data type '%c'\n", type);
-: 78:
-: 79: }
-: 80:
-: 81: }
-: 82:
#####: 83:}

BIN
CPE455/lab07/crashy.gcda Normal file

Binary file not shown.

BIN
CPE455/lab07/crashy.gcno Normal file

Binary file not shown.

BIN
CPE455/lab07/crashy.zip Normal file

Binary file not shown.

BIN
CPE455/lab07/example1 Normal file

Binary file not shown.

BIN
CPE455/lab07/example2 Normal file

Binary file not shown.

BIN
CPE455/lab07/example3 Normal file

Binary file not shown.

1
CPE455/lab07/example4 Normal file
View File

@ -0,0 +1 @@
ABC<>

BIN
CPE455/lab07/example5 Normal file

Binary file not shown.

409
CPE455/lab07/lab07.txt Normal file
View File

@ -0,0 +1,409 @@
Script started on Tue 29 Mar 2022 09:53:31 AM CDT
[?1034hbash-4.2$ gcc -g --coverage crashy.c -o crashy
bash-4.2$ ./vcrashy
Usage: ./crashy <inputfile>
bash-4.2$ gcov crashy.c
File 'crashy.c'
Lines executed:9.30% of 43
Creating 'crashy.c.gcov'
bash-4.2$ ./crashy example1
i: 0x78563412
c: 0xcc
s: hello
bash-4.2$ ./crashy example1
gcov crashy.c
File 'crashy.c'
Lines executed:74.42% of 43
Creating 'crashy.c.gcov'
bash-4.2$ gcov crashy.c
 ./crashy example12
i: 0x00000001
i: 0x00000002
i: 0x00000003
i: 0x00000004
i: 0x00000005
bash-4.2$ ./crashy example2
gcov crashy.c
File 'crashy.c'
Lines executed:74.42% of 43
Creating 'crashy.c.gcov'
bash-4.2$ gcov crashy.c
 ./crashy example23
s: this
s: is
s: an
s: example
bash-4.2$ ./crashy example3
gcov crashy.c
File 'crashy.c'
Lines executed:74.42% of 43
Creating 'crashy.c.gcov'
bash-4.2$ gcov crashy.c
 ./crashy example34
c: 0x41
c: 0x42
c: 0x43
bash-4.2$ ./crashy example4
gcov crashy.c
File 'crashy.c'
Lines executed:74.42% of 43
Creating 'crashy.c.gcov'
bash-4.2$ gcov crashy.c
 ./crashy example45
i: 0x00001337
#: ELITE
bash-4.2$ ./crashy example5
gcov crashy.c
File 'crashy.c'
Lines executed:81.40% of 43
Creating 'crashy.c.gcov'
bash-4.2$ more crashy
crashy crashy.c crashy.c.gcov crashy.gcda crashy.gcno crashy.zip
bash-4.2$ more crashy.c.gcov
-: 0:Source:crashy.c
-: 0:Graph:crashy.gcno
-: 0:Data:crashy.gcda
-: 0:Runs:6
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:#include <stdlib.h>
-: 3:#include <string.h>
-: 4:
6: 5:int main(int argc, char *argv[]) {
-: 6:
-: 7: FILE *fp;
-: 8: unsigned int sz, len, ptr;
-: 9: char *buffer;
-: 10: char type;
-: 11: char tmp_char;
-: 12: int tmp_int;
-: 13: char *tmp_string;
-: 14:
6: 15: if(argc != 2) {
1: 16: fprintf(stderr, "Usage: %s <inputfile>\n", argv[0]);
1: 17: return 1;
-: 18: }
-: 19:
5: 20: fp = fopen(argv[1], "r");
5: 21: if(!fp) {
#####: 22: fprintf(stderr, "Failed to open '%s'\n", argv[1]);
#####: 23: return 1;
-: 24: }
-: 25:
5: 26: fseek(fp, 0, SEEK_END);
5: 27: sz = ftell(fp);
5: 28: fseek(fp, 0, SEEK_SET);
-: 29:
5: 30: buffer = malloc(sz);
5: 31: if(!buffer) {
#####: 32: fprintf(stderr, "Failed to allocate %d bytes of memory\n", sz);
#####: 33: return 1;
-: 34: }
-: 35:
5: 36: fread(buffer, sizeof(char), sz, fp);
-: 37:
5: 38: ptr = 0;
27: 39: while(ptr < sz) {
-: 40:
22: 41: type = buffer[ptr++];
22: 42: switch(type) {
-: 43:
-: 44: case '\x01': // integer
7: 45: tmp_int = *(int *)(buffer + ptr);
7: 46: ptr += sizeof(int);
--More--(55%)
7: 47: printf("i: 0x%08x\n", tmp_int);
--More--(57%)
7: 48: break;
--More--(58%)
-: 49:
--More--(59%)
-: 50: case '\x02': // char
--More--(60%)
4: 51: tmp_char = buffer[ptr++];
--More--(61%)
4: 52: printf("c: 0x%02x\n", (unsigned char)tmp_char);
--More--(64%)
4: 53: break;
--More--(65%)
-: 54:
--More--(65%)
-: 55: case '\x03': // string
--More--(67%)
5: 56: len = *(int *)(buffer + ptr);
--More--(68%)
5: 57: ptr += sizeof(int);
--More--(70%)
5: 58: tmp_string = malloc(len);
--More--(71%)
5: 59: if(!tmp_string) {
--More--(72%)
#####: 60: fprintf(stderr, "Failed to allocate %d bytes of m
--More--(75%)
emory\n", len);
--More--(75%)
#####: 61: return 1;
--More--(76%)
-: 62: }
--More--(77%)
5: 63: strcpy(tmp_string, (buffer + ptr));
--More--(79%)
5: 64: printf("s: %s\n", tmp_string);
--More--(81%)
5: 65: ptr += len;
--More--(82%)
5: 66: break;
--More--(83%)
-: 67:
--More--(83%)
-: 68: case '\x04': // comment
--More--(85%)
1: 69: printf("#: %s\n", (buffer + ptr));
--More--(86%)
1: 70: while(*(buffer + ptr++) != '\x00');
--More--(88%)
1: 71: break;
--More--(89%)
-: 72:
--More--(90%)
-: 73: case '\xff': // END
--More--(91%)
5: 74: return 0;
--More--(92%)
-: 75:
--More--(93%)
-: 76: default:
--More--(94%)
#####: 77: fprintf(stderr, "Unknown data type '%c'\n", type);
--More--(96%)
bash-4.2$ more crashy.c.gcov
-: 0:Source:crashy.c
-: 0:Graph:crashy.gcno
-: 0:Data:crashy.gcda
-: 0:Runs:6
-: 0:Programs:1
-: 1:#include <stdio.h>
-: 2:#include <stdlib.h>
-: 3:#include <string.h>
-: 4:
6: 5:int main(int argc, char *argv[]) {
-: 6:
-: 7: FILE *fp;
-: 8: unsigned int sz, len, ptr;
-: 9: char *buffer;
-: 10: char type;
-: 11: char tmp_char;
-: 12: int tmp_int;
-: 13: char *tmp_string;
-: 14:
6: 15: if(argc != 2) {
1: 16: fprintf(stderr, "Usage: %s <inputfile>\n", argv[0]);
1: 17: return 1;
-: 18: }
-: 19:
5: 20: fp = fopen(argv[1], "r");
5: 21: if(!fp) {
#####: 22: fprintf(stderr, "Failed to open '%s'\n", argv[1]);
#####: 23: return 1;
-: 24: }
-: 25:
5: 26: fseek(fp, 0, SEEK_END);
5: 27: sz = ftell(fp);
5: 28: fseek(fp, 0, SEEK_SET);
-: 29:
5: 30: buffer = malloc(sz);
5: 31: if(!buffer) {
#####: 32: fprintf(stderr, "Failed to allocate %d bytes of memory\n", sz);
#####: 33: return 1;
-: 34: }
-: 35:
5: 36: fread(buffer, sizeof(char), sz, fp);
-: 37:
5: 38: ptr = 0;
27: 39: while(ptr < sz) {
-: 40:
22: 41: type = buffer[ptr++];
22: 42: switch(type) {
-: 43:
-: 44: case '\x01': // integer
7: 45: tmp_int = *(int *)(buffer + ptr);
7: 46: ptr += sizeof(int);
--More--(55%)
7: 47: printf("i: 0x%08x\n", tmp_int);
--More--(57%)
7: 48: break;
--More--(58%)
-: 49:
--More--(59%)
-: 50: case '\x02': // char
--More--(60%)
4: 51: tmp_char = buffer[ptr++];
--More--(61%)
4: 52: printf("c: 0x%02x\n", (unsigned char)tmp_char);
--More--(64%)
4: 53: break;
--More--(65%)
-: 54:
--More--(65%)
-: 55: case '\x03': // string
--More--(67%)
5: 56: len = *(int *)(buffer + ptr);
--More--(68%)
5: 57: ptr += sizeof(int);
--More--(70%)
5: 58: tmp_string = malloc(len);
--More--(71%)
5: 59: if(!tmp_string) {
--More--(72%)
#####: 60: fprintf(stderr, "Failed to allocate %d bytes of memory\n", len);
--More--(75%)
#####: 61: return 1;
--More--(76%)
-: 62: }
--More--(77%)
5: 63: strcpy(tmp_string, (buffer + ptr));
--More--(79%)
5: 64: printf("s: %s\n", tmp_string);
--More--(81%)
5: 65: ptr += len;
--More--(82%)
5: 66: break;
--More--(83%)
-: 67:
--More--(83%)
-: 68: case '\x04': // comment
--More--(85%)
1: 69: printf("#: %s\n", (buffer + ptr));
--More--(86%)
1: 70: while(*(buffer + ptr++) != '\x00');
--More--(88%)
1: 71: break;
--More--(89%)
-: 72:
--More--(90%)
-: 73: case '\xff': // END
--More--(91%)
5: 74: return 0;
--More--(92%)
-: 75:
--More--(93%)
-: 76: default:
--More--(94%)
#####: 77: fprintf(stderr, "Unknown data type '%c'\n", type);
--More--(96%)
-: 78:
--More--(96%)
-: 79: }
--More--(97%)
-: 80:
--More--(98%)
-: 81: }
--More--(98%)
-: 82:
--More--(99%)
#####: 83:}
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$
bash-4.2$ ./crashy example6
Failed to open 'example6'
bash-4.2$ ./crashy example6
more crashy.c.gcov
gcov crashy.c
File 'crashy.c'
Lines executed:86.05% of 43
Creating 'crashy.c.gcov'
bash-4.2$ gdb ./crashy
[?1034hGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/student/anw0044/CPE455/lab07/crashy...done.
(gdb)
(gdb) break main
Breakpoint 1 at 0x400e4c: file crashy.c, line 15.
(gdb) break 31
Breakpoint 2 at 0x400fa7: file crashy.c, line 31.
(gdb) break 3159
Breakpoint 3 at 0x401153: file crashy.c, line 59.
(gdb) break 5931main3159
run example1
Starting program: /home/student/anw0044/CPE455/lab07/./crashy example1
Breakpoint 1, main (argc=2, argv=0x7fffffffe438) at crashy.c:15
15 if(argc != 2) {
Missing separate debuginfos, use: debuginfo-install glibc-2.17-325.el7_9.x86_64
(gdb) continue
Continuing.
Breakpoint 2, main (argc=2, argv=0x7fffffffe438) at crashy.c:31
31 if(!buffer) {
(gdb) print buffer=0
$1 = 0x0
(gdb) conytinue
Continuing.
Failed to allocate 19 bytes of memory
[Inferior 1 (process 1861) exited with code 01]
(gdb) continue
print buffer=0
continue
run example1
Starting program: /home/student/anw0044/CPE455/lab07/./crashy example1
Breakpoint 1, main (argc=2, argv=0x7fffffffe438) at crashy.c:15
15 if(argc != 2) {
(gdb) print tmp_string=0
$2 = 0x0
(gdb) continue
Continuing.
Breakpoint 2, main (argc=2, argv=0x7fffffffe438) at crashy.c:31
31 if(!buffer) {
(gdb) continue
Continuing.
i: 0x78563412
c: 0xcc
Breakpoint 3, main (argc=2, argv=0x7fffffffe438) at crashy.c:59
59 if(!tmp_string) {
(gdb) continue
print tmp_string=0
$3 = 0x0
(gdb) continue
Continuing.
Failed to allocate 6 bytes of memory
[Inferior 1 (process 1910) exited with code 01]
(gdb) quit
bash-4.2$ gdb ./crashycov crashy.c
./crashy example6
gcov crashy.c
File 'crashy.c'
Lines executed:95.35% of 43
Creating 'crashy.c.gcov'
bash-4.2$ cat crashy.c.gcov
-: 0:Source:crashy.c
-: 0:Graph:crashy.gcno
-: 0:Data:crashy.gcda