Safer use of basename()
This commit is contained in:
parent
247a2c39a5
commit
9fa0e397ee
|
@ -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)
|
||||
|
|
17
src/move.c
17
src/move.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user