fix: leaks and conditional jumps in the parsing
This commit is contained in:
9
.clang-format
Normal file
9
.clang-format
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 8
|
||||||
|
UseTab: AlignWithSpaces
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
IndentCaseLabels: false
|
||||||
|
ColumnLimit: 80
|
||||||
|
AlignConsecutiveMacros: true
|
@ -46,8 +46,7 @@ uint8_t parse_type(char *arg)
|
|||||||
return SCAN_ALL;
|
return SCAN_ALL;
|
||||||
uint8_t type = 0;
|
uint8_t type = 0;
|
||||||
char *current_arg = strtok(arg, ",");
|
char *current_arg = strtok(arg, ",");
|
||||||
while (current_arg)
|
while (current_arg) {
|
||||||
{
|
|
||||||
if (strcmp(current_arg, "NULL") == 0)
|
if (strcmp(current_arg, "NULL") == 0)
|
||||||
type |= SCAN_NULL;
|
type |= SCAN_NULL;
|
||||||
else if (strcmp(current_arg, "SYN") == 0)
|
else if (strcmp(current_arg, "SYN") == 0)
|
||||||
@ -60,9 +59,10 @@ uint8_t parse_type(char *arg)
|
|||||||
type |= SCAN_XMAS;
|
type |= SCAN_XMAS;
|
||||||
else if (strcmp(current_arg, "UDP") == 0)
|
else if (strcmp(current_arg, "UDP") == 0)
|
||||||
type |= SCAN_UDP;
|
type |= SCAN_UDP;
|
||||||
else
|
else {
|
||||||
{
|
dprintf(2,
|
||||||
dprintf(2, "ft_nmap: invalid argument to --scan: '%s'\n", arg);
|
"ft_nmap: invalid argument to --scan: '%s'\n",
|
||||||
|
arg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
current_arg = strtok(NULL, ",");
|
current_arg = strtok(NULL, ",");
|
||||||
@ -212,6 +212,7 @@ struct option_lst *parse_options(int ac, char *const *av)
|
|||||||
{"scan", required_argument, 0, 0},
|
{"scan", required_argument, 0, 0},
|
||||||
{"max_retries", required_argument, 0, 0},
|
{"max_retries", required_argument, 0, 0},
|
||||||
{"ttl", required_argument, 0, 0},
|
{"ttl", required_argument, 0, 0},
|
||||||
|
{NULL, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
@ -225,12 +226,13 @@ struct option_lst *parse_options(int ac, char *const *av)
|
|||||||
add_option(&head, FL_FAST, optarg);
|
add_option(&head, FL_FAST, optarg);
|
||||||
continue;
|
continue;
|
||||||
case '?':
|
case '?':
|
||||||
|
free_options(head);
|
||||||
return NULL;
|
return NULL;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (check_arg(option_index, optarg) < 0 || add_option(&head, option_index, optarg) < 0)
|
if (check_arg(option_index, optarg) < 0 ||
|
||||||
{
|
add_option(&head, option_index, optarg) < 0) {
|
||||||
free_options(head);
|
free_options(head);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -254,7 +256,7 @@ int parsing(struct scan *general, const struct option_lst *options)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
general->type = parse_type(get_option_arg(options, FL_TYPE));
|
general->type = parse_type(get_option_arg(options, FL_TYPE));
|
||||||
if (general->type == (uint8_t) -1)
|
if (general->type == (uint8_t)-1)
|
||||||
return -1;
|
return -1;
|
||||||
const char *max_retries = get_option_arg(options, FL_MAXRETRIES);
|
const char *max_retries = get_option_arg(options, FL_MAXRETRIES);
|
||||||
general->max_retries = max_retries ? atoi(max_retries) : 1;
|
general->max_retries = max_retries ? atoi(max_retries) : 1;
|
||||||
|
Reference in New Issue
Block a user