Skip to content

Commit

Permalink
Check seplen and len before malloc'ing "tokens"
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed May 5, 2011
1 parent bf9fd5f commit c040cbd
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/sds.c
Expand Up @@ -298,15 +298,17 @@ int sdscmp(sds s1, sds s2) {
*/
sds *sdssplitlen(char *s, int len, char *sep, int seplen, int *count) {
int elements = 0, slots = 5, start = 0, j;
sds *tokens;

sds *tokens = zmalloc(sizeof(sds)*slots);
if (seplen < 1 || len < 0) return NULL;

tokens = zmalloc(sizeof(sds)*slots);
#ifdef SDS_ABORT_ON_OOM
if (tokens == NULL) sdsOomAbort();
#else
if (tokens == NULL) return NULL;
#endif
if (seplen < 1 || len < 0 || tokens == NULL) {
*count = 0;
return NULL;
}

if (len == 0) {
*count = 0;
return tokens;
Expand Down

0 comments on commit c040cbd

Please sign in to comment.