[PATCH] Fix the error in determining the range of file name length

jiaying.song.cn@windriver.com jiaying.song.cn@windriver.com
Fri Sep 13 03:19:15 GMT 2024


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



More information about the Binutils mailing list