]> git.ipfire.org Git - thirdparty/pdns.git/commit
auth: Prevent dereferencing std::string::end() in SimpleMatch
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Apr 2021 10:18:50 +0000 (12:18 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Apr 2021 10:18:50 +0000 (12:18 +0200)
commit17c752211f039e214d6b055e5f160dfff297b3ae
treea49a751d1ff6bbcd6c3926fdb43b736894720509
parent8116c813591fbcf25d6cd922bc5acc1ac37204ef
auth: Prevent dereferencing std::string::end() in SimpleMatch

SimpleMatch is called with user-supplied strings in the API and the
bind backend. We might get away with it in most cases because
std::strings are null-terminated, but it's still undefined behaviour
as there is no guarantee that end() will point to the terminator.

Reported by cppcheck 2.4.1:
```
misc.hh:501:16: warning: Either the condition 'mi==d_mask.end()' is redundant or there is possible dereference of an invalid iterator: mi. [derefInvalidIteratorRedundantCheck]
        while(*mi == '*') ++mi;
               ^
misc.hh:502:16: note: Assuming that condition 'mi==d_mask.end()' is not redundant
        if (mi == d_mask.end()) return true;
               ^
misc.hh:501:16: note: Dereference of an invalid iterator
        while(*mi == '*') ++mi;
```
pdns/misc.hh