Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential fault at createDoubleObject #964

Merged
merged 1 commit into from Aug 29, 2022

Conversation

afcidk
Copy link
Contributor

@afcidk afcidk commented Jun 14, 2021

Resolves #963.

Add additional check to hi_malloc for r->str when len+1 equals to 0.

hiredis.c Outdated
@@ -231,6 +231,11 @@ static void *createDoubleObject(const redisReadTask *task, double value, char *s
freeReplyObject(r);
return NULL;
}
else if (len+1 == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case would len be -1 here as described in #963 ?
Ien is a size_t, i.e. an unsigned integer, and when the function is called using a signed integer the conversion rules
in 6.3.1.3 (bullet 2) of the c99 standard would apply.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to protect against hi_malloc(len + 1) when len == SIZE_MAX but I wonder if that's the more straightforward way to do it.

Just test that at the top of the routine and return NULL if it is true.

If we're feeling ambitious I suppose we could limit the maximum value here to a much more sane length.

More detail in this SO question

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, yes, that's a potential issue. Testing in the top of the routine would be simple and pragmatic.

Copy link
Contributor Author

@afcidk afcidk Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about confusing with -1.

This function is currently not able to be called if parameter len is larger than 326.

hiredis/read.c

Lines 290 to 297 in dfa33e6

char buf[326], *eptr;
double d;
if ((size_t)len >= sizeof(buf)) {
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
"Double value is too large");
return REDIS_ERR;
}

However, this check depends on the buffer size, which seems not so stable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If len < 326 at this point, it means the added return NULL; is dead code. Better add an assert(len < SIZE_MAX) instead then.

Resolves redis#963.

Add additional check to `hi_malloc` for `r->str` when len equals to
SIZE_MAX.
@michael-grunder michael-grunder merged commit 77e4f09 into redis:master Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential fault at createDoubleObject
4 participants