1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-04 06:36:46 +02:00

Fix a few issues

- realloc needs to be error checked
- use correct format specifiers
- make sure optarg and DATA_FILE aren't null before using them
This commit is contained in:
jfreegman
2020-11-02 18:08:54 -05:00
parent e7a0c32a68
commit 1bbd50aac7
8 changed files with 29 additions and 11 deletions

View File

@ -1106,23 +1106,31 @@ static void parse_args(int argc, char *argv[])
break;
case 'f':
if (optarg == NULL) {
queue_init_message("Invalid argument for option: %d", opt);
break;
}
arg_opts.use_custom_data = 1;
if (DATA_FILE) {
free(DATA_FILE);
DATA_FILE = NULL;
}
if (BLOCK_FILE) {
free(BLOCK_FILE);
BLOCK_FILE = NULL;
}
DATA_FILE = malloc(strlen(optarg) + 1);
strcpy(DATA_FILE, optarg);
if (DATA_FILE == NULL) {
exit_toxic_err("failed in parse_args", FATALERR_MEMORY);
}
strcpy(DATA_FILE, optarg);
BLOCK_FILE = malloc(strlen(optarg) + strlen("-blocklist") + 1);
if (BLOCK_FILE == NULL) {