<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62893>62893</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [scudo] incorrect ScopedString::append overload picked up on several platforms, leading to crashes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          q66
      </td>
    </tr>
</table>

<pre>
    The `ScopedString::append` method has two overloads:

```
void append(const char *Format, va_list Args);
void append(const char *Format, ...) FORMAT(2, 3);
```

On some platforms, `va_list` is typedef'd to `char *` (while on others it's some opaque object etc., the actual definition is not clear). On those platforms, when you call `.append("formatstring", x)` with `x` being a `char *` or a string constant, it the `va_list` overload will get picked up, in case of string constants with this warning:

```
./tests/strings_test.cpp:66:22: warning: ISO C++ forbids converting a string constant to 'va_list' {aka 'char*'} [-Wwrite-strings]
```

This crashes at least some tests (known on 32-bit x86 and on ppc64le with musl at very least), and may possibly (but I'm not 100% sure) crash the allocator when logging.

Disambiguating this by making the `va_list` variant a non-overload fixes the problem.

Patch:

```
>From f2f90378d4a2c1f744c85d327c67ae8e862fdc7f Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Tue, 23 May 2023 21:09:55 +0200
Subject: [PATCH] disambiguate ScopedString::append

On some targets, the definition of va_list may result in a wrong
overload of append getting picked up when passing a single string
as a variadic argument.
---
 lib/scudo/standalone/report.cpp       | 2 +-
 lib/scudo/standalone/string_utils.cpp | 6 +++---
 lib/scudo/standalone/string_utils.h   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/scudo/standalone/report.cpp b/lib/scudo/standalone/report.cpp
index a37faac..9cb70ad 100644
--- a/lib/scudo/standalone/report.cpp
+++ b/lib/scudo/standalone/report.cpp
@@ -21,7 +21,7 @@ public:
   void append(const char *Format, ...) {
     va_list Args;
 va_start(Args, Format);
-    Message.append(Format, Args);
+ Message.vappend(Format, Args);
     va_end(Args);
   }
   NORETURN ~ScopedErrorReport() {
diff --git a/lib/scudo/standalone/string_utils.cpp b/lib/scudo/standalone/string_utils.cpp
index 13fdb9c..3d921ba 100644
--- a/lib/scudo/standalone/string_utils.cpp
+++ b/lib/scudo/standalone/string_utils.cpp
@@ -218,7 +218,7 @@ int formatString(char *Buffer, uptr BufferLength, const char *Format, ...) {
 return Res;
 }
 
-void ScopedString::append(const char *Format, va_list Args) {
+void ScopedString::vappend(const char *Format, va_list Args) {
   va_list ArgsCopy;
   va_copy(ArgsCopy, Args);
   // formatString doesn't currently support a null buffer or zero buffer length,
@@ -239,7 +239,7 @@ void ScopedString::append(const char *Format, va_list Args) {
 void ScopedString::append(const char *Format, ...) {
 va_list Args;
   va_start(Args, Format);
-  append(Format, Args);
+ vappend(Format, Args);
   va_end(Args);
 }
 
@@ -247,7 +247,7 @@ void Printf(const char *Format, ...) {
   va_list Args;
 va_start(Args, Format);
   ScopedString Msg;
-  Msg.append(Format, Args);
+  Msg.vappend(Format, Args);
   outputRaw(Msg.data());
 va_end(Args);
 }
diff --git a/lib/scudo/standalone/string_utils.h b/lib/scudo/standalone/string_utils.h
index 4190119..a4cab52 100644
--- a/lib/scudo/standalone/string_utils.h
+++ b/lib/scudo/standalone/string_utils.h
@@ -25,7 +25,7 @@ public:
 String.clear();
     String.push_back('\0');
   }
-  void append(const char *Format, va_list Args);
+  void vappend(const char *Format, va_list Args);
   void append(const char *Format, ...) FORMAT(2, 3);
   void output() const { outputRaw(String.data()); }
   void reserve(size_t Size) { String.reserve(Size + 1); }
-- 
2.39.0
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWEtz2zrS_TXwpkssChQfWmghyVF9t77xTcr21CxdINkkMYYAXgCUrCzmt08BJPWKnZGTm0rJJNhoNE6fPngwY3gtERckXpH4_o51tlF68VeS3OWqPCyeGwSShE-FarF8sprLmkRLEi1Z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