fix: leaks and conditional jumps in the parsing

This commit is contained in:
nmap
2025-07-02 16:41:02 +02:00
parent 4c0230cd39
commit 05dd5478c3
2 changed files with 19 additions and 8 deletions

9
.clang-format Normal file
View File

@ -0,0 +1,9 @@
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: AlignWithSpaces
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: Never
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: false
ColumnLimit: 80
AlignConsecutiveMacros: true

View File

@ -46,8 +46,7 @@ uint8_t parse_type(char *arg)
return SCAN_ALL;
uint8_t type = 0;
char *current_arg = strtok(arg, ",");
while (current_arg)
{
while (current_arg) {
if (strcmp(current_arg, "NULL") == 0)
type |= SCAN_NULL;
else if (strcmp(current_arg, "SYN") == 0)
@ -60,9 +59,10 @@ uint8_t parse_type(char *arg)
type |= SCAN_XMAS;
else if (strcmp(current_arg, "UDP") == 0)
type |= SCAN_UDP;
else
{
dprintf(2, "ft_nmap: invalid argument to --scan: '%s'\n", arg);
else {
dprintf(2,
"ft_nmap: invalid argument to --scan: '%s'\n",
arg);
return -1;
}
current_arg = strtok(NULL, ",");
@ -212,6 +212,7 @@ struct option_lst *parse_options(int ac, char *const *av)
{"scan", required_argument, 0, 0},
{"max_retries", required_argument, 0, 0},
{"ttl", required_argument, 0, 0},
{NULL, 0, 0, 0},
};
int c;
@ -225,12 +226,13 @@ struct option_lst *parse_options(int ac, char *const *av)
add_option(&head, FL_FAST, optarg);
continue;
case '?':
free_options(head);
return NULL;
default:
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);
return NULL;
}