Skip to content

Commit 30fb15c

Browse files
committed
Fix UB when validating spirv-ext option
When passing `spirv-ext=,`, SPVExt will contain empty strings. Calling `front` on an empty string is undefined behavior, so first ensure that the string is not empty.
1 parent 14b843b commit 30fb15c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/llvm-spirv/llvm-spirv.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ static int parseSPVExtOption(
484484

485485
for (unsigned i = 0; i < SPVExt.size(); ++i) {
486486
const std::string &ExtString = SPVExt[i];
487-
if ('+' != ExtString.front() && '-' != ExtString.front()) {
487+
if (ExtString.empty() ||
488+
('+' != ExtString.front() && '-' != ExtString.front())) {
488489
errs() << "Invalid value of --spirv-ext, expected format is:\n"
489490
<< "\t--spirv-ext=+EXT_NAME,-EXT_NAME\n";
490491
return -1;

0 commit comments

Comments
 (0)