Browse code

core: main - several optarg safety checks

Daniel-Constantin Mierla authored on 06/04/2021 12:48:34
Showing 1 changed files
... ...
@@ -2140,6 +2140,10 @@ int main(int argc, char** argv)
2140 2140
 					/* ignore, they were parsed immediately after startup */
2141 2141
 					break;
2142 2142
 			case 'f':
2143
+					if (optarg == NULL) {
2144
+						fprintf(stderr, "bad -f parameter\n");
2145
+						goto error;
2146
+					}
2143 2147
 					cfg_file=optarg;
2144 2148
 					break;
2145 2149
 			case 'c':
... ...
@@ -2147,10 +2151,18 @@ int main(int argc, char** argv)
2147 2151
 					log_stderr=1; /* force stderr logging */
2148 2152
 					break;
2149 2153
 			case 'L':
2154
+					if (optarg == NULL) {
2155
+						fprintf(stderr, "bad -L parameter\n");
2156
+						goto error;
2157
+					}
2150 2158
 					mods_dir = optarg;
2151 2159
 					mods_dir_cmd = 1;
2152 2160
 					break;
2153 2161
 			case 'm':
2162
+					if (optarg == NULL) {
2163
+						fprintf(stderr, "bad shared mem size\n");
2164
+						goto error;
2165
+					}
2154 2166
 					shm_mem_size=strtol(optarg, &tmp, 10) * 1024 * 1024;
2155 2167
 					if (tmp &&(*tmp)){
2156 2168
 						fprintf(stderr, "bad shmem size number: -m %s\n",
... ...
@@ -2188,6 +2200,10 @@ int main(int argc, char** argv)
2188 2200
 					/* ignore it, was parsed immediately after startup */
2189 2201
 					break;
2190 2202
 			case 'O':
2203
+					if (optarg == NULL) {
2204
+						fprintf(stderr, "bad -O parameter\n");
2205
+						goto error;
2206
+					}
2191 2207
 					scr_opt_lev=strtol(optarg, &tmp, 10);
2192 2208
 					if (tmp &&(*tmp)){
2193 2209
 						fprintf(stderr, "bad optimization level: -O %s\n",
... ...
@@ -2200,6 +2216,10 @@ int main(int argc, char** argv)
2200 2216
 					user=optarg;
2201 2217
 					break;
2202 2218
 			case 'A':
2219
+					if (optarg == NULL) {
2220
+						fprintf(stderr, "bad -A parameter\n");
2221
+						goto error;
2222
+					}
2203 2223
 					p = strchr(optarg, '=');
2204 2224
 					if(p) {
2205 2225
 						tmp_len = p - optarg;
... ...
@@ -2451,6 +2471,10 @@ try_again:
2451 2471
 									   takes priority over config */
2452 2472
 					break;
2453 2473
 			case 'b':
2474
+					if (optarg == NULL) {
2475
+						fprintf(stderr, "bad -b parameter\n");
2476
+						goto error;
2477
+					}
2454 2478
 					maxbuffer=strtol(optarg, &tmp, 10);
2455 2479
 					if (tmp &&(*tmp)){
2456 2480
 						fprintf(stderr, "bad max buffer size number: -b %s\n",
... ...
@@ -2473,6 +2497,10 @@ try_again:
2473 2497
 				#endif
2474 2498
 					break;
2475 2499
 			case 'l':
2500
+					if (optarg == NULL) {
2501
+						fprintf(stderr, "bad -l parameter\n");
2502
+						goto error;
2503
+					}
2476 2504
 					p = strrchr(optarg, '/');
2477 2505
 					if(p==NULL) {
2478 2506
 						p = optarg;
... ...
@@ -2522,6 +2550,10 @@ try_again:
2522 2550
 					free_name_lst(n_lst);
2523 2551
 					break;
2524 2552
 			case 'n':
2553
+					if (optarg == NULL) {
2554
+						fprintf(stderr, "bad -n parameter\n");
2555
+						goto error;
2556
+					}
2525 2557
 					children_no=strtol(optarg, &tmp, 10);
2526 2558
 					if ((tmp==0) ||(*tmp)){
2527 2559
 						fprintf(stderr, "bad process number: -n %s\n",
... ...
@@ -2548,6 +2580,10 @@ try_again:
2548 2580
  									"TCP support disabled\n", optarg);
2549 2581
 						goto error;
2550 2582
 					}
2583
+					if (optarg == NULL) {
2584
+						fprintf(stderr, "bad -N parameter\n");
2585
+						goto error;
2586
+					}
2551 2587
 					tcp_cfg_children_no=strtol(optarg, &tmp, 10);
2552 2588
 					if ((tmp==0) ||(*tmp)){
2553 2589
 						fprintf(stderr, "bad process number: -N %s\n",
... ...
@@ -2560,6 +2596,10 @@ try_again:
2560 2596
 					break;
2561 2597
 			case 'W':
2562 2598
 				#ifdef USE_TCP
2599
+					if (optarg == NULL) {
2600
+						fprintf(stderr, "bad -W parameter\n");
2601
+						goto error;
2602
+					}
2563 2603
 					tcp_poll_method=get_poll_type(optarg);
2564 2604
 					if (tcp_poll_method==POLL_NONE){
2565 2605
 						fprintf(stderr, "bad poll method name: -W %s\ntry "
... ...
@@ -2577,6 +2617,10 @@ try_again:
2577 2617
 									"SCTP support disabled\n", optarg);
2578 2618
 						goto error;
2579 2619
 					}
2620
+					if (optarg == NULL) {
2621
+						fprintf(stderr, "bad -Q parameter\n");
2622
+						goto error;
2623
+					}
2580 2624
 					sctp_children_no=strtol(optarg, &tmp, 10);
2581 2625
 					if ((tmp==0) ||(*tmp)){
2582 2626
 						fprintf(stderr, "bad process number: -O %s\n",