realpath allocates memory

This commit is contained in:
Arun Prakash Jana 2020-02-29 12:56:10 +05:30
parent 5198c62863
commit 0d7d0ca7db
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -2926,12 +2926,10 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, ushort *items)
return FALSE; return FALSE;
} }
if (nextkey - ptr > 1) { if (nextkey - ptr > 1)
--nextkey;
/* Clear trailing ; or / */ /* Clear trailing ; or / */
if (*nextkey == ';' || (*nextkey == '/' && *(nextkey - 1) != ':')) if (*--nextkey == ';')
*(*envcpy + (nextkey - ptr)) = '\0'; *(*envcpy + (nextkey - ptr)) = '\0';
}
ptr = *envcpy; ptr = *envcpy;
nextkey = ptr; nextkey = ptr;
@ -2950,10 +2948,6 @@ static bool parsekvpair(kv **arr, char **envcpy, const uchar id, ushort *items)
} }
if (*ptr == ';') { if (*ptr == ';') {
/* Remove trailing space */
if (i > 0 && *(ptr - 1) == '/')
*(ptr - 1) = '\0';
*ptr = '\0'; *ptr = '\0';
nextkey = ptr + 1; nextkey = ptr + 1;
} }
@ -2996,20 +2990,11 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar max, bool path)
ssize_t len = strlen(home); ssize_t len = strlen(home);
ssize_t loclen = strlen(kvarr[r].val); ssize_t loclen = strlen(kvarr[r].val);
if (!buf) { xstrlcpy(g_buf, home, len + 1);
buf = (char *)malloc(len + loclen); xstrlcpy(g_buf + len, kvarr[r].val + 1, loclen);
if (!buf) {
DPRINTF_S(strerror(errno));
return NULL;
}
}
xstrlcpy(buf, home, len + 1);
xstrlcpy(buf + len, kvarr[r].val + 1, loclen);
return buf;
} }
return realpath(kvarr[r].val, buf); return realpath(((kvarr[r].val[0] == '~') ? g_buf : kvarr[r].val), buf);
} }
} }