[PATCH] Fix the error in determining the range of file name length
Song, Jiaying (CN)
Jiaying.Song.CN@windriver.com
Fri Sep 13 03:41:41 GMT 2024
Hi Martin, Alan, and team,
Thank you for your attention to this issue. Based on recent tests, it appears that the check (strlen(input) + 2) > NAME_MAX in the code is incorrect because it does not leave sufficient buffer space. This is because, in addition to the tmp_prefix generated by appending an "_" symbol to input, the temporary files also have a suffix s00000.o. Consequently, the final filename adds 9 extra bytes to the input.
Given this, the conditional statement should be updated to if ((strlen(input) + 20) > NAME_MAX). However, I am unsure if the 20-byte margin is adequate and would appreciate your feedback on this.
Here are the specifics from the tests:
* Input length in bytes: 247
* Input content: /buildarea1/jsong3/fkewjfnweqdfaewklfnewkfjwkllllllllllkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkwefwefewwkeifewnfiejinelsinelskndiemojief/libqemu_plugin_api.a
* Final tmp_prefix: buildarea1_jsong3_fkewjfnweqdfaewklfnewkfjwkllllllllllkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkwefwefewwkeifewnfiejinelsinelskndiemojief_libqemu_plugin_api_a
* Length of tmp_prefix: 248
Error encountered: /buildarea1/jsong3/LTS24/testlongfilenametestlongfilenametestlongfilenametestlongfilenametestlongfilenametestlongfilenametestlongfilenametestlongfilenametestlongfilenametestlong/tmp-glibc/work/i686-nativesdk-mingw32-w64-mingw32/nativesdk-qemu/8.2.3/recipe-sysroot-native/usr/bin/i686-w64-mingw32/i686-w64-mingw32-dlltool: bfd_open failed open stub file: _buildarea1_jsong3_fkewjfnweqdfaewklfnewkfjwkllllllllllkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkwefwefewwkeifewnfiejinelsinelskndiemojief_libqemu_plugin_api_a_s00000.o: File name too long
Thank you for your assistance and feedback.
Best regards,
Jiaying.
________________________________
From: jiaying.song.cn@windriver.com <jiaying.song.cn@windriver.com>
Sent: Friday, September 13, 2024 11:19
To: binutils@sourceware.org <binutils@sourceware.org>
Cc: Li, Changqing <Changqing.Li@windriver.com>; Song, Jiaying (CN) <Jiaying.Song.CN@windriver.com>
Subject: [PATCH] Fix the error in determining the range of file name length
From: Jiaying Song <jiaying.song.cn@windriver.com>
The check condition `(strlen(input) + 2) > NAME_MAX` in the code is
incorrect because it does not leave enough buffer space. This is
because, in addition to the `tmp_prefix` generated by appending an "_"
symbol to the `input`, the generated temporary files also have a suffix
of `s00000.o`. Therefore, the final filename adds 9 extra bytes to the
`input`. To ensure adequate space, the conditional statement should be
changed to `if ((strlen(input) + 20) > NAME_MAX)`.
Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
---
binutils/dlltool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/binutils/dlltool.c b/binutils/dlltool.c
index 6dc16a9ed84..7aa2435b052 100644
--- a/binutils/dlltool.c
+++ b/binutils/dlltool.c
@@ -4069,7 +4069,7 @@ main (int ac, char **av)
{
/* If possible use a deterministic prefix. */
const char *input = imp_name ? imp_name : delayimp_name;
- if (input && strlen (input) + 2 <= NAME_MAX)
+ if (input && strlen (input) + 20 <= NAME_MAX)
{
tmp_prefix = xmalloc (strlen (input) + 2);
sprintf (tmp_prefix, "%s_", input);
--
2.25.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20240913/752b68b9/attachment-0001.htm>
More information about the Binutils
mailing list