forked from len0rd/rockbox
fileop: check dst path length during pre-scan
Use the known difference in path length between src and dst in order to detect an insufficient buffer size not just for the source, but also for the destination path during the pre-scan already. Change-Id: I9e4caeb9b9d2cb1e9577f418f2b777ab17718acf
This commit is contained in:
parent
48400b6ec1
commit
ce417b3e1b
1 changed files with 7 additions and 1 deletions
|
|
@ -51,6 +51,7 @@ struct file_op_params
|
||||||
unsigned long long total_size;
|
unsigned long long total_size;
|
||||||
unsigned long long processed_size;
|
unsigned long long processed_size;
|
||||||
size_t append; /* Append position in 'path' for stack push */
|
size_t append; /* Append position in 'path' for stack push */
|
||||||
|
size_t extra_len; /* Length added by dst path compared to src */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int prompt_name(char* buf, size_t bufsz)
|
static int prompt_name(char* buf, size_t bufsz)
|
||||||
|
|
@ -131,6 +132,7 @@ static void init_file_op(struct file_op_params *param,
|
||||||
param->toplevel_name = selected_file;
|
param->toplevel_name = selected_file;
|
||||||
}
|
}
|
||||||
param->is_dir = dir_exists(param->path);
|
param->is_dir = dir_exists(param->path);
|
||||||
|
param->extra_len = 0;
|
||||||
param->objects = 0; /* how many files and subdirectories*/
|
param->objects = 0; /* how many files and subdirectories*/
|
||||||
param->processed = 0;
|
param->processed = 0;
|
||||||
param->total_size = 0;
|
param->total_size = 0;
|
||||||
|
|
@ -209,7 +211,7 @@ static int directory_fileop(struct file_op_params *param, enum file_op_current f
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param->append >= sizeof (param->path)) {
|
if (param->append + param->extra_len >= sizeof (param->path)) {
|
||||||
rc = FORC_PATH_TOO_LONG;
|
rc = FORC_PATH_TOO_LONG;
|
||||||
break; /* no space left in buffer */
|
break; /* no space left in buffer */
|
||||||
}
|
}
|
||||||
|
|
@ -523,6 +525,10 @@ int copy_move_fileobject(const char *src_path, const char *dst_path, unsigned in
|
||||||
/* Try renaming first */
|
/* Try renaming first */
|
||||||
rc = move_by_rename(&src, dst.path, &flags);
|
rc = move_by_rename(&src, dst.path, &flags);
|
||||||
if (rc < FORC_SUCCESS) {
|
if (rc < FORC_SUCCESS) {
|
||||||
|
int extra_len = dst.append - src.append;
|
||||||
|
if (extra_len > 0)
|
||||||
|
src.extra_len = extra_len;
|
||||||
|
|
||||||
rc = check_count_fileobjects(&src);
|
rc = check_count_fileobjects(&src);
|
||||||
if (rc == FORC_SUCCESS) {
|
if (rc == FORC_SUCCESS) {
|
||||||
rc = copy_move_directory(&src, &dst, flags);
|
rc = copy_move_directory(&src, &dst, flags);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue