Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
a31ca8d7
Commit
a31ca8d7
authored
Dec 11, 2018
by
antirez
Browse files
stringmatchlen() fuzz test added.
Verified to be able to trigger at least #5632. Does not report other issues.
parent
c710d4af
Changes
3
Show whitespace changes
Inline
Side-by-side
src/debug.c
View file @
a31ca8d7
...
@@ -322,6 +322,7 @@ void debugCommand(client *c) {
...
@@ -322,6 +322,7 @@ void debugCommand(client *c) {
"SLEEP <seconds> -- Stop the server for <seconds>. Decimals allowed."
,
"SLEEP <seconds> -- Stop the server for <seconds>. Decimals allowed."
,
"STRUCTSIZE -- Return the size of different Redis core C structures."
,
"STRUCTSIZE -- Return the size of different Redis core C structures."
,
"ZIPLIST <key> -- Show low level info about the ziplist encoding."
,
"ZIPLIST <key> -- Show low level info about the ziplist encoding."
,
"STRINGMATCH-TEST -- Run a fuzz tester against the stringmatchlen() function."
,
NULL
NULL
};
};
addReplyHelp
(
c
,
help
);
addReplyHelp
(
c
,
help
);
...
@@ -619,6 +620,10 @@ NULL
...
@@ -619,6 +620,10 @@ NULL
changeReplicationId
();
changeReplicationId
();
clearReplicationId2
();
clearReplicationId2
();
addReply
(
c
,
shared
.
ok
);
addReply
(
c
,
shared
.
ok
);
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"stringmatch-test"
)
&&
c
->
argc
==
2
)
{
stringmatchlen_fuzz_test
();
addReplyStatus
(
c
,
"Apparently Redis did not crash: test passed"
);
}
else
{
}
else
{
addReplySubcommandSyntaxError
(
c
);
addReplySubcommandSyntaxError
(
c
);
return
;
return
;
...
...
src/util.c
View file @
a31ca8d7
...
@@ -171,6 +171,22 @@ int stringmatch(const char *pattern, const char *string, int nocase) {
...
@@ -171,6 +171,22 @@ int stringmatch(const char *pattern, const char *string, int nocase) {
return
stringmatchlen
(
pattern
,
strlen
(
pattern
),
string
,
strlen
(
string
),
nocase
);
return
stringmatchlen
(
pattern
,
strlen
(
pattern
),
string
,
strlen
(
string
),
nocase
);
}
}
/* Fuzz stringmatchlen() trying to crash it with bad input. */
int
stringmatchlen_fuzz_test
(
void
)
{
char
str
[
32
];
char
pat
[
32
];
int
cycles
=
10000000
;
int
total_matches
=
0
;
while
(
cycles
--
)
{
int
strlen
=
rand
()
%
sizeof
(
str
);
int
patlen
=
rand
()
%
sizeof
(
pat
);
for
(
int
j
=
0
;
j
<
strlen
;
j
++
)
str
[
j
]
=
rand
()
%
128
;
for
(
int
j
=
0
;
j
<
patlen
;
j
++
)
pat
[
j
]
=
rand
()
%
128
;
total_matches
+=
stringmatchlen
(
pat
,
patlen
,
str
,
strlen
,
0
);
}
return
total_matches
;
}
/* Convert a string representing an amount of memory into the number of
/* Convert a string representing an amount of memory into the number of
* bytes, so for instance memtoll("1Gb") will return 1073741824 that is
* bytes, so for instance memtoll("1Gb") will return 1073741824 that is
* (1024*1024*1024).
* (1024*1024*1024).
...
...
src/util.h
View file @
a31ca8d7
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
int
stringmatchlen
(
const
char
*
p
,
int
plen
,
const
char
*
s
,
int
slen
,
int
nocase
);
int
stringmatchlen
(
const
char
*
p
,
int
plen
,
const
char
*
s
,
int
slen
,
int
nocase
);
int
stringmatch
(
const
char
*
p
,
const
char
*
s
,
int
nocase
);
int
stringmatch
(
const
char
*
p
,
const
char
*
s
,
int
nocase
);
int
stringmatchlen_fuzz_test
(
void
);
long
long
memtoll
(
const
char
*
p
,
int
*
err
);
long
long
memtoll
(
const
char
*
p
,
int
*
err
);
uint32_t
digits10
(
uint64_t
v
);
uint32_t
digits10
(
uint64_t
v
);
uint32_t
sdigits10
(
int64_t
v
);
uint32_t
sdigits10
(
int64_t
v
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment