Skip to content

Commit

Permalink
memory cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rke committed Jun 24, 2021
1 parent c6a0165 commit f86ddc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pcap.c
Expand Up @@ -204,6 +204,7 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) {
off_t bytes; /* read/written bytes counter */
off_t filesize; /* filesize of input file in bytes */
unsigned short hdr_integ; /* integrity counter of global header */
int res; /* return code */

/* init write buffer */
writebuffer = malloc(1024000);
Expand All @@ -218,12 +219,16 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) {
/* check space of pcap global header */
if (filesize < (off_t)sizeof(global_hdr)) {
printf("[-] File is too small to read pcap global header.\n");
free(writebuffer);
return(-2);
}

printf("[*] Analyzing Global Header...\n");
bytes = fread(&global_hdr, sizeof(global_hdr), 1, pcap); /* read first bytes of input file into struct */
if (bytes != 1) return -3;
if (bytes != 1) {
free(writebuffer);
return -3;
}

/* init integrity counter */
hdr_integ = 0;
Expand Down Expand Up @@ -345,7 +350,9 @@ int fix_pcap(FILE *pcap, FILE *pcap_fix) {
/* END OF GLOBAL HEADER CHECK */

/* start checking packets now */
return(fix_pcap_packets(pcap, pcap_fix, filesize, global_hdr, hdr_integ, writebuffer, writepos));
res = fix_pcap_packets(pcap, pcap_fix, filesize, global_hdr, hdr_integ, writebuffer, writepos);
free(writebuffer);
return(res);
}

/*
Expand Down
1 change: 1 addition & 0 deletions pcapfix.c
Expand Up @@ -432,6 +432,7 @@ int main(int argc, char *argv[]) {

/* delete output file due to failure */
if (strcmp(filename, filename_fix) != 0) remove(filename_fix);
free(filename_fix);

/* deep scan / soft mode dependent output */
if (deep_scan == 0 || soft_mode == 0) printf("If you are SURE that there are pcap packets inside, try with deep scan (-d) (pcap only!) and/or soft mode (-s) to find them!\n\n");
Expand Down

0 comments on commit f86ddc7

Please sign in to comment.