<div dir="ltr"><div>Thanks for catching this!</div><div><br></div>I'm not familiar with at all with test-suite, so someone else may be better suited to review your patch. That being said:<div><br></div><div>id3tag.c -- LGTM</div><div><br></div><div>externs.c -- Did some investigating. This code is rather different than what I'm used to. :)</div><div><br></div><div>From the compiler's perspective: string(OBJECT) returns a pointer to a 4-char array inside of OBJECT. We try to copy a 119-byte string (file path) into this. memcpy() works here because Apple uses __builtin_object_size(p, 0) for memcpy, and __builtin_object_size(p, 1) (sometimes 0) for strcpy; the former has no clue what size OBJECT is, so it fails, while the latter says "hey, this field is clearly 4 bytes," causing FORTIFY to kill the program when we try to copy more than that. (relevant header: <a href="http://opensource.apple.com/source/Libc/Libc-1044.10.1/include/secure/_string.h">http://opensource.apple.com/source/Libc/Libc-1044.10.1/include/secure/_string.h</a> )</div><div><br></div><div>From the program's perspective at runtime, OBJECT points to a non-constant sized malloc. NewWord guarantees that *OBJECT has sufficient space to store the entire string. The types lie.</div><div><br></div><div>In light of this, if we could add a comment to the new StringCopy definition that reads something like: "Types lie at some points in this program, and FORTIFY implementations rely on types. Using memcpy instead of strcpy here makes some FORTIFY impls permissive enough that they won't crash us when we're doing tricky (but still correct) things," that may be best. :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 4, 2015 at 11:25 PM, Steven Wu <span dir="ltr"><<a href="mailto:stevenwu@apple.com" target="_blank">stevenwu@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">r246877 exposes some undefined behavior in LNT that cause the test to crash. Both consumer-lame and consumer-typeset has strcpy that overflow the buffer, one intentionally one maybe by accident. Here is my proposed way to fix the tests.<br>
<br>
Thanks<br>
<span class="HOEnZb"><font color="#888888"><br>
Steven<br>
<br>
</font></span><br><br>
<br>
>From 7151bf31954c9d0680e4bb592dbc130d0234650b Mon Sep 17 00:00:00 2001<br>
From: Steven Wu <<a href="mailto:stevenwu@apple.com">stevenwu@apple.com</a>><br>
Date: Fri, 4 Sep 2015 23:15:21 -0700<br>
Subject: [PATCH] Fix the undefined behavior in MiBench<br>
<br>
The undefined behavior is causing runtime failure after r246877.<br>
Fix consumer-lane by replacing strcpy with direct assignment to avoid<br>
buffer overflow. consumer-typeset is intentionally overflowing buffer so<br>
use memcpy instead of strcpy.<br>
---<br>
 MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c     | 2 +-<br>
 MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h | 3 ++-<br>
 2 files changed, 3 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c b/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c<br>
index e24a966..23f2b86 100644<br>
--- a/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c<br>
+++ b/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c<br>
@@ -34,7 +34,7 @@ void id3_inittag(ID3TAGDATA *tag) {<br>
        strcpy( tag->album, "");<br>
        strcpy( tag->year, "");<br>
        strcpy( tag->comment, "");<br>
-       strcpy( tag->genre, "ˇ");       /* unset genre */<br>
+       tag->genre[0] = 'ˇ';    /* unset genre */<br>
        tag->track = 0;<br>
<br>
        tag->valid = 0;         /* not ready for writing*/<br>
diff --git a/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h b/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h<br>
index 7e050bd..a14e8ee 100644<br>
--- a/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h<br>
+++ b/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h<br>
@@ -3266,7 +3266,8 @@ extern int          strcollcmp(char *a, char *b);<br>
                    ( UseCollate ? strcollcmp((char *)(a),(char *)(b)) <= 0 \<br>
                                 : strcmp((char *)(a),(char *)(b)) <= 0 )<br>
 #define                  StringCat(a, b)       strcat((char *)(a),(char *)(b))<br>
-#define                  StringCopy(a, b)      strcpy((char *)(a),(char *)(b))<br>
+#define                  StringCopy(a, b)      (char*)memcpy((void *)(a),(void *)(b), \<br>
+                                             strlen((char*)(b)) + 1)<br>
 #define                  StringLength(a)       strlen((char *)(a))<br>
 #define                  StringFOpen(a, b)     fopen( (char *) (a), (b) )<br>
 #define                  StringFPuts(a, b)     fputs( (char *) (a), (b) )<br>
--<br>
2.3.8 (Apple Git-58)<br>
<br>
<br>
<br>
<br></blockquote></div><br></div>