summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-08-05 20:45:40 +0200
committerChristian Soffke <christian.soffke@gmail.com>2024-08-11 19:32:55 +0200
commitce417b3e1bea6a18889965bafee4094d4dd3e083 (patch)
treec3da0e8cc8e79a198da72dab7183e3c5e76cf59f
parent48400b6ec112118b69123d2374a3bb7d8df78f89 (diff)
downloadrockbox-ce417b3e1b.tar.gz
rockbox-ce417b3e1b.zip
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
-rw-r--r--apps/fileop.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/apps/fileop.c b/apps/fileop.c
index 1aaee3bb64..65a3b37e0a 100644
--- a/apps/fileop.c
+++ b/apps/fileop.c
@@ -51,6 +51,7 @@ struct file_op_params
unsigned long long total_size;
unsigned long long processed_size;
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)
@@ -131,6 +132,7 @@ static void init_file_op(struct file_op_params *param,
param->toplevel_name = selected_file;
}
param->is_dir = dir_exists(param->path);
+ param->extra_len = 0;
param->objects = 0; /* how many files and subdirectories*/
param->processed = 0;
param->total_size = 0;
@@ -209,7 +211,7 @@ static int directory_fileop(struct file_op_params *param, enum file_op_current f
break;
}
- if (param->append >= sizeof (param->path)) {
+ if (param->append + param->extra_len >= sizeof (param->path)) {
rc = FORC_PATH_TOO_LONG;
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 */
rc = move_by_rename(&src, dst.path, &flags);
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);
if (rc == FORC_SUCCESS) {
rc = copy_move_directory(&src, &dst, flags);