fix: parsing leaks fixed
This commit is contained in:
parent
331d1077b9
commit
d0b1fa6329
@ -25,3 +25,4 @@ struct option_lst *parse_options(int ac, char *const *av);
|
||||
char *get_option_arg(const struct option_lst *options, e_flag flag);
|
||||
int parse_ports(const char *arg, uint16_t *start, uint16_t *end);
|
||||
e_scantype parse_type(const char *arg);
|
||||
void free_options(struct option_lst *options);
|
||||
|
24
src/main.c
24
src/main.c
@ -7,7 +7,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "dns.h"
|
||||
#include "interface.h"
|
||||
#include "parsing.h"
|
||||
#include "print.h"
|
||||
#include "scan.h"
|
||||
@ -23,12 +22,12 @@ static int scan_host(char *host, const struct option_lst *options)
|
||||
"ft_nmap: failed to retrieve ip address from "
|
||||
"'%s'\n",
|
||||
host);
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct response responses[1024] = {0};
|
||||
if (create_threads(options, ip_addr, responses) < 0)
|
||||
return -1;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -46,28 +45,35 @@ int main(int ac, char **av)
|
||||
return 1;
|
||||
|
||||
char *host = get_option_arg(options, FL_IP);
|
||||
if (host)
|
||||
return scan_host(host, options);
|
||||
if (host) {
|
||||
int rv = scan_host(host, options);
|
||||
free_options(options);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char *hosts_path = get_option_arg(options, FL_FILE);
|
||||
if (!hosts_path) {
|
||||
dprintf(2, "ft_nmap: address/hostname required\n");
|
||||
return 1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
FILE *hosts_file = fopen(hosts_path, "r");
|
||||
if (hosts_file == NULL) {
|
||||
dprintf(2, "ft_nmap: unable to open file '%s'\n", hosts_path);
|
||||
return 1;
|
||||
goto error;
|
||||
}
|
||||
char line[256];
|
||||
while (fgets(line, sizeof(line), hosts_file)) {
|
||||
if (scan_host(line, options) < 0) {
|
||||
fclose(hosts_file);
|
||||
return 1;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
fclose(hosts_file);
|
||||
|
||||
return 0;
|
||||
free_options(options);
|
||||
return EXIT_SUCCESS;
|
||||
error:
|
||||
free_options(options);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@ -8,6 +8,16 @@
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
void free_options(struct option_lst *options)
|
||||
{
|
||||
struct option_lst *it = options;
|
||||
while (it->next) {
|
||||
struct option_lst *tmp = it;
|
||||
it = it->next;
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
char *get_option_arg(const struct option_lst *options, e_flag flag)
|
||||
{
|
||||
if (!options)
|
||||
|
Loading…
Reference in New Issue
Block a user