Browse code

core: main - several optarg safety checks

(cherry picked from commit 4f7b5537688293d196669dd5a7d0124f7656cf2d)
(cherry picked from commit 6e38b6e81e8cdb656b28e221a59aaf7a38b76ef3)

Daniel-Constantin Mierla authored on 06/04/2021 12:48:34 • Henning Westerholt committed on 22/10/2021 11:41:29
Showing 1 changed files
... ...
@@ -2033,6 +2033,10 @@ int main(int argc, char** argv)
2033 2033
 					/* ignore, they were parsed immediately after startup */
2034 2034
 					break;
2035 2035
 			case 'f':
2036
+					if (optarg == NULL) {
2037
+						fprintf(stderr, "bad -f parameter\n");
2038
+						goto error;
2039
+					}
2036 2040
 					cfg_file=optarg;
2037 2041
 					break;
2038 2042
 			case 'c':
... ...
@@ -2040,10 +2044,18 @@ int main(int argc, char** argv)
2040 2044
 					log_stderr=1; /* force stderr logging */
2041 2045
 					break;
2042 2046
 			case 'L':
2047
+					if (optarg == NULL) {
2048
+						fprintf(stderr, "bad -L parameter\n");
2049
+						goto error;
2050
+					}
2043 2051
 					mods_dir = optarg;
2044 2052
 					mods_dir_cmd = 1;
2045 2053
 					break;
2046 2054
 			case 'm':
2055
+					if (optarg == NULL) {
2056
+						fprintf(stderr, "bad shared mem size\n");
2057
+						goto error;
2058
+					}
2047 2059
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
2048 2060
 					if (tmp &&(*tmp)){
2049 2061
 						fprintf(stderr, "bad shmem size number: -m %s\n",
... ...
@@ -2081,6 +2093,10 @@ int main(int argc, char** argv)
2081 2093
 					/* ignore it, was parsed immediately after startup */
2082 2094
 					break;
2083 2095
 			case 'O':
2096
+					if (optarg == NULL) {
2097
+						fprintf(stderr, "bad -O parameter\n");
2098
+						goto error;
2099
+					}
2084 2100
 					scr_opt_lev=strtol(optarg, &tmp, 10);
2085 2101
 					if (tmp &&(*tmp)){
2086 2102
 						fprintf(stderr, "bad optimization level: -O %s\n",
... ...
@@ -2093,6 +2109,10 @@ int main(int argc, char** argv)
2093 2109
 					user=optarg;
2094 2110
 					break;
2095 2111
 			case 'A':
2112
+					if (optarg == NULL) {
2113
+						fprintf(stderr, "bad -A parameter\n");
2114
+						goto error;
2115
+					}
2096 2116
 					p = strchr(optarg, '=');
2097 2117
 					if(p) {
2098 2118
 						*p = '\0';
... ...
@@ -2306,6 +2326,10 @@ try_again:
2306 2326
 									   takes priority over config */
2307 2327
 					break;
2308 2328
 			case 'b':
2329
+					if (optarg == NULL) {
2330
+						fprintf(stderr, "bad -b parameter\n");
2331
+						goto error;
2332
+					}
2309 2333
 					maxbuffer=strtol(optarg, &tmp, 10);
2310 2334
 					if (tmp &&(*tmp)){
2311 2335
 						fprintf(stderr, "bad max buffer size number: -b %s\n",
... ...
@@ -2328,6 +2352,10 @@ try_again:
2328 2352
 				#endif
2329 2353
 					break;
2330 2354
 			case 'l':
2355
+					if (optarg == NULL) {
2356
+						fprintf(stderr, "bad -l parameter\n");
2357
+						goto error;
2358
+					}
2331 2359
 					p = strrchr(optarg, '/');
2332 2360
 					if(p==NULL) {
2333 2361
 						p = optarg;
... ...
@@ -2377,6 +2405,10 @@ try_again:
2377 2405
 					free_name_lst(n_lst);
2378 2406
 					break;
2379 2407
 			case 'n':
2408
+					if (optarg == NULL) {
2409
+						fprintf(stderr, "bad -n parameter\n");
2410
+						goto error;
2411
+					}
2380 2412
 					children_no=strtol(optarg, &tmp, 10);
2381 2413
 					if ((tmp==0) ||(*tmp)){
2382 2414
 						fprintf(stderr, "bad process number: -n %s\n",
... ...
@@ -2403,6 +2435,10 @@ try_again:
2403 2435
  									"TCP support disabled\n", optarg);
2404 2436
 						goto error;
2405 2437
 					}
2438
+					if (optarg == NULL) {
2439
+						fprintf(stderr, "bad -N parameter\n");
2440
+						goto error;
2441
+					}
2406 2442
 					tcp_cfg_children_no=strtol(optarg, &tmp, 10);
2407 2443
 					if ((tmp==0) ||(*tmp)){
2408 2444
 						fprintf(stderr, "bad process number: -N %s\n",
... ...
@@ -2415,6 +2451,10 @@ try_again:
2415 2451
 					break;
2416 2452
 			case 'W':
2417 2453
 				#ifdef USE_TCP
2454
+					if (optarg == NULL) {
2455
+						fprintf(stderr, "bad -W parameter\n");
2456
+						goto error;
2457
+					}
2418 2458
 					tcp_poll_method=get_poll_type(optarg);
2419 2459
 					if (tcp_poll_method==POLL_NONE){
2420 2460
 						fprintf(stderr, "bad poll method name: -W %s\ntry "
... ...
@@ -2432,6 +2472,10 @@ try_again:
2432 2472
 									"SCTP support disabled\n", optarg);
2433 2473
 						goto error;
2434 2474
 					}
2475
+					if (optarg == NULL) {
2476
+						fprintf(stderr, "bad -Q parameter\n");
2477
+						goto error;
2478
+					}
2435 2479
 					sctp_children_no=strtol(optarg, &tmp, 10);
2436 2480
 					if ((tmp==0) ||(*tmp)){
2437 2481
 						fprintf(stderr, "bad process number: -O %s\n",