Browse code

core: main - several optarg safety checks

(cherry picked from commit 4f7b5537688293d196669dd5a7d0124f7656cf2d)

Daniel-Constantin Mierla authored on 06/04/2021 12:48:34
Showing 1 changed files
... ...
@@ -2077,6 +2077,10 @@ int main(int argc, char** argv)
2077 2077
 					/* ignore, they were parsed immediately after startup */
2078 2078
 					break;
2079 2079
 			case 'f':
2080
+					if (optarg == NULL) {
2081
+						fprintf(stderr, "bad -f parameter\n");
2082
+						goto error;
2083
+					}
2080 2084
 					cfg_file=optarg;
2081 2085
 					break;
2082 2086
 			case 'c':
... ...
@@ -2084,10 +2088,18 @@ int main(int argc, char** argv)
2084 2088
 					log_stderr=1; /* force stderr logging */
2085 2089
 					break;
2086 2090
 			case 'L':
2091
+					if (optarg == NULL) {
2092
+						fprintf(stderr, "bad -L parameter\n");
2093
+						goto error;
2094
+					}
2087 2095
 					mods_dir = optarg;
2088 2096
 					mods_dir_cmd = 1;
2089 2097
 					break;
2090 2098
 			case 'm':
2099
+					if (optarg == NULL) {
2100
+						fprintf(stderr, "bad shared mem size\n");
2101
+						goto error;
2102
+					}
2091 2103
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
2092 2104
 					if (tmp &&(*tmp)){
2093 2105
 						fprintf(stderr, "bad shmem size number: -m %s\n",
... ...
@@ -2125,6 +2137,10 @@ int main(int argc, char** argv)
2125 2137
 					/* ignore it, was parsed immediately after startup */
2126 2138
 					break;
2127 2139
 			case 'O':
2140
+					if (optarg == NULL) {
2141
+						fprintf(stderr, "bad -O parameter\n");
2142
+						goto error;
2143
+					}
2128 2144
 					scr_opt_lev=strtol(optarg, &tmp, 10);
2129 2145
 					if (tmp &&(*tmp)){
2130 2146
 						fprintf(stderr, "bad optimization level: -O %s\n",
... ...
@@ -2137,6 +2153,10 @@ int main(int argc, char** argv)
2137 2153
 					user=optarg;
2138 2154
 					break;
2139 2155
 			case 'A':
2156
+					if (optarg == NULL) {
2157
+						fprintf(stderr, "bad -A parameter\n");
2158
+						goto error;
2159
+					}
2140 2160
 					p = strchr(optarg, '=');
2141 2161
 					if(p) {
2142 2162
 						*p = '\0';
... ...
@@ -2378,6 +2398,10 @@ try_again:
2378 2398
 									   takes priority over config */
2379 2399
 					break;
2380 2400
 			case 'b':
2401
+					if (optarg == NULL) {
2402
+						fprintf(stderr, "bad -b parameter\n");
2403
+						goto error;
2404
+					}
2381 2405
 					maxbuffer=strtol(optarg, &tmp, 10);
2382 2406
 					if (tmp &&(*tmp)){
2383 2407
 						fprintf(stderr, "bad max buffer size number: -b %s\n",
... ...
@@ -2400,6 +2424,10 @@ try_again:
2400 2424
 				#endif
2401 2425
 					break;
2402 2426
 			case 'l':
2427
+					if (optarg == NULL) {
2428
+						fprintf(stderr, "bad -l parameter\n");
2429
+						goto error;
2430
+					}
2403 2431
 					p = strrchr(optarg, '/');
2404 2432
 					if(p==NULL) {
2405 2433
 						p = optarg;
... ...
@@ -2449,6 +2477,10 @@ try_again:
2449 2477
 					free_name_lst(n_lst);
2450 2478
 					break;
2451 2479
 			case 'n':
2480
+					if (optarg == NULL) {
2481
+						fprintf(stderr, "bad -n parameter\n");
2482
+						goto error;
2483
+					}
2452 2484
 					children_no=strtol(optarg, &tmp, 10);
2453 2485
 					if ((tmp==0) ||(*tmp)){
2454 2486
 						fprintf(stderr, "bad process number: -n %s\n",
... ...
@@ -2475,6 +2507,10 @@ try_again:
2475 2507
  									"TCP support disabled\n", optarg);
2476 2508
 						goto error;
2477 2509
 					}
2510
+					if (optarg == NULL) {
2511
+						fprintf(stderr, "bad -N parameter\n");
2512
+						goto error;
2513
+					}
2478 2514
 					tcp_cfg_children_no=strtol(optarg, &tmp, 10);
2479 2515
 					if ((tmp==0) ||(*tmp)){
2480 2516
 						fprintf(stderr, "bad process number: -N %s\n",
... ...
@@ -2487,6 +2523,10 @@ try_again:
2487 2523
 					break;
2488 2524
 			case 'W':
2489 2525
 				#ifdef USE_TCP
2526
+					if (optarg == NULL) {
2527
+						fprintf(stderr, "bad -W parameter\n");
2528
+						goto error;
2529
+					}
2490 2530
 					tcp_poll_method=get_poll_type(optarg);
2491 2531
 					if (tcp_poll_method==POLL_NONE){
2492 2532
 						fprintf(stderr, "bad poll method name: -W %s\ntry "
... ...
@@ -2504,6 +2544,10 @@ try_again:
2504 2544
 									"SCTP support disabled\n", optarg);
2505 2545
 						goto error;
2506 2546
 					}
2547
+					if (optarg == NULL) {
2548
+						fprintf(stderr, "bad -Q parameter\n");
2549
+						goto error;
2550
+					}
2507 2551
 					sctp_children_no=strtol(optarg, &tmp, 10);
2508 2552
 					if ((tmp==0) ||(*tmp)){
2509 2553
 						fprintf(stderr, "bad process number: -O %s\n",