[llvm] [llvm-libtool-darwin] Ensure filelist buffer is null-terminated (PR #205115)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 15 18:47:01 PDT 2026


https://github.com/stephenduong1004 updated https://github.com/llvm/llvm-project/pull/205115

>From 28cb68956eeaca055a83f8e3b83b043343df4da9 Mon Sep 17 00:00:00 2001
From: stephenduong1004 <stephenduong at google.com>
Date: Mon, 22 Jun 2026 10:47:03 -0400
Subject: [PATCH] [llvm-libtool-darwin] Ensure filelist buffer is
 null-terminated

[llvm-libtool-darwin] Ensure filelist buffer is null-terminated

In llvm-libtool-darwin.cpp, `MemoryBuffer::getFileOrSTDIN` was previously called to load the filelist with `RequiresNullTerminator` set to `false`.
However, the retrieved buffer is subsequently passed to `llvm::line_iterator`.

Since `llvm::line_iterator` explicitly requires its underlying buffer to be  null-terminated, omitting this requirement can result in an out-of-bounds read/buffer overrun when parsing the file list.

This change fixes the issue by requesting a null-terminated buffer (`RequiresNullTerminator=true`).
---
 llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index 4165274a6f8bd..40b10aae26f68 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -148,7 +148,7 @@ static Error processFileList() {
 
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
       MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/false,
-                                   /*RequiresNullTerminator=*/false);
+                                   /*RequiresNullTerminator=*/true);
   if (std::error_code EC = FileOrErr.getError())
     return createFileError(FileName, errorCodeToError(EC));
   const MemoryBuffer &Ref = *FileOrErr.get();



More information about the llvm-commits mailing list