Browse code

core: main - checking of optarg for covering all unixes

Daniel-Constantin Mierla authored on 09/04/2021 07:34:29
Showing 1 changed files
... ...
@@ -2095,6 +2095,10 @@ int main(int argc, char** argv)
2095 2095
 					ksr_cfg_print_mode = 1;
2096 2096
 					break;
2097 2097
 			case KARGOPTVAL+10:
2098
+					if (optarg == NULL) {
2099
+						fprintf(stderr, "bad atexit value\n");
2100
+						goto error;
2101
+					}
2098 2102
 					if(optarg[0]=='y' || optarg[0]=='1') {
2099 2103
 						ksr_atexit_mode = 1;
2100 2104
 					} else if(optarg[0]=='n' || optarg[0]=='0') {
... ...
@@ -2234,6 +2238,10 @@ int main(int argc, char** argv)
2234 2238
 					};
2235 2239
 					break;
2236 2240
 			case 'u':
2241
+					if (optarg == NULL) {
2242
+						fprintf(stderr, "bad -u parameter\n");
2243
+						goto error;
2244
+					}
2237 2245
 					/* user needed for possible shm. pre-init */
2238 2246
 					user=optarg;
2239 2247
 					break;
... ...
@@ -2293,6 +2301,10 @@ int main(int argc, char** argv)
2293 2301
 
2294 2302
 			/* long options */
2295 2303
 			case KARGOPTVAL:
2304
+					if (optarg == NULL) {
2305
+						fprintf(stderr, "bad alias parameter\n");
2306
+						goto error;
2307
+					}
2296 2308
 					if(parse_phostport(optarg, &tmp, &tmp_len,
2297 2309
 											&port, &proto)!=0) {
2298 2310
 						fprintf(stderr, "Invalid alias value '%s'\n", optarg);
... ...
@@ -2304,24 +2316,40 @@ int main(int argc, char** argv)
2304 2316
 					}
2305 2317
 					break;
2306 2318
 			case KARGOPTVAL+1:
2319
+					if (optarg == NULL) {
2320
+						fprintf(stderr, "bad subst parameter\n");
2321
+						goto error;
2322
+					}
2307 2323
 					if(pp_subst_add(optarg)<0) {
2308 2324
 						LM_ERR("failed to add subst expression: %s\n", optarg);
2309 2325
 						goto error;
2310 2326
 					}
2311 2327
 					break;
2312 2328
 			case KARGOPTVAL+2:
2329
+					if (optarg == NULL) {
2330
+						fprintf(stderr, "bad substdef parameter\n");
2331
+						goto error;
2332
+					}
2313 2333
 					if(pp_substdef_add(optarg, 0)<0) {
2314 2334
 						LM_ERR("failed to add substdef expression: %s\n", optarg);
2315 2335
 						goto error;
2316 2336
 					}
2317 2337
 					break;
2318 2338
 			case KARGOPTVAL+3:
2339
+					if (optarg == NULL) {
2340
+						fprintf(stderr, "bad substdefs parameter\n");
2341
+						goto error;
2342
+					}
2319 2343
 					if(pp_substdef_add(optarg, 1)<0) {
2320 2344
 						LM_ERR("failed to add substdefs expression: %s\n", optarg);
2321 2345
 						goto error;
2322 2346
 					}
2323 2347
 					break;
2324 2348
 			case KARGOPTVAL+4:
2349
+					if (optarg == NULL) {
2350
+						fprintf(stderr, "bad server if parameter\n");
2351
+						goto error;
2352
+					}
2325 2353
 					server_id=(int)strtol(optarg, &tmp, 10);
2326 2354
 					if ((tmp==0) || (*tmp)){
2327 2355
 						LM_ERR("bad server_id value: %s\n", optarg);
... ...
@@ -2383,12 +2411,20 @@ int main(int argc, char** argv)
2383 2411
 	while((c=getopt_long(argc, argv, options, long_options, &option_index))!=-1) {
2384 2412
 		switch(c) {
2385 2413
 			case KARGOPTVAL+5:
2414
+					if (optarg == NULL) {
2415
+						fprintf(stderr, "bad load module parameter\n");
2416
+						goto error;
2417
+					}
2386 2418
 					if (load_module(optarg)!=0) {
2387 2419
 						LM_ERR("failed to load the module: %s\n", optarg);
2388 2420
 						goto error;
2389 2421
 					}
2390 2422
 					break;
2391 2423
 			case KARGOPTVAL+6:
2424
+					if (optarg == NULL) {
2425
+						fprintf(stderr, "bad modparam parameter\n");
2426
+						goto error;
2427
+					}
2392 2428
 					if(set_mod_param_serialized(optarg) < 0) {
2393 2429
 						LM_ERR("failed to set modparam: %s\n", optarg);
2394 2430
 						goto error;