[binutils-gdb] Fix a potential problem in the BFD library when accessing the Windows' nul device driver.

Nick Clifton nickc@sourceware.org
Tue Jan 3 12:08:31 GMT 2023


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a8cf07d37b0063df888da82aed00babd1907ab7e

commit a8cf07d37b0063df888da82aed00babd1907ab7e
Author: Himal <himalr@proton.me>
Date:   Tue Jan 3 12:07:16 2023 +0000

    Fix a potential problem in the BFD library when accessing the Windows' nul device driver.
    
            PR 29947
            * bfdio.c (_bfd_real_fopen): Do not add a prefix to the Windows'
            nul device filename.

Diff:
---
 bfd/ChangeLog | 6 ++++++
 bfd/bfdio.c   | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a7d9845247a..91a73aca5e8 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2023-01-03  Himal  <himalr@proton.me>
+
+	PR 29947
+	* bfdio.c (_bfd_real_fopen): Do not add a prefix to the Windows'
+	nul device filename.
+
 2023-01-03  Nick Clifton  <nickc@redhat.com>
 
 	* po/fr.po: Updated French trabslation.
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index e9fa5bb012c..337d4a10b66 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -154,6 +154,11 @@ _bfd_real_fopen (const char *filename, const char *modes)
    wcscpy (fullPath, prefix);
 
    int        prefixLen = sizeof(prefix) / sizeof(wchar_t);
+
+   /* Do not add a prefix to the null device.  */
+   if (stricmp (filename, "nul") == 0)
+    prefixLen = 1;
+
    wchar_t *  fullPathOffset = fullPath + prefixLen - 1;
 
    GetFullPathNameW (partPath, fullPathWSize, fullPathOffset, lpFilePart);


More information about the Binutils-cvs mailing list