fs: fat_write: fix short name creation.
PATCH 1/1 fs: fat_write: fix short name creation.
Truncate file names if the buffer size is exceeded to avoid a buffer overflow.
Use Sphinx style function description.
Add a TODO comment.
Reported-by CID 303779
Signed-off-by Heinrich Schuchardt <[email protected]>
--- fs/fat/fat_write.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/fat/fat_write.c +12 -3
@@ -50,8 +50,11 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)return ret; } -/* -* Set short name in directory entry +/** +* set_name() - set short name in directory entry +* +* @dirent: directory entry +* @filename: long file name */ static void set_name (dir_entry *dirent,const char *filename) {
@@ -66,7 +69,8 @@ static void set_name(dir_entry *dirent, const char *filename)if (len ==0 )return ; -strcpy (s_name, filename); +strncpy (s_name, filename,VFAT_MAXLEN_BYTES -1 ); + s_name[VFAT_MAXLEN_BYTES -1 ] ='\0' ;uppercase (s_name, len); period =strchr (s_name,'.' );
@@ -87,6 +91,11 @@ static void set_name(dir_entry *dirent, const char *filename)memcpy (dirent->name, s_name, period_location); }else {memcpy (dirent->name, s_name,6 ); +/* +* TODO: Translating two long names with the same first six +* characters to the same short name is utterly wrong. +* Short names must be unique. +*/ dirent->name[6 ] ='~' ; dirent->name[7 ] ='1' ; }
--
2.26.2
PATCH 1/1 fs: fat_write: fix short name creation.
Hi Heinrich,
Quoted 6 lines · Heinrich Schuchardt
Truncate file names if the buffer size is exceeded to avoid a buffer overflow.
Use Sphinx style function description.
Quoted 7 lines
Add a TODO comment.
Reported-by CID 303779Signed-off-by Heinrich Schuchardt <[email protected]>--- fs/fat/fat_write.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
Reviewed-by Simon Glass <[email protected]>
See below
Quoted 20 lines
fs/fat/fat_write.c +5
-2@@ -50,8 +50,11 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)return ret; } -/* -* Set short name in directory entry +/** +* set_name() - set short name in directory entry +* +* @dirent: directory entry +* @filename: long file name */ static void set_name (dir_entry *dirent,const char *filename) {
fs/fat/fat_write.c static void set_name(dir_entry *dirent, const char *filename) · line 73
Quoted 6 lines
fs/fat/fat_write.c +2
-1@@ -66,7 +69,8 @@ static void set_name(dir_entry *dirent, const char *filename)if (len ==0 )return ; -strcpy (s_name, filename); +strncpy (s_name, filename,VFAT_MAXLEN_BYTES -1 ); + s_name[VFAT_MAXLEN_BYTES -1 ] ='\0' ;
Could use strlcpy() here
Quoted 16 lines
fs/fat/fat_write.c +5
-1uppercase (s_name, len); period =strchr (s_name,'.' );@@ -87,6 +91,11 @@ static void set_name(dir_entry *dirent, const char *filename)memcpy (dirent->name, s_name, period_location); }else {memcpy (dirent->name, s_name,6 ); +/* +* TODO: Translating two long names with the same first six +* characters to the same short name is utterly wrong. +* Short names must be unique. +*/ dirent->name[6 ] ='~' ; dirent->name[7 ] ='1' ; } --
Quoted 2 lines
2.26.2
Regards,
Simon
PATCH 1/1 fs: fat_write: fix short name creation.
In reply to Heinrich SchuchardtQuoted 10 lines · Heinrich Schuchardt
Truncate file names if the buffer size is exceeded to avoid a buffer overflow.
Use Sphinx style function description.
Add a TODO comment.
Reported-by CID 303779Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200707/0b0b54e6/attachment.sig>