This is an archive of the discontinued LLVM Phabricator instance.

[Support/GlobPattern] - Do not crash when pattern has characters with int value < 0.
ClosedPublic

Authored by grimar on Jul 26 2017, 8:06 AM.

Details

Summary

Found it during work on LLD, it would crash on following
linker script:

SECTIONS { .foo : { *("*®") } }

That happens because ® has int value -82. And chars are used as
array index in code, and are signed by default.

Diff Detail

Event Timeline

grimar created this revision.Jul 26 2017, 8:06 AM
grimar planned changes to this revision.Jul 26 2017, 8:14 AM
grimar updated this revision to Diff 108284.Jul 26 2017, 8:17 AM
  • Use character literals in testcase.
grimar updated this revision to Diff 108285.Jul 26 2017, 8:19 AM
  • Uploaded correct diff. Sorry for noise.
ruiu added inline comments.Jul 26 2017, 10:16 AM
lib/Support/GlobPattern.cpp
41

Instead of casting to uint8_t, cast to unsigned.

grimar added inline comments.Jul 27 2017, 1:04 AM
lib/Support/GlobPattern.cpp
41

That will not work:

(unsigned)0xFF == 0xFFFFFFFF == 4294967295
(uint8_t)0xFF == 255
grimar added inline comments.Jul 27 2017, 1:07 AM
lib/Support/GlobPattern.cpp
41

I was mean

(unsigned)(char)0xFF == 4294967295
ruiu added inline comments.Jul 27 2017, 1:57 PM
lib/Support/GlobPattern.cpp
38

Add these line before this line to remove all these casts.

uint8_t Start = S[0];
uint8_t End = S[2];
grimar updated this revision to Diff 108602.Jul 28 2017, 1:48 AM
  • Addressed review comments.
ruiu accepted this revision.Jul 28 2017, 10:41 AM

LGTM

lib/Support/GlobPattern.cpp
38

Add a blank line.

This revision is now accepted and ready to land.Jul 28 2017, 10:41 AM
This revision was automatically updated to reflect the committed changes.