Commit Graph

24 Commits

Author SHA1 Message Date
michael-grunder 3bb985314d Fix a static analysis false positive
Static analyzer's can't tell that hi_calloc is calloc-like, and report a
potential null pointer dereference.  This isn't possible but it's
probably smarter to make the test anyway in the event code changes.
2020-07-21 15:39:40 -07:00
Michael Grunder 6448f735d5
sdsrange overflow fix (#830)
Fix overflow bug in `sdsrange`
2020-06-07 14:38:16 -07:00
Michael Grunder 8e0264cfd6
Allow users to replace allocator and handle OOM everywhere. (#800)
* Adds an indirection to every allocation/deallocation to allow users to 
  plug in ones of their choosing (use custom functions, jemalloc, etc).

* Gracefully handle OOM everywhere in hiredis.  This should make it possible
  for users of the library to have more flexibility in how they handle such situations.

* Changes `redisReaderTask->elements` from an `int` to a `long long` to prevent
  a possible overflow when transferring the task elements into a `redisReply`.

* Adds a configurable `max elements` member to `redisReader` that defaults to
  2^32 - 1.  This can be set to "unlimited" by setting the value to zero.
2020-05-22 09:27:49 -07:00
Michael Grunder 83bba659b9
Add logic to handle RESP3 push messages (#819)
Fixes #815
2020-05-21 11:12:18 -07:00
Michael Grunder 5c9f49e212
Resp3 verbatim string support (#805)
Pull RESP3 verbatim string handling from Redis

Fixes #802
2020-05-19 12:56:02 -07:00
Michael Grunder eafb085d11
Remove nested depth limitation. (#797)
* Remove nested depth limitation.

This commit removes the nested multi-bulk depth limitation of 7.
We do this by switching to pointer to pointer indirection and
growing the stack in chunks when needed.

See: #794, #421
2020-05-04 10:36:04 -07:00
ShooterIT 386b9950f3 fix spelling mistakes 2020-01-01 14:42:10 +08:00
Yossi Gottlieb 28759c4b81 Fix MSVC build. 2019-08-28 18:43:40 +03:00
Mark Nunberg ff4fa45422
Merge pull request #697 from yossigo/resp3
Port RESP3 support from Redis.
2019-08-27 06:59:32 -04:00
Mark Nunberg f9bccfb7ba
Merge branch 'master' into createArray-size_t 2019-08-09 04:02:53 -04:00
Yossi Gottlieb 91de9c975a RESP3 support changes from Redis.
This corresponds to commits d5c54f0b..bea09a7f in the redis repository.
2019-08-04 12:13:04 +03:00
Yossi Gottlieb a7a1886b7e Initial RESP3 support [d5c54f0b]. 2019-08-04 11:55:24 +03:00
qi.yang 918e24c83b redisReaderGetReply leak memory 2019-05-30 15:03:38 +08:00
Tom Lee c3188bfb1f Make string2ll static to avoid conflict with redis
See discussion on #609. This should also make it easier for redis to
update the vendored/bundled hiredis (though not by much).
2018-09-24 16:14:08 -07:00
Justin Brewer ef4256670f Update createArray to take size_t
This makes createArray consistent with createString, which also takes
size_t. Bounds-check and unit tests are updated to allow up to
min(SIZE_MAX,LLONG_MAX).

Changelog is updated to mention this API break.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-05-21 10:49:30 -05:00
michael-grunder 7bef042c03 Use string2ll from Redis
This commit pulls string2ll from Redis (with permission from Antirez)
as strtoll is 2-3x slower and even worse vs the original version in
hiredis that didn't check for overflow at all.

By using string2ll there is almost no measurable performance impact
of overflow detection even in integer parsing heavy workloads (e.g.
INCRBY commands).
2018-05-20 10:44:19 -07:00
Justin Brewer 1091975857 Fix bulk and multi-bulk length truncation
processMultiBulkItem truncates the value read from readLongLong,
resulting in a corrupted state when the next item is read.
createArray takes an int, so bound to INT_MAX.

Inspection showed that processBulkItem had the same truncation issue.
createString takes size_t, so bound to SIZE_MAX. This only has an
effect on 32-bit platforms.

A strict lower bound is also added, since negative lengths other
than -1 are invalid according to RESP.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-05-20 09:07:21 -07:00
Justin Brewer 93421f9d84 Properly detect integer parse errors
Badly formatted or out-of-range integers are now protocol errors.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-05-19 10:48:14 -07:00
Justin Brewer 58e6b87f51 Remove redundant NULL checks
free(NULL) is a valid NOP. Most of the hiredis free functions behave the
same way. redisReaderFree is updated to also be NULL-safe.

There is one redundant NULL check at sds.c:1036, but it's left as is
since sds is imported from upstream.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30 21:45:13 -05:00
Justin Brewer 54acc8f087 Remove redundant zero stores
calloc is guaranteed to provide a zero-initialized buffer. There is
no need to set fields to zero explicitly.

Signed-off-by: Justin Brewer <jzb0012@auburn.edu>
2018-04-30 21:45:13 -05:00
cdliuqiang@gmail.com 9219556386 calloc param fixes and NULL check 2018-01-05 16:19:54 +01:00
DongwenHuang 6bfc580a34 Update read.c
static char *seekNewline(char *s, size_t len)  : 
this function can not parse the string,such as "hello world\r". the case that  the last char is '\r'.
2016-04-11 23:27:45 +08:00
tzickel ec229678c2 Added support for compiling the parser code with Microsoft Visual C compiler.
For hiredis-py and others support on windows.
2015-03-13 15:58:23 +02:00
tzickel ba3e74c408 Refactor reading code into read.c
Makes hiredis reading functions easier to include in external projects

[fixed all merge conflicts against current version]

Closes #249
2015-01-05 16:53:22 -05:00