aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/akcom-udpecho.c
diff options
context:
space:
mode:
authorDavid M. Syzdek <david.syzdek@acsalaska.com>2022-07-21 23:19:40 -0800
committerDavid M. Syzdek <david.syzdek@acsalaska.com>2022-07-21 23:19:40 -0800
commit8cf0ea9cef7defefff31a54469bdf4552ff8c076 (patch)
treeae32ba951dbf6b28d73a0eab208f5384a280840f /src/akcom-udpecho.c
parentf285bd7f3d7ab38115c25b016ff848641437a877 (diff)
downloadakcom-udpecho-8cf0ea9cef7defefff31a54469bdf4552ff8c076.tar.gz
akcom-udpecho-8cf0ea9cef7defefff31a54469bdf4552ff8c076.tar.bz2
akcom-udpecho-8cf0ea9cef7defefff31a54469bdf4552ff8c076.tar.xz
akcom-udpecho-8cf0ea9cef7defefff31a54469bdf4552ff8c076.zip
akcom-udpecho: fixing possible pointer dereferencing error
Diffstat (limited to '')
-rw-r--r--src/akcom-udpecho.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/akcom-udpecho.c b/src/akcom-udpecho.c
index 8fdcc88..e6a2299 100644
--- a/src/akcom-udpecho.c
+++ b/src/akcom-udpecho.c
@@ -629,7 +629,8 @@ my_socket(
629 fprintf(stderr, "%s: getaddrinfo(): %s\n", prog_name, gai_strerror(rc)); 629 fprintf(stderr, "%s: getaddrinfo(): %s\n", prog_name, gai_strerror(rc));
630 return(-1); 630 return(-1);
631 }; 631 };
632 for(info = res; (info != NULL); info = info->ai_next) 632 // use first IPv6 address
633 for(info = res; ((info != NULL) && (!(socklen)) ); info = info->ai_next)
633 { 634 {
634 if (info->ai_addr->sa_family != AF_INET6) 635 if (info->ai_addr->sa_family != AF_INET6)
635 continue; 636 continue;
@@ -638,9 +639,12 @@ my_socket(
638 inet_ntop(AF_INET6, &sa.sin6.sin6_addr, addrstr, sizeof(addrstr)); 639 inet_ntop(AF_INET6, &sa.sin6.sin6_addr, addrstr, sizeof(addrstr));
639 port = ntohs(sa.sin6.sin6_port); 640 port = ntohs(sa.sin6.sin6_port);
640 snprintf(logmsg, sizeof(logmsg), "UDPECHO %s:%hu ([%s]:%hu): %zu bytes\n", cnf_host, port, addrstr, port, cnf_packetsize); 641 snprintf(logmsg, sizeof(logmsg), "UDPECHO %s:%hu ([%s]:%hu): %zu bytes\n", cnf_host, port, addrstr, port, cnf_packetsize);
641 } 642 };
642 if (sa.sa.sa_family != AF_INET6) 643 // use first IPv4 address, if no IPv6 address
644 for(info = res; ((info != NULL) && (!(socklen)) ); info = info->ai_next)
643 { 645 {
646 if (info->ai_addr->sa_family != AF_INET)
647 continue;
644 socklen = res->ai_addrlen; 648 socklen = res->ai_addrlen;
645 memcpy(&sa.sa, res->ai_addr, socklen); 649 memcpy(&sa.sa, res->ai_addr, socklen);
646 inet_ntop(AF_INET, &sa.sin.sin_addr, addrstr, sizeof(addrstr)); 650 inet_ntop(AF_INET, &sa.sin.sin_addr, addrstr, sizeof(addrstr));
@@ -648,6 +652,11 @@ my_socket(
648 snprintf(logmsg, sizeof(logmsg), "UDPECHO %s:%hu (%s:%hu): %zu bytes\n", cnf_host, port, addrstr, port, cnf_packetsize); 652 snprintf(logmsg, sizeof(logmsg), "UDPECHO %s:%hu (%s:%hu): %zu bytes\n", cnf_host, port, addrstr, port, cnf_packetsize);
649 }; 653 };
650 freeaddrinfo(res); 654 freeaddrinfo(res);
655 if (!(socklen))
656 {
657 fprintf(stderr, "%s: unable to resolve host\n", prog_name);
658 return(-1);
659 };
651 if (!(cnf_silent)) 660 if (!(cnf_silent))
652 printf("%s", logmsg); 661 printf("%s", logmsg);
653 662