mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-01 08:55:34 +00:00
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 <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
fa914675d2
commit
a20f0c820f
1 changed files with 12 additions and 3 deletions
|
@ -50,8 +50,11 @@ static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
|
||||||
return ret;
|
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)
|
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)
|
if (len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strcpy(s_name, filename);
|
strncpy(s_name, filename, VFAT_MAXLEN_BYTES - 1);
|
||||||
|
s_name[VFAT_MAXLEN_BYTES - 1] = '\0';
|
||||||
uppercase(s_name, len);
|
uppercase(s_name, len);
|
||||||
|
|
||||||
period = strchr(s_name, '.');
|
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);
|
memcpy(dirent->name, s_name, period_location);
|
||||||
} else {
|
} else {
|
||||||
memcpy(dirent->name, s_name, 6);
|
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[6] = '~';
|
||||||
dirent->name[7] = '1';
|
dirent->name[7] = '1';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue