Skip to content

Commit 333509b

Browse files
committed
better unicode support
1 parent c269c39 commit 333509b

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

docs/Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
1010

1111
### Version ++3.11a (dev)
1212
- afl-cc
13-
- fixed for a crash that can occur with ASAN + CMPLOG together
13+
- fixed for a crash that can occur with ASAN + CMPLOG together plus
14+
better support for unicode (thanks to @stbergmann for reporting!)
1415

1516
### Version ++3.10c (release)
1617
- Mac OS ARM64 support

instrumentation/SanitizerCoverageLTO.so.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,17 +872,21 @@ bool ModuleSanitizerCoverage::instrumentModule(
872872
// was not already added
873873
if (!isMemcmp) {
874874

875-
if (addedNull == false) {
875+
if (addedNull == false && thestring[optLen - 1] != '\0') {
876876

877877
thestring.append("\0", 1); // add null byte
878878
optLen++;
879879

880880
}
881881

882-
// ensure we do not have garbage
883-
size_t offset = thestring.find('\0', 0);
884-
if (offset + 1 < optLen) optLen = offset + 1;
885-
thestring = thestring.substr(0, optLen);
882+
if (!isStdString) {
883+
884+
// ensure we do not have garbage
885+
size_t offset = thestring.find('\0', 0);
886+
if (offset + 1 < optLen) optLen = offset + 1;
887+
thestring = thestring.substr(0, optLen);
888+
889+
}
886890

887891
}
888892

instrumentation/afl-llvm-dict2file.so.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,21 @@ bool AFLdict2filePass::runOnModule(Module &M) {
543543
// was not already added
544544
if (!isMemcmp) {
545545

546-
if (addedNull == false) {
546+
if (addedNull == false && thestring[optLen - 1] != '\0') {
547547

548548
thestring.append("\0", 1); // add null byte
549549
optLen++;
550550

551551
}
552552

553-
// ensure we do not have garbage
554-
size_t offset = thestring.find('\0', 0);
555-
if (offset + 1 < optLen) optLen = offset + 1;
556-
thestring = thestring.substr(0, optLen);
553+
if (!isStdString) {
554+
555+
// ensure we do not have garbage
556+
size_t offset = thestring.find('\0', 0);
557+
if (offset + 1 < optLen) optLen = offset + 1;
558+
thestring = thestring.substr(0, optLen);
559+
560+
}
557561

558562
}
559563

instrumentation/afl-llvm-lto-instrumentation.so.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,17 +658,21 @@ bool AFLLTOPass::runOnModule(Module &M) {
658658
// was not already added
659659
if (!isMemcmp) {
660660

661-
if (addedNull == false) {
661+
if (addedNull == false && thestring[optLen - 1] != '\0') {
662662

663663
thestring.append("\0", 1); // add null byte
664664
optLen++;
665665

666666
}
667667

668-
// ensure we do not have garbage
669-
size_t offset = thestring.find('\0', 0);
670-
if (offset + 1 < optLen) optLen = offset + 1;
671-
thestring = thestring.substr(0, optLen);
668+
if (!isStdString) {
669+
670+
// ensure we do not have garbage
671+
size_t offset = thestring.find('\0', 0);
672+
if (offset + 1 < optLen) optLen = offset + 1;
673+
thestring = thestring.substr(0, optLen);
674+
675+
}
672676

673677
}
674678

instrumentation/compare-transform-pass.so.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,21 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
421421
}
422422

423423
// add null termination character implicit in c strings
424-
TmpConstStr.append("\0", 1);
424+
if (TmpConstStr[TmpConstStr.length() - 1] != 0) {
425+
426+
TmpConstStr.append("\0", 1);
427+
428+
}
425429

426430
// in the unusual case the const str has embedded null
427431
// characters, the string comparison functions should terminate
428432
// at the first null
429-
if (!isMemcmp)
433+
if (!isMemcmp) {
434+
430435
TmpConstStr.assign(TmpConstStr, 0, TmpConstStr.find('\0') + 1);
431436

437+
}
438+
432439
constStrLen = TmpConstStr.length();
433440
// prefer use of StringRef (in comparison to std::string a StringRef has
434441
// built-in runtime bounds checking, which makes debugging easier)

0 commit comments

Comments
 (0)