Skip to content

Commit

Permalink
Set pattern ID type in AhoCorasickPlus::addPattern
Browse files Browse the repository at this point in the history
Else there's potential for invalid memory accesses, e.g. if the memory
for pattern ID type happens to be equal to the "string" ID type and then
it accesses the associated union field which hasn't been initialized.
  • Loading branch information
jsiwek committed Jan 8, 2020
1 parent ee79325 commit ac86ce7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ahocorasick/AhoCorasickPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
along with multifast. If not, see <http://www.gnu.org/licenses/>.
* Modified by Jon Siwek: add "copy" flag to addPattern() methods
* Modified by Jon Siwek: fix addPattern() to set pattern ID type to "number"
*/

#include "ahocorasick.h"
Expand Down Expand Up @@ -48,6 +49,7 @@ AhoCorasickPlus::EnumReturnStatus AhoCorasickPlus::addPattern
patt.ptext.astring = (AC_ALPHABET_t*) pattern.data();
patt.ptext.length = pattern.size();
patt.id.u.number = id;
patt.id.type = AC_PATTID_TYPE_NUMBER;
patt.rtext.astring = NULL;
patt.rtext.length = 0;

Expand Down

0 comments on commit ac86ce7

Please sign in to comment.