Mercurial > dropbear
comparison svr-runopts.c @ 1197:86a9e0204c03
ports and addresses must be malloced to avoid segfault on exit
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 02 Dec 2015 22:37:20 +0800 |
parents | 53751952ed95 |
children | 64a50eac1030 |
comparison
equal
deleted
inserted
replaced
1195:8a5e9a97bd7a | 1197:86a9e0204c03 |
---|---|
31 #include "ecdsa.h" | 31 #include "ecdsa.h" |
32 | 32 |
33 svr_runopts svr_opts; /* GLOBAL */ | 33 svr_runopts svr_opts; /* GLOBAL */ |
34 | 34 |
35 static void printhelp(const char * progname); | 35 static void printhelp(const char * progname); |
36 static void addportandaddress(char* spec); | 36 static void addportandaddress(const char* spec); |
37 static void loadhostkey(const char *keyfile, int fatal_duplicate); | 37 static void loadhostkey(const char *keyfile, int fatal_duplicate); |
38 static void addhostkey(const char *keyfile); | 38 static void addhostkey(const char *keyfile); |
39 | 39 |
40 static void printhelp(const char * progname) { | 40 static void printhelp(const char * progname) { |
41 | 41 |
346 } | 346 } |
347 opts.idle_timeout_secs = val; | 347 opts.idle_timeout_secs = val; |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 static void addportandaddress(char* spec) { | 351 static void addportandaddress(const char* spec) { |
352 | 352 char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL; |
353 char *myspec = NULL; | |
354 | 353 |
355 if (svr_opts.portcount < DROPBEAR_MAX_PORTS) { | 354 if (svr_opts.portcount < DROPBEAR_MAX_PORTS) { |
356 | 355 |
357 /* We don't free it, it becomes part of the runopt state */ | 356 /* We don't free it, it becomes part of the runopt state */ |
358 myspec = m_strdup(spec); | 357 spec_copy = m_strdup(spec); |
358 myspec = spec_copy; | |
359 | 359 |
360 if (myspec[0] == '[') { | 360 if (myspec[0] == '[') { |
361 myspec++; | 361 myspec++; |
362 svr_opts.ports[svr_opts.portcount] = strchr(myspec, ']'); | 362 port = strchr(myspec, ']'); |
363 if (svr_opts.ports[svr_opts.portcount] == NULL) { | 363 if (!port) { |
364 /* Unmatched [ -> exit */ | 364 /* Unmatched [ -> exit */ |
365 dropbear_exit("Bad listen address"); | 365 dropbear_exit("Bad listen address"); |
366 } | 366 } |
367 svr_opts.ports[svr_opts.portcount][0] = '\0'; | 367 port[0] = '\0'; |
368 svr_opts.ports[svr_opts.portcount]++; | 368 port++; |
369 if (svr_opts.ports[svr_opts.portcount][0] != ':') { | 369 if (port[0] != ':') { |
370 /* Missing port -> exit */ | 370 /* Missing port -> exit */ |
371 dropbear_exit("Missing port"); | 371 dropbear_exit("Missing port"); |
372 } | 372 } |
373 } else { | 373 } else { |
374 /* search for ':', that separates address and port */ | 374 /* search for ':', that separates address and port */ |
375 svr_opts.ports[svr_opts.portcount] = strrchr(myspec, ':'); | 375 port = strrchr(myspec, ':'); |
376 } | 376 } |
377 | 377 |
378 if (svr_opts.ports[svr_opts.portcount] == NULL) { | 378 if (!port) { |
379 /* no ':' -> the whole string specifies just a port */ | 379 /* no ':' -> the whole string specifies just a port */ |
380 svr_opts.ports[svr_opts.portcount] = myspec; | 380 port = myspec; |
381 } else { | 381 } else { |
382 /* Split the address/port */ | 382 /* Split the address/port */ |
383 svr_opts.ports[svr_opts.portcount][0] = '\0'; | 383 port[0] = '\0'; |
384 svr_opts.ports[svr_opts.portcount]++; | 384 port++; |
385 svr_opts.addresses[svr_opts.portcount] = myspec; | 385 address = myspec; |
386 } | 386 } |
387 | 387 |
388 if (svr_opts.addresses[svr_opts.portcount] == NULL) { | 388 if (!address) { |
389 /* no address given -> fill in the default address */ | 389 /* no address given -> fill in the default address */ |
390 svr_opts.addresses[svr_opts.portcount] = m_strdup(DROPBEAR_DEFADDRESS); | 390 address = DROPBEAR_DEFADDRESS; |
391 } | 391 } |
392 | 392 |
393 if (svr_opts.ports[svr_opts.portcount][0] == '\0') { | 393 if (port[0] == '\0') { |
394 /* empty port -> exit */ | 394 /* empty port -> exit */ |
395 dropbear_exit("Bad port"); | 395 dropbear_exit("Bad port"); |
396 } | 396 } |
397 | 397 svr_opts.ports[svr_opts.portcount] = m_strdup(port); |
398 svr_opts.addresses[svr_opts.portcount] = m_strdup(address); | |
398 svr_opts.portcount++; | 399 svr_opts.portcount++; |
400 m_free(spec_copy); | |
399 } | 401 } |
400 } | 402 } |
401 | 403 |
402 static void disablekey(int type) { | 404 static void disablekey(int type) { |
403 int i; | 405 int i; |