summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2000-07-20 09:05:15 +0000
committerbrian <brian@FreeBSD.org>2000-07-20 09:05:15 +0000
commit145f71945d245c592d771bd0138510d7bcb43f1a (patch)
tree977d504c42072179b35113c243b77b58524acc88 /lib
parent93bac0087e1506b7c834bf6c6d364194717b2ecd (diff)
downloadFreeBSD-src-145f71945d245c592d771bd0138510d7bcb43f1a.zip
FreeBSD-src-145f71945d245c592d771bd0138510d7bcb43f1a.tar.gz
Alocate rcmd{,_af}()'s *ahost argument using malloc() (well
strdup()) rather than pointing it at something that's free()d (via freeaddrinfo(res)) before the function returns. I appreciate that this is an API change, but it's the only way (AFAIK) of doing this without breaking existing code that uses rcmd{,_af}(). Pointed out by: phkmalloc
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/rcmd.35
-rw-r--r--lib/libc/net/rcmd.c12
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3
index 63f7fb5..7aa77e1 100644
--- a/lib/libc/net/rcmd.3
+++ b/lib/libc/net/rcmd.3
@@ -99,6 +99,10 @@ is set to the standard name of the host
and a connection is established to a server
residing at the well-known Internet port
.Fa inport .
+It is up to the caller to free the memory associated with
+.Fa *ahost
+using
+.Fn free .
.Pp
If the connection succeeds,
a socket in the Internet domain of type
@@ -264,6 +268,7 @@ is overloaded to mean ``All network ports in use.''
.Xr rlogin 1 ,
.Xr rsh 1 ,
.Xr intro 2 ,
+.Xr free 3 ,
.Xr rexec 3 ,
.Xr rexecd 8 ,
.Xr rlogind 8 ,
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 70a18d4..6f076ed 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -100,7 +100,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
int s, aport, lport, timo, error;
char c;
int refused;
- char num[8];
+ char num[8], *ohost;
pid = getpid();
@@ -119,8 +119,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
strerror(errno));
return (-1);
}
- if (res->ai_canonname)
- *ahost = res->ai_canonname;
+ ohost = *ahost;
+ *ahost = strdup(res->ai_canonname ? res->ai_canonname : *ahost);
ai = res;
refused = 0;
oldmask = sigblock(sigmask(SIGURG));
@@ -139,6 +139,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
strerror(errno));
freeaddrinfo(res);
sigsetmask(oldmask);
+ free(*ahost);
+ *ahost = ohost;
return (-1);
}
_fcntl(s, F_SETOWN, pid);
@@ -185,6 +187,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af)
(void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno));
freeaddrinfo(res);
sigsetmask(oldmask);
+ free(*ahost);
+ *ahost = ohost;
return (-1);
}
lport--;
@@ -292,6 +296,8 @@ bad:
(void)_close(s);
sigsetmask(oldmask);
freeaddrinfo(res);
+ free(*ahost);
+ *ahost = ohost;
return (-1);
}
OpenPOWER on IntegriCloud