Add some fuzzers to test algorithms and data structures (#1852)
Fix some issues found with these new fuzzers
This commit is contained in:
+8
@@ -18,6 +18,10 @@
|
||||
along with multifast. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _AC_TYPES_H_
|
||||
#define _AC_TYPES_H_
|
||||
|
||||
@@ -274,3 +278,7 @@ void ac_automata_dump (AC_AUTOMATA_t * thiz, FILE *);
|
||||
#endif
|
||||
void ac_automata_get_stats(AC_AUTOMATA_t * thiz, struct ac_stats *stats);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+12
-3
@@ -643,17 +643,25 @@ static AC_ERROR_t dump_node_common(AC_AUTOMATA_t * thiz,
|
||||
dump_node_header(n,ai);
|
||||
if (n->matched_patterns && n->matched_patterns->num && n->final) {
|
||||
char lbuf[512];
|
||||
int nl = 0,j;
|
||||
int nl = 0,j,ret;
|
||||
|
||||
nl = ndpi_snprintf(lbuf,sizeof(lbuf),"'%.100s' N:%d{",rstr,n->matched_patterns->num);
|
||||
for (j=0; j<n->matched_patterns->num; j++) {
|
||||
AC_PATTERN_t *sid = &n->matched_patterns->patterns[j];
|
||||
if(j) nl += ndpi_snprintf(&lbuf[nl],sizeof(lbuf)-nl-1,", ");
|
||||
nl += ndpi_snprintf(&lbuf[nl],sizeof(lbuf)-nl-1,"%d %c%.100s%c",
|
||||
if(j) {
|
||||
ret = ndpi_snprintf(&lbuf[nl],sizeof(lbuf)-nl-1,", ");
|
||||
if (ret < 0 || (unsigned int)ret >= sizeof(lbuf)-nl-1)
|
||||
break;
|
||||
nl += (unsigned int)ret;
|
||||
}
|
||||
ret = ndpi_snprintf(&lbuf[nl],sizeof(lbuf)-nl-1,"%d %c%.100s%c",
|
||||
sid->rep.number & 0x3fff,
|
||||
sid->rep.number & 0x8000 ? '^':' ',
|
||||
sid->astring,
|
||||
sid->rep.number & 0x4000 ? '$':' ');
|
||||
if (ret < 0 || (unsigned int)ret >= sizeof(lbuf)-nl-1)
|
||||
break;
|
||||
nl += (unsigned int)ret;
|
||||
}
|
||||
fprintf(ai->file,"%s}\n",lbuf);
|
||||
}
|
||||
@@ -700,6 +708,7 @@ void ac_automata_dump(AC_AUTOMATA_t * thiz, FILE *file) {
|
||||
fprintf(ai.file,"---\n mem size %zu avg node size %d, node one char %d, <=8c %d, >8c %d, range %d\n---DUMP-END-\n",
|
||||
ai.memcnt,(int)ai.memcnt/(thiz->all_nodes_num+1),(int)ai.node_oc,(int)ai.node_8c,(int)ai.node_xc,(int)ai.node_xr);
|
||||
#endif
|
||||
acho_free(ai.bufstr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+6
-2
@@ -16,7 +16,9 @@ u_int32_t MurmurHash3_x86_32(const void *key, u_int32_t len, u_int32_t seed) {
|
||||
|
||||
const u_int32_t c1 = 0xcc9e2d51;
|
||||
const u_int32_t c2 = 0x1b873593;
|
||||
const u_int32_t *blocks = (const u_int32_t *)(data + nblocks * 4);
|
||||
const u_int32_t *blocks = NULL;
|
||||
if(data && len) /* To avoid UBSAN warning: runtime error: applying zero offset to null pointer */
|
||||
blocks = (const u_int32_t *)(data + nblocks * 4);
|
||||
|
||||
for(i = -nblocks; i; i++)
|
||||
{
|
||||
@@ -31,7 +33,9 @@ u_int32_t MurmurHash3_x86_32(const void *key, u_int32_t len, u_int32_t seed) {
|
||||
h1 = h1 * 5 + 0xe6546b64;
|
||||
}
|
||||
|
||||
const u_int8_t * tail = (const u_int8_t *)(data + nblocks * 4);
|
||||
const u_int8_t * tail = NULL;
|
||||
if(data && len) /* To avoid UBSAN warning: runtime error: applying zero offset to null pointer */
|
||||
tail = (const u_int8_t *)(data + nblocks * 4);
|
||||
|
||||
u_int32_t k1 = 0;
|
||||
|
||||
|
||||
Vendored
+7
@@ -71,6 +71,13 @@ static __inline u_int8_t _hll_rank(u_int32_t hash, u_int8_t bits) {
|
||||
[i: 19] 524288 bytes [StdError: 0.14%]
|
||||
*/
|
||||
int hll_init(struct ndpi_hll *hll, u_int8_t bits) {
|
||||
if(!hll) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(hll, '\0', sizeof(*hll));
|
||||
|
||||
if(bits < 4 || bits > 20) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user