comparison netio.c @ 1383:f03cfe9c76ac fuzz

Disable setnonblocking(), get_socket_address(), set_sock_priority() for fuzzing
author Matt Johnston <matt@ucc.asn.au>
date Fri, 26 May 2017 22:10:51 +0800
parents 08f4fa4dc6a0
children 69862e8cc405
comparison
equal deleted inserted replaced
1382:4b864fd12b22 1383:f03cfe9c76ac
309 #endif 309 #endif
310 #ifdef SO_PRIORITY 310 #ifdef SO_PRIORITY
311 int so_prio_val = 0; 311 int so_prio_val = 0;
312 #endif 312 #endif
313 313
314 #ifdef DROPBEAR_FUZZ
315 if (fuzz.fuzzing) {
316 TRACE(("fuzzing skips set_sock_prio"))
317 return;
318 }
319 #endif
314 320
315 /* Don't log ENOTSOCK errors so that this can harmlessly be called 321 /* Don't log ENOTSOCK errors so that this can harmlessly be called
316 * on a client '-J' proxy pipe */ 322 * on a client '-J' proxy pipe */
317 323
318 /* set the TOS bit for either ipv4 or ipv6 */ 324 /* set the TOS bit for either ipv4 or ipv6 */
480 void get_socket_address(int fd, char **local_host, char **local_port, 486 void get_socket_address(int fd, char **local_host, char **local_port,
481 char **remote_host, char **remote_port, int host_lookup) 487 char **remote_host, char **remote_port, int host_lookup)
482 { 488 {
483 struct sockaddr_storage addr; 489 struct sockaddr_storage addr;
484 socklen_t addrlen; 490 socklen_t addrlen;
491
492 #if DROPBEAR_FUZZ
493 if (fuzz.fuzzing) {
494 fuzz_get_socket_address(fd, local_host, local_port, remote_host, remote_port, host_lookup);
495 return;
496 }
497 #endif
485 498
486 if (local_host || local_port) { 499 if (local_host || local_port) {
487 addrlen = sizeof(addr); 500 addrlen = sizeof(addr);
488 if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) { 501 if (getsockname(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
489 if (errno == ENOTSOCK) { 502 dropbear_exit("Failed socket address: %s", strerror(errno));
490 // FUZZ
491 if (local_host) {
492 *local_host = m_strdup("notsocket");
493 }
494 if (local_port) {
495 *local_port = m_strdup("999");
496 }
497 return;
498 } else {
499 dropbear_exit("Failed socket address: %s", strerror(errno));
500 }
501 } 503 }
502 getaddrstring(&addr, local_host, local_port, host_lookup); 504 getaddrstring(&addr, local_host, local_port, host_lookup);
503 } 505 }
504 if (remote_host || remote_port) { 506 if (remote_host || remote_port) {
505 addrlen = sizeof(addr); 507 addrlen = sizeof(addr);
506 if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) { 508 if (getpeername(fd, (struct sockaddr*)&addr, &addrlen) < 0) {
507 if (errno == ENOTSOCK) { 509 dropbear_exit("Failed socket address: %s", strerror(errno));
508 // FUZZ
509 if (remote_host) {
510 *remote_host = m_strdup("notsocket");
511 }
512 if (remote_port) {
513 *remote_port = m_strdup("999");
514 }
515 return;
516 } else {
517 dropbear_exit("Failed socket address: %s", strerror(errno));
518 }
519 } 510 }
520 getaddrstring(&addr, remote_host, remote_port, host_lookup); 511 getaddrstring(&addr, remote_host, remote_port, host_lookup);
521 } 512 }
522 } 513 }
523 514
567 * to exhibit that behaviour. */ 558 * to exhibit that behaviour. */
568 getaddrstring(addr, ret_host, ret_port, 0); 559 getaddrstring(addr, ret_host, ret_port, 0);
569 return; 560 return;
570 } else { 561 } else {
571 /* if we can't do a numeric lookup, something's gone terribly wrong */ 562 /* if we can't do a numeric lookup, something's gone terribly wrong */
572 if (ret == EAI_FAMILY) {
573 // FUZZ
574 // Fake it for non-socket input
575 if (ret_host) {
576 *ret_host = m_strdup("0.0.0.0");
577 }
578 if (ret_port)
579 {
580 *ret_port = m_strdup("999");
581 }
582 return;
583 }
584 dropbear_exit("Failed lookup: %s", gai_strerror(ret)); 563 dropbear_exit("Failed lookup: %s", gai_strerror(ret));
585 } 564 }
586 } 565 }
587 566
588 if (ret_host) { 567 if (ret_host) {