Commit Graph

119 Commits

Author SHA1 Message Date
Michael Grunder
2e7d7cbabd
Resp3 oob push support (#841)
Proper support for RESP3 PUSH messages.

By default, PUSH messages are now intercepted and the reply memory freed.  
This means existing code should work unchanged when connecting to Redis
>= 6.0.0 even if `CLIENT TRACKING` were then enabled.

Additionally, we define two callbacks users can configure if they wish to handle
these messages in a custom way:

void redisPushFn(void *privdata, void *reply);
void redisAsyncPushFn(redisAsyncContext *ac, void *reply);

See #825
2020-07-19 18:54:42 -07:00
michael-grunder
ffd6eaebd6 Merge branch 'master' into new-ssl-api 2020-05-30 09:30:01 -07:00
Michael Grunder
e553e0f382
Document allocator injection and completeness fix in test.c (#824) 2020-05-26 10:06:28 -07:00
Michael Grunder
f5d2585043
Use unique names for allocator struct members (#823)
Using `strdup` as a struct member causes issues in older gcc
2020-05-25 12:17:43 -07:00
Yossi Gottlieb
190bca88d0 New SSL API to replace redisSecureConnection(). 2020-05-24 23:37:47 +03: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
Michael Grunder
cc9d032971
Win32 tests and timeout fix (#776)
Unit tests in Windows and a Windows timeout fix

This commit gets our unit tests compiling and running on Windows as well as removes a duplicated `timeval` -> `DWORD` conversion logic in sockcompat.c 

There are minor differences in behavior between Linux and Windows to note:

1.  In Windows, opening a non-existent hangs forever in WSAPoll whereas
    it correctly returns with a "Connection refused" error on Linux.
    For that reason, I simply skip this test in Windows.

    It may be related to this known issue:
    https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/

2.  Timeouts are handled slightly differently in Windows and Linux.  
    In Linux, we intentionally set REDIS_ERR_IO for connection
    timeouts whereas in Windows we set REDIS_ERR_TIMEOUT.  It may be
    prudent to fix this discrepancy although there are almost certainly
    users relying on the current behavior.
2020-04-02 22:41:34 -07:00
michael-grunder
ac0b186aa3 Free the reply in redisGetReply when passed NULL
We currently perform a NULL check in redisGetReply and don't push the
reply back to the caller, but we don't free any reply meaning that this
will leak memory:

redisGetReply(context, NULL);

This change simply frees the reply if we were passed NULL.

Addresses #740
2019-12-12 14:40:50 -08:00
michael-grunder
5aa7b1056b Fixes leaks in unit tests
redisFormatSdsCommandArgv takes an sds* and calls sdsempty() for us.

Addresses #714
2019-09-25 11:02:44 -07:00
Yossi Gottlieb
d952ed877a Add SSL mode tests.
This repeats all existing tests in SSL mode, but does not yet provide
SSL-specific tests.
2019-09-16 17:30:35 +03:00
Mark Nunberg
f9bccfb7ba
Merge branch 'master' into createArray-size_t 2019-08-09 04:02:53 -04:00
Eivind Uggedal
993af7710e test: fix errstr matching for musl libc
This makes the tests pass on musl[1] based distros like Alpine Linux.

[1]: https://www.musl-libc.org/
2019-05-14 07:29:26 +00:00
michael-grunder
afcc11cc5a Fix NXDOMAIN test case
As it turns out 'idontexist.com' actually does exist.
2019-03-31 13:46:05 -07:00
David Carlier
d9fe8bdf67 FreeBSD build fix 2018-11-26 16:20:51 +00:00
Mark Nunberg
3cb4fb2395 Skip NXDOMAIN test when using evil ISPs
Some ISPs like to inject their own "Suggestions" page whenever you hit
NXDOMAIN. This confuses Redis as well as addrinfo (black-holing the
route).
2018-09-25 20:51:34 -04: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
33a36dc25b Don't overflow 32 bit machines in the tests! 2018-05-20 12:34:20 -07:00
michael-grunder
60f622b892 Add an integer parsing heavy workload to throughput testing 2018-05-20 11:57:21 -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
Jan-Erik Rediger
8655a6ac7a test: Add regression test for sds argv formatting 2016-05-14 11:26:18 +02:00
not-a-robot
a91afd746b Auto merge of #379 - thomaslee:tom_test_race, r=badboy
Fix potential race in 'invalid timeout' tests

It's possible for the call to connect() to succeed on the very first try, in which case the logic for checking for invalid timeout fields is never executed. When this happens, the tests fail because they expect a REDIS_ERR_IO but no such failure has occurred.

Tests aside, this is a potential source of irritating and hard-to-find intermittent bugs.

This patch forces the validation to occur early so that we get predictable behavior whenever an invalid timeout is specified.
2016-04-20 17:42:04 +02:00
owent
6c53d6803a Add CI for Windows
- fix macro problem in mingw-gcc
- fix typedef in cygwin
2016-04-20 16:10:02 +02:00
Jerry Jacobs
8a5fdf0c9e test.c: Fix shadowed name with typedef when compiling with -Wshadow 2016-04-17 20:33:59 +00:00
Tom Lee
d4b715f0aa Fix potential race in 'invalid timeout' tests
It's possible for the call to connect() to succeed on the very first
try, in which case the logic for checking for invalid timeout fields is
never executed. When this happens, the tests fail because they expect a
REDIS_ERR_IO but no such failure has occurred.

Tests aside, this is a potential source of irritating and hard-to-find
intermittent bugs.

This patch forces the validation to occur early so that we get
predictable behavior whenever an invalid timeout is specified.
2015-11-18 00:36:29 -08:00
olgeni
3d4b5c29ba Add FreeBSD message to test_blocking_connection_errors. 2015-09-16 12:24:03 +02:00
Jan-Erik Rediger
d9e0b0f6ab Implement a reconnect method for the client context
Originally implemented by @abedra as part of #306.

In case a write or read times out, we force an error state, because we
can't guarantuee that the next read will get the right data.
Instead we need to reconnect to have a clean-state connection, which is
now easily possible with this method.
2015-04-16 21:00:30 +02:00
Jan-Erik Rediger
b872919463 Make this work on Redis 3.0 2015-04-16 18:24:50 +02:00
Matt Stancliff
27076a3e6d Fix tests when assert() undefined
Closes #309

(such as when -DNDEBUG disables all assert() macros)

Inspired by keith-bennett-gbg, but re-rewritten to be more concise.
2015-02-18 14:45:03 -05:00
Matt Stancliff
3c023ee157 Cleanup memory during test 2015-01-22 16:00:38 -05:00
Matt Stancliff
802456def1 Use known-bad hostname when testing hostname fail
Suggested at
https://github.com/redis/hiredis/issues/294#issuecomment-69153074

This change also makes the test stop hanging for 10 to 30 seconds
waiting for the resolver to timeout.  Now the resolver immediately
sees the hostname is bad and returns error without waiting for timeout.
2015-01-08 17:28:55 -05:00
Matt Stancliff
c642079a80 Update test error message detection for dead hosts
Fixes #294
2015-01-08 17:26:22 -05:00
Daniel Melani
21a1207ae1 Add tests for redisFree() and freeReplyObject()
Test that redisFree() and freeReplyObject() do not crash when NULL is
passed in.
2014-05-29 17:10:03 +02:00
Axel Etcheverry
66192a0052 Add new redisAppendFormatedCommand with tests
Closes #202
2014-04-09 17:02:42 -04:00
ripcurld00d
303a0421ef Fix "host cannot be resolved test" test
Closes #186
2014-04-09 17:02:42 -04:00
Eddy Jansson
ae30d58ff9 Add redisConnectFd() and redisFreeKeepFd()
These allows for easier integration of hiredis with external
code that wants to manage its fds, say for instance in a pool.

Closes #223
2014-04-09 17:02:42 -04:00
Wolfgang Richter
37a840dc2c Emphasize size_t length for %b formatting
Closes #121.
2013-07-10 23:05:39 -07:00
Pieter Noordhuis
49de2cf990 Fix DNS error test (fixes #167) 2013-07-10 21:58:10 -07:00
Pieter Noordhuis
94675ea8c8 Merge branch 'gai_strerror'
See pull request #153.
2013-05-01 09:32:10 -07:00
Pieter Noordhuis
b1f07f77d2 Fix style 2013-05-01 09:32:03 -07:00
Aaron Bedra
fca66b9e8b Set error when invalid timeout value is given to redisConnectWithTimeout
Closes #154

This commit properly sets the error value inside of
redisContextWaitReady when an invalid sec or usec value is provided.
Tests for each case are provided to demonstrate that the issue is
properly fixed and to avoid regression.

Signed-off-by: Aaron Bedra <aaron@aaronbedra.com>
2013-03-14 21:34:21 -05:00
Thordur Bjornsson
e5589afdec Fix tests for test_blocking_connection_errors();
Add strings to allow OpenBSD/OSX to pass.
2013-02-23 10:51:24 +01:00
Henri Doreau
814be4f5bd Made connect functions return NULL on alloc failures.
Updated documentation and examples accordingly.
2013-01-22 10:19:46 +01:00
Pieter Noordhuis
05d0608ab9 Test new maximum depth of multi-bulk replies 2012-08-27 23:47:42 -07:00
Chip Salzenberg
1d5e27f6d7 more error messages 2011-12-20 10:05:57 -08:00
mrb
52a29a124b increase read depth by one, would allow ruby redis client to read from slowlog 2011-12-02 08:45:13 -05:00
Pieter Noordhuis
b52193977e Colorize test outcome 2011-07-10 17:36:07 +02:00