comparison svr-runopts.c @ 1348:5c2899e35b63 fuzz

fuzz harness
author Matt Johnston <matt@ucc.asn.au>
date Sat, 13 May 2017 22:50:54 +0800
parents b28624698130
children 3fdd8c5a0195
comparison
equal deleted inserted replaced
1347:b28624698130 1348:5c2899e35b63
344 if (m_str_to_uint(idle_timeout_arg, &val) == DROPBEAR_FAILURE) { 344 if (m_str_to_uint(idle_timeout_arg, &val) == DROPBEAR_FAILURE) {
345 dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg); 345 dropbear_exit("Bad idle_timeout '%s'", idle_timeout_arg);
346 } 346 }
347 opts.idle_timeout_secs = val; 347 opts.idle_timeout_secs = val;
348 } 348 }
349
350 #ifdef DROPBEAR_FUZZ
351 if (opts.fuzz.fuzzing) {
352 struct passwd *pw;
353 /* user lookups might be slow, cache it */
354 pw = getpwuid(getuid());
355 dropbear_assert(pw);
356 opts.fuzz.pw_name = m_strdup(pw->pw_name);
357 opts.fuzz.pw_dir = m_strdup(pw->pw_dir);
358 opts.fuzz.pw_shell = m_strdup(pw->pw_shell);
359 opts.fuzz.pw_passwd = m_strdup("!!zzznope");
360 }
361 #endif
362 } 349 }
363 350
364 static void addportandaddress(const char* spec) { 351 static void addportandaddress(const char* spec) {
365 char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL; 352 char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL;
366 353
486 } 473 }
487 svr_opts.hostkey_files[svr_opts.num_hostkey_files] = m_strdup(keyfile); 474 svr_opts.hostkey_files[svr_opts.num_hostkey_files] = m_strdup(keyfile);
488 svr_opts.num_hostkey_files++; 475 svr_opts.num_hostkey_files++;
489 } 476 }
490 477
491 #ifdef DROPBEAR_FUZZ
492 static void load_fixed_hostkeys() {
493 #include "hostkeys.c"
494
495 buffer *b = buf_new(3000);
496 enum signkey_type type;
497
498 TRACE(("load fixed hostkeys"))
499
500 svr_opts.hostkey = new_sign_key();
501
502 buf_setlen(b, 0);
503 buf_putbytes(b, keyr, keyr_len);
504 buf_setpos(b, 0);
505 type = DROPBEAR_SIGNKEY_RSA;
506 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
507 dropbear_exit("failed fixed rsa hostkey");
508 }
509
510 buf_setlen(b, 0);
511 buf_putbytes(b, keyd, keyd_len);
512 buf_setpos(b, 0);
513 type = DROPBEAR_SIGNKEY_DSS;
514 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
515 dropbear_exit("failed fixed dss hostkey");
516 }
517
518 buf_setlen(b, 0);
519 buf_putbytes(b, keye, keye_len);
520 buf_setpos(b, 0);
521 type = DROPBEAR_SIGNKEY_ECDSA_NISTP256;
522 if (buf_get_priv_key(b, svr_opts.hostkey, &type) == DROPBEAR_FAILURE) {
523 dropbear_exit("failed fixed ecdsa hostkey");
524 }
525
526 buf_free(b);
527 }
528 #endif // DROPBEAR_FUZZ
529 478
530 void load_all_hostkeys() { 479 void load_all_hostkeys() {
531 int i; 480 int i;
532 int disable_unset_keys = 1; 481 int disable_unset_keys = 1;
533 int any_keys = 0; 482 int any_keys = 0;
534
535 #ifdef DROPBEAR_FUZZ
536 if (opts.fuzz.fuzzing) {
537 load_fixed_hostkeys();
538 return;
539 }
540 #endif
541 483
542 svr_opts.hostkey = new_sign_key(); 484 svr_opts.hostkey = new_sign_key();
543 485
544 for (i = 0; i < svr_opts.num_hostkey_files; i++) { 486 for (i = 0; i < svr_opts.num_hostkey_files; i++) {
545 char *hostkey_file = svr_opts.hostkey_files[i]; 487 char *hostkey_file = svr_opts.hostkey_files[i];