Make a malloced copy of "chrootdir" even if it points to an absolute

pathname inside "residue" so "chrootdir" can be simply freed later.

PR:		bin/53435
Submitted by:	Yutaka Ishihara <yutaka at fandc.co.jp>
MFC after:	1 week
This commit is contained in:
yar 2003-07-09 12:46:24 +00:00
parent 9bee0009ad
commit 72eaf383f4

View File

@ -1494,9 +1494,11 @@ pass(char *passwd)
* c) expand it to the absolute pathname if necessary.
*/
if (dochroot && residue &&
(chrootdir = strtok(residue, " \t")) != NULL &&
chrootdir[0] != '/') {
asprintf(&chrootdir, "%s/%s", pw->pw_dir, chrootdir);
(chrootdir = strtok(residue, " \t")) != NULL) {
if (chrootdir[0] != '/')
asprintf(&chrootdir, "%s/%s", pw->pw_dir, chrootdir);
else
chrootdir = strdup(chrootdir); /* so it can be freed */
if (chrootdir == NULL)
fatalerror("Ran out of memory.");
}