Skip to content

Commit

Permalink
Merge branch 'github_develop' into github_master
Browse files Browse the repository at this point in the history
  • Loading branch information
fatchanghao committed Feb 21, 2023
2 parents 64a995b + f815639 commit c37166d
Show file tree
Hide file tree
Showing 46 changed files with 244 additions and 94 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

This is a list of notable changes to Hyperscan, in reverse chronological order.

## [5.4.1] 2023-02-20
- The Intel Hyperscan team is pleased to provide a bug fix release to our open source library.
Intel also maintains an upgraded version available through your Intel sales representative.
- Bugfix for issue #184: fix random char value of UTF-8.
- Bugfix for issue #291: bypass logical combination flag in hs_expression_info().
- Bugfix for issue #292: fix build error due to libc symbol parsing.
- Bugfix for issue #302/304: add empty string check for pure literal API.
- Bugfix for issue #303: fix unknown instruction error in pure literal API.
- Bugfix for issue #303: avoid memory leak in stream close stage.
- Bugfix for issue #305: fix assertion failure in DFA construction.
- Bugfix for issue #317: fix aligned allocator segment faults.
- Bugfix for issue #350: add quick validity check for scratch.
- Bugfix for issue #359: fix glibc-2.34 stack size issue.
- Bugfix for issue #360: fix SKIP flag issue in chimera.
- Bugfix for issue #362: fix one cotec check corner issue in UTF-8 validation.
- Fix other compile issues.

## [5.4.0] 2020-12-31
- Improvement on literal matcher "Fat Teddy" performance, including
support for Intel(R) AVX-512 Vector Byte Manipulation Instructions (Intel(R)
Expand Down
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project (hyperscan C CXX)

set (HS_MAJOR_VERSION 5)
set (HS_MINOR_VERSION 4)
set (HS_PATCH_VERSION 0)
set (HS_PATCH_VERSION 1)
set (HS_VERSION ${HS_MAJOR_VERSION}.${HS_MINOR_VERSION}.${HS_PATCH_VERSION})

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
Expand Down Expand Up @@ -397,6 +397,18 @@ if (CXX_UNUSED_CONST_VAR)
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-unused-const-variable")
endif()

# clang-14 complains about unused-but-set variable.
CHECK_CXX_COMPILER_FLAG("-Wunused-but-set-variable" CXX_UNUSED_BUT_SET_VAR)
if (CXX_UNUSED_BUT_SET_VAR)
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-unused-but-set-variable")
endif()

# clang-14 complains about using bitwise operator instead of logical ones.
CHECK_CXX_COMPILER_FLAG("-Wbitwise-instead-of-logical" CXX_BITWISE_INSTEAD_OF_LOGICAL)
if (CXX_BITWISE_INSTEAD_OF_LOGICAL)
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-bitwise-instead-of-logical")
endif()

# gcc 6 complains about type attributes that get ignored, like alignment
CHECK_CXX_COMPILER_FLAG("-Wignored-attributes" CXX_IGNORED_ATTR)
if (CXX_IGNORED_ATTR)
Expand Down Expand Up @@ -428,8 +440,10 @@ CHECK_CXX_COMPILER_FLAG("-Wunused-variable" CXX_WUNUSED_VARIABLE)

# gcc 10 complains about this
CHECK_C_COMPILER_FLAG("-Wstringop-overflow" CC_STRINGOP_OVERFLOW)
if(CC_STRINGOP_OVERFLOW)
CHECK_CXX_COMPILER_FLAG("-Wstringop-overflow" CXX_STRINGOP_OVERFLOW)
if(CC_STRINGOP_OVERFLOW OR CXX_STRINGOP_OVERFLOW)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-stringop-overflow")
set(EXTRA_CXX_FLAGS "${EXTRA_CXX_FLAGS} -Wno-stringop-overflow")
endif()

endif()
Expand Down Expand Up @@ -579,7 +593,7 @@ set (hs_exec_common_SRCS

set (hs_exec_SRCS
${hs_HEADERS}
src/hs_version.h
src/hs_version.h.in
src/ue2common.h
src/allocator.h
src/crc32.c
Expand Down Expand Up @@ -736,7 +750,7 @@ SET (hs_compile_SRCS
src/grey.h
src/hs.cpp
src/hs_internal.h
src/hs_version.h
src/hs_version.h.in
src/scratch.h
src/state.h
src/ue2common.h
Expand Down
6 changes: 5 additions & 1 deletion chimera/ch_runtime.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Intel Corporation
* Copyright (c) 2018-2022, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -326,6 +326,10 @@ ch_error_t catchupPcre(struct HybridContext *hyctx, unsigned int id,
} else if (cbrv == CH_CALLBACK_SKIP_PATTERN) {
DEBUG_PRINTF("user callback told us to skip this pattern\n");
pd->scanStart = hyctx->length;
if (top_id == id) {
break;
}
continue;
}

if (top_id == id) {
Expand Down
2 changes: 1 addition & 1 deletion cmake/build_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ KEEPSYMS=$(mktemp -p /tmp keep.syms.XXXXX)
LIBC_SO=$("$@" --print-file-name=libc.so.6)
cp ${KEEPSYMS_IN} ${KEEPSYMS}
# get all symbols from libc and turn them into patterns
nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ ]*\).*/^\1$/' >> ${KEEPSYMS}
nm -f p -g -D ${LIBC_SO} | sed -s 's/\([^ @]*\).*/^\1$/' >> ${KEEPSYMS}
# build the object
"$@"
# rename the symbols in the object
Expand Down
7 changes: 6 additions & 1 deletion examples/patbench.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2017, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -115,6 +115,7 @@
#include <algorithm>
#include <cstring>
#include <chrono>
#include <climits>
#include <fstream>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -657,6 +658,10 @@ int main(int argc, char **argv) {
break;
case 'n':
repeatCount = atoi(optarg);
if (repeatCount <= 0 || repeatCount > UINT_MAX) {
cerr << "Invalid repeatCount." << endl;
exit(-1);
}
break;
default:
usage(argv[0]);
Expand Down
7 changes: 6 additions & 1 deletion examples/pcapscan.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2016, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -51,6 +51,7 @@

#include <cstring>
#include <chrono>
#include <climits>
#include <fstream>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -489,6 +490,10 @@ int main(int argc, char **argv) {

// Streaming mode scans.
double secsStreamingScan = 0.0, secsStreamingOpenClose = 0.0;
if (repeatCount <= 0 || repeatCount > UINT_MAX) {
cerr << "Invalid repeatCount." << endl;
exit(-1);
}
for (unsigned int i = 0; i < repeatCount; i++) {
// Open streams.
clock.start();
Expand Down
12 changes: 11 additions & 1 deletion examples/simplegrep.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -57,6 +57,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <hs.h>

Expand Down Expand Up @@ -152,6 +153,15 @@ int main(int argc, char *argv[]) {
char *pattern = argv[1];
char *inputFN = argv[2];

if (access(inputFN, F_OK) != 0) {
fprintf(stderr, "ERROR: file doesn't exist.\n");
return -1;
}
if (access(inputFN, R_OK) != 0) {
fprintf(stderr, "ERROR: can't be read.\n");
return -1;
}

/* First, we attempt to compile the pattern provided on the command line.
* We assume 'DOTALL' semantics, meaning that the '.' meta-character will
* match newline characters. The compiler will analyse the given pattern and
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/compiler.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2020, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -323,7 +323,8 @@ void addExpression(NG &ng, unsigned index, const char *expression,
}

// Ensure that our pattern isn't too long (in characters).
if (strlen(expression) > cc.grey.limitPatternLength) {
size_t maxlen = cc.grey.limitPatternLength + 1;
if (strnlen(expression, maxlen) >= maxlen) {
throw CompileError("Pattern length exceeds limit.");
}

Expand Down Expand Up @@ -416,6 +417,10 @@ void addLitExpression(NG &ng, unsigned index, const char *expression,
"HS_FLAG_SOM_LEFTMOST are supported in literal API.");
}

if (!strcmp(expression, "")) {
throw CompileError("Pure literal API doesn't support empty string.");
}

// This expression must be a pure literal, we can build ue2_literal
// directly based on expression text.
ParsedLitExpression ple(index, expression, expLength, flags, id);
Expand Down
8 changes: 7 additions & 1 deletion src/hs.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2020, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -514,6 +514,12 @@ hs_error_t hs_expression_info_int(const char *expression, unsigned int flags,
return HS_COMPILER_ERROR;
}

if (flags & HS_FLAG_COMBINATION) {
*error = generateCompileError("Invalid parameter: unsupported "
"logical combination expression", -1);
return HS_COMPILER_ERROR;
}

*info = nullptr;
*error = nullptr;

Expand Down
2 changes: 1 addition & 1 deletion src/hs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

#define HS_MAJOR 5
#define HS_MINOR 4
#define HS_PATCH 0
#define HS_PATCH 1

#include "hs_compile.h"
#include "hs_runtime.h"
Expand Down
12 changes: 3 additions & 9 deletions src/hs_compile.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2020, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -748,10 +748,7 @@ hs_error_t HS_CDECL hs_free_compile_error(hs_compile_error_t *error);
* - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode.
* - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset
* when a match is found.
* - HS_FLAG_COMBINATION - Parse the expression in logical combination
* syntax.
* - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for
* the sub-expressions in logical combinations.
* - HS_FLAG_QUIET - This flag will be ignored.
*
* @param info
* On success, a pointer to the pattern information will be returned in
Expand Down Expand Up @@ -814,10 +811,7 @@ hs_error_t HS_CDECL hs_expression_info(const char *expression,
* - HS_FLAG_PREFILTER - Compile pattern in prefiltering mode.
* - HS_FLAG_SOM_LEFTMOST - Report the leftmost start of match offset
* when a match is found.
* - HS_FLAG_COMBINATION - Parse the expression in logical combination
* syntax.
* - HS_FLAG_QUIET - Ignore match reporting for this expression. Used for
* the sub-expressions in logical combinations.
* - HS_FLAG_QUIET - This flag will be ignored.
*
* @param ext
* A pointer to a filled @ref hs_expr_ext_t structure that defines
Expand Down
6 changes: 4 additions & 2 deletions src/hs_internal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2019-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -80,7 +80,9 @@ extern "C"
| HS_FLAG_PREFILTER \
| HS_FLAG_SINGLEMATCH \
| HS_FLAG_ALLOWEMPTY \
| HS_FLAG_SOM_LEFTMOST)
| HS_FLAG_SOM_LEFTMOST \
| HS_FLAG_COMBINATION \
| HS_FLAG_QUIET)

#ifdef __cplusplus
} /* extern "C" */
Expand Down
2 changes: 1 addition & 1 deletion src/hwlm/noodle_engine_sse.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ hwlm_error_t scanDoubleShort(const struct noodTable *n, const u8 *buf,
if (!l) {
return HWLM_SUCCESS;
}
assert(l <= 32);
assert(l <= 16);

DEBUG_PRINTF("d %zu\n", d - buf);
m128 v = zeroes128();
Expand Down
8 changes: 8 additions & 0 deletions src/nfa/goughcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ void makeCFG_top_edge(GoughGraph &cfg, const vector<GoughVertex> &vertices,
assert(contains(src_slots, slot_id));

shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
if (!vmin) {
assert(0);
throw std::bad_alloc();
}
cfg[e].vars.push_back(vmin);
final_var = vmin.get();

Expand Down Expand Up @@ -318,6 +322,10 @@ void makeCFG_edge(GoughGraph &cfg, const map<u32, u32> &som_creators,
DEBUG_PRINTF("bypassing min on join %u\n", slot_id);
} else {
shared_ptr<GoughSSAVarMin> vmin = make_shared<GoughSSAVarMin>();
if (!vmin) {
assert(0);
throw std::bad_alloc();
}
cfg[e].vars.push_back(vmin);
final_var = vmin.get();

Expand Down
6 changes: 4 additions & 2 deletions src/nfa/mcclellancompile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015-2020, Intel Corporation
* Copyright (c) 2015-2021, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -1082,7 +1082,9 @@ void find_better_daddy(dfa_info &info, dstate_id_t curr_id, bool using8bit,
// Use the daddy already set for this state so long as it isn't already
// a Sherman state.
dstate_id_t daddy = currState.daddy;
if (!info.is_sherman(daddy) && !info.is_widestate(daddy)) {
if (info.is_widestate(daddy)) {
return;
} else if (!info.is_sherman(daddy)) {
hinted.insert(currState.daddy);
} else {
// Fall back to granddaddy, which has already been processed (due
Expand Down
1 change: 1 addition & 0 deletions src/nfa/nfa_dump_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace ue2 {
DISPATCH_CASE(LBR_NFA_VERM, LbrVerm, dbnt_func); \
DISPATCH_CASE(LBR_NFA_NVERM, LbrNVerm, dbnt_func); \
DISPATCH_CASE(LBR_NFA_SHUF, LbrShuf, dbnt_func); \
DISPATCH_CASE(LBR_NFA_VSHUF, LbrVShuf, dbnt_func); \
DISPATCH_CASE(LBR_NFA_TRUF, LbrTruf, dbnt_func); \
DISPATCH_CASE(CASTLE_NFA, Castle, dbnt_func); \
DISPATCH_CASE(SHENG_NFA, Sheng, dbnt_func); \
Expand Down
4 changes: 4 additions & 0 deletions src/nfa/repeatcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ RepeatStateInfo::RepeatStateInfo(enum RepeatType type, const depth &repeatMin,
const depth &repeatMax, u32 minPeriod)
: stateSize(0), packedCtrlSize(0), horizon(0), patchCount(0),
patchSize(0), encodingSize(0), patchesOffset(0) {
if (type == REPEAT_SPARSE_OPTIMAL_P && minPeriod == 0) {
assert(0);
throw std::domain_error("SPARSE_OPTIMAL_P must have non-zero minPeriod.");
}
assert(repeatMin <= repeatMax);
assert(repeatMax.is_reachable());
assert(minPeriod || type != REPEAT_SPARSE_OPTIMAL_P);
Expand Down
9 changes: 9 additions & 0 deletions src/nfagraph/ng_som.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,10 @@ static
bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) {
ue2_literal lit;
shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
if (!rhs) {
assert(0);
throw std::bad_alloc();
}
if (!ng.cc.grey.allowLitHaig) {
return false;
}
Expand Down Expand Up @@ -2510,6 +2514,11 @@ bool doHaigLitHaigSom(NG &ng, NGHolder &g,
ue2_literal lit;
shared_ptr<NGHolder> rhs = make_shared<NGHolder>();
shared_ptr<NGHolder> lhs = make_shared<NGHolder>();
if (!rhs || !lhs) {
assert(0);
throw std::bad_alloc();
}

if (!splitOffBestLiteral(g, regions, &lit, &*lhs, &*rhs, ng.cc)) {
return false;
}
Expand Down
Loading

0 comments on commit c37166d

Please sign in to comment.