comparison svr-runopts.c @ 1347:b28624698130 fuzz

copy over some fuzzing code from AFL branch
author Matt Johnston <matt@ucc.asn.au>
date Fri, 12 May 2017 23:14:54 +0800
parents 64a50eac1030
children 5c2899e35b63
comparison
equal deleted inserted replaced
1346:78b7e0634117 1347:b28624698130
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
349 } 362 }
350 363
351 static void addportandaddress(const char* spec) { 364 static void addportandaddress(const char* spec) {
352 char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL; 365 char *spec_copy = NULL, *myspec = NULL, *port = NULL, *address = NULL;
353 366
473 } 486 }
474 svr_opts.hostkey_files[svr_opts.num_hostkey_files] = m_strdup(keyfile); 487 svr_opts.hostkey_files[svr_opts.num_hostkey_files] = m_strdup(keyfile);
475 svr_opts.num_hostkey_files++; 488 svr_opts.num_hostkey_files++;
476 } 489 }
477 490
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 void load_all_hostkeys() { 530 void load_all_hostkeys() {
479 int i; 531 int i;
480 int disable_unset_keys = 1; 532 int disable_unset_keys = 1;
481 int any_keys = 0; 533 int any_keys = 0;
534
535 #ifdef DROPBEAR_FUZZ
536 if (opts.fuzz.fuzzing) {
537 load_fixed_hostkeys();
538 return;
539 }
540 #endif
482 541
483 svr_opts.hostkey = new_sign_key(); 542 svr_opts.hostkey = new_sign_key();
484 543
485 for (i = 0; i < svr_opts.num_hostkey_files; i++) { 544 for (i = 0; i < svr_opts.num_hostkey_files; i++) {
486 char *hostkey_file = svr_opts.hostkey_files[i]; 545 char *hostkey_file = svr_opts.hostkey_files[i];