1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-02-03 17:11:32 +00:00

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
This commit is contained in:
Brian Somers 2000-07-20 09:05:15 +00:00
parent 4bb78bf510
commit 732d07e535
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=63622
2 changed files with 14 additions and 3 deletions

View File

@ -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 ,

View File

@ -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);
}