xbps-bin: simplify sanitize_localpath().

--HG--
extra : convert_revision : 223334822b80c6b11e63f1a34e7bfadb9115d5b9
This commit is contained in:
Juan RP 2008-12-27 22:56:47 +01:00
parent 926b1dfa4a
commit e5774555cf
1 changed files with 8 additions and 9 deletions

View File

@ -130,6 +130,7 @@ static bool
sanitize_localpath(char *buf, const char *path) sanitize_localpath(char *buf, const char *path)
{ {
char *dirnp, *basenp, *dir, *base, *tmp; char *dirnp, *basenp, *dir, *base, *tmp;
bool rv = false;
dir = strdup(path); dir = strdup(path);
if (dir == NULL) if (dir == NULL)
@ -143,29 +144,27 @@ sanitize_localpath(char *buf, const char *path)
dirnp = dirname(dir); dirnp = dirname(dir);
if (strcmp(dirnp, ".") == 0) if (strcmp(dirnp, ".") == 0)
goto error; goto out;
basenp = basename(base); basenp = basename(base);
if (strcmp(basenp, base) == 0) if (strcmp(basenp, base) == 0)
goto error; goto out;
tmp = strncpy(buf, dirnp, PATH_MAX - 1); tmp = strncpy(buf, dirnp, PATH_MAX - 1);
if (sizeof(*tmp) >= PATH_MAX) if (sizeof(*tmp) >= PATH_MAX)
goto error; goto out;
buf[strlen(buf) + 1] = '\0'; buf[strlen(buf) + 1] = '\0';
if (strcmp(dirnp, "/")) if (strcmp(dirnp, "/"))
strncat(buf, "/", 1); strncat(buf, "/", 1);
strncat(buf, basenp, PATH_MAX - strlen(buf) - 1); strncat(buf, basenp, PATH_MAX - strlen(buf) - 1);
rv = true;
out:
free(dir); free(dir);
free(base); free(base);
return true; return rv;
error:
free(base);
free(dir);
return false;
} }
int int