Safer use of basename()

This commit is contained in:
Pierre Pronchery 2007-12-13 00:12:22 +00:00
parent 247a2c39a5
commit 9fa0e397ee
2 changed files with 13 additions and 6 deletions

View File

@ -389,7 +389,7 @@ static int _copy_multiple(Copy * copy, char const * src, char const * dst)
char * q;
if((p = strdup(src)) == NULL)
return 1;
return _copy_error(copy, src, 1);
to = basename(p);
len = strlen(src + strlen(to) + 2);
if((q = malloc(len * sizeof(char))) == NULL)

View File

@ -389,14 +389,21 @@ static int _move_multiple(Move * move, char const * src, char const * dst)
char * to;
size_t len;
char * p;
char * q;
to = basename(src); /* XXX src is const */
len = strlen(src + strlen(to) + 2);
if((p = malloc(len * sizeof(char))) == NULL)
if((p = strdup(src)) == NULL)
return _move_error(move, src, 1);
sprintf(p, "%s/%s", dst, to);
ret = _move_single(move, src, p);
to = basename(p);
len = strlen(src + strlen(to) + 2);
if((q = malloc(len * sizeof(char))) == NULL)
{
free(p);
return _move_error(move, src, 1);
}
sprintf(q, "%s/%s", dst, to);
ret = _move_single(move, src, q);
free(p);
free(q);
return ret;
}