aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDon Lewis <truckman@FreeBSD.org>2016-05-12 05:43:54 +0000
committerDon Lewis <truckman@FreeBSD.org>2016-05-12 05:43:54 +0000
commiteeb6394364222289c401422a054d680576b050d2 (patch)
treed274127edd78d096c19af96aba4052cb50f2ccf0
parenta09a9cbb40376c4d604fabdd75e98f77314578bc (diff)
downloadsrc-eeb6394364222289c401422a054d680576b050d2.tar.gz
src-eeb6394364222289c401422a054d680576b050d2.zip
Check for socket creation success before calling bind().
Reported by: Coverity CID: 1194209
Notes
Notes: svn path=/head/; revision=299516
-rw-r--r--sbin/ping/ping.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index e7df6cab08a2..db78ef606025 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -285,6 +285,16 @@ main(int argc, char *const *argv)
err(EX_NOPERM, "setuid() failed");
uid = getuid();
+ if (ssend < 0) {
+ errno = ssend_errno;
+ err(EX_OSERR, "ssend socket");
+ }
+
+ if (srecv < 0) {
+ errno = srecv_errno;
+ err(EX_OSERR, "srecv socket");
+ }
+
alarmtimeout = df = preload = tos = 0;
outpack = outpackhdr + sizeof(struct ip);
@@ -625,16 +635,6 @@ main(int argc, char *const *argv)
}
#endif
- if (ssend < 0) {
- errno = ssend_errno;
- err(EX_OSERR, "ssend socket");
- }
-
- if (srecv < 0) {
- errno = srecv_errno;
- err(EX_OSERR, "srecv socket");
- }
-
if (connect(ssend, (struct sockaddr *)&whereto, sizeof(whereto)) != 0)
err(1, "connect");