Fixing the test-suite broken after r246877
Steven Wu via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 23:25:21 PDT 2015
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.
Thanks
Steven
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-the-undefined-behavior-in-MiBench.patch
Type: application/octet-stream
Size: 2108 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150904/8dbbf5a4/attachment.obj>
-------------- next part --------------
From 7151bf31954c9d0680e4bb592dbc130d0234650b Mon Sep 17 00:00:00 2001
From: Steven Wu <stevenwu at apple.com>
Date: Fri, 4 Sep 2015 23:15:21 -0700
Subject: [PATCH] Fix the undefined behavior in MiBench
The undefined behavior is causing runtime failure after r246877.
Fix consumer-lane by replacing strcpy with direct assignment to avoid
buffer overflow. consumer-typeset is intentionally overflowing buffer so
use memcpy instead of strcpy.
---
MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c | 2 +-
MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c b/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c
index e24a966..23f2b86 100644
--- a/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c
+++ b/MultiSource/Benchmarks/MiBench/consumer-lame/id3tag.c
@@ -34,7 +34,7 @@ void id3_inittag(ID3TAGDATA *tag) {
strcpy( tag->album, "");
strcpy( tag->year, "");
strcpy( tag->comment, "");
- strcpy( tag->genre, "ˇ"); /* unset genre */
+ tag->genre[0] = 'ˇ'; /* unset genre */
tag->track = 0;
tag->valid = 0; /* not ready for writing*/
diff --git a/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h b/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h
index 7e050bd..a14e8ee 100644
--- a/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h
+++ b/MultiSource/Benchmarks/MiBench/consumer-typeset/externs.h
@@ -3266,7 +3266,8 @@ extern int strcollcmp(char *a, char *b);
( UseCollate ? strcollcmp((char *)(a),(char *)(b)) <= 0 \
: strcmp((char *)(a),(char *)(b)) <= 0 )
#define StringCat(a, b) strcat((char *)(a),(char *)(b))
-#define StringCopy(a, b) strcpy((char *)(a),(char *)(b))
+#define StringCopy(a, b) (char*)memcpy((void *)(a),(void *)(b), \
+ strlen((char*)(b)) + 1)
#define StringLength(a) strlen((char *)(a))
#define StringFOpen(a, b) fopen( (char *) (a), (b) )
#define StringFPuts(a, b) fputs( (char *) (a), (b) )
--
2.3.8 (Apple Git-58)
More information about the llvm-commits
mailing list