Commit Graph

172 Commits

Author SHA1 Message Date
michael-grunder
0c63e3f396 Fix timing based macOS CI failure.
Signed-off-by: michael-grunder <michael.grunder@gmail.com>
2024-08-13 08:03:06 -07:00
guoguangwu
7ab6b824c7 fix: typos
Signed-off-by: guoguangwu <guoguangwug@gmail.com>
2024-03-15 20:56:25 -07:00
git-hulk
5b253d89c7 Add support of RESP3 attribute type
Currently, Redis DEBUG PROTOCOL 'attrib' command will return an
attribute type, but hiredis doesn't support it yet. So it got the
protocol type error:

```
127.0.0.1:6379>  DEBUG PROTOCOL attrib
Error: Protocol error, got "|" as reply type byte
```

After apply this PR, it should reply:

```
127.0.0.1:6379> DEBUG PROTOCOL attrib
1# "key-popularity"
1# 1) "key:123"
   2) (integer) 90
```
2024-01-31 12:08:52 -08:00
Michael Grunder
869f3d0ef1
Make redisEnableKeepAlive a no-op on AF_UNIX connections. (#1215)
Fixes #1185
2023-08-18 21:07:25 -07:00
michael-grunder
e07ae7d3b6 Add a panic helper for non-assert aborts.
We merged a fix for a "maybe uninitialized" warning in #1209, but after
merging there could actually have then been a double free.

The reason is that when compiling with NDEBUG our assert macro becomes a
no-op, meaning that execution would no longer stop after `assert(NULL)`.

This commit just adds a simple panic macro which will execute regardless
of whether NDEBUG is defined or not.
2023-07-25 11:16:07 -07:00
V G
dedc6208b1 Fix a false positive warning of gcc 12+ -Werror=maybe-uninitialized 2023-07-14 08:37:31 -07:00
windyakin
052f99ab2d Ensure functionality without _MSC_VER definition 2023-06-08 12:18:12 -07:00
Michael Grunder
ded32c7d1a
Add a test for the TCP_USER_TIMEOUT option. (#1192)
* Add a test for the TCP_USER_TIMEOUT option.
* Explicitly set errno to ENOTSUP on unsupported OS's
2023-06-01 09:09:11 -07:00
Yossi Gottlieb
5cbd1f2960
Add -Werror as a default. (#1193) 2023-06-01 19:03:24 +03:00
michael-grunder
5d84c8cfdb Add a test ensuring we don't clobber connection error.
Adds a test that we don't attempt to set any socket timeout if the
connection itself failed.  This issue only seemed to occur on macOS but
it's nice to have a test for it.
2023-04-15 17:20:11 -07:00
Michael Grunder
563b062e37 Accept -nan per the RESP3 spec recommendation.
For reference:
https://github.com/redis/redis-specifications/blob/master/protocol/RESP3.md
2023-04-14 12:41:58 -07:00
filipe oliveira
f0bdf8405b
Add support for nan in RESP3 double (#1133) 2022-11-14 08:55:52 -08:00
michael-grunder
2b069573a5 CI fixes in preparation of release
- Upgrade to actions/checkout@v3 as node 12 is being phased out.
- Perform a manual dnf refresh on RockyLinux during setup.
- Switch to official cygwin/cygwin-install-action
2022-11-02 14:43:59 -07:00
Bjorn Svensson
3b15a04b59
Fixup of PR734: Coverage of hiredis.c (#1124)
Improve coverage (#734)

* Remove duplicate tests

- double covered by:
  "Can parse RESP3 doubles"
- bool covered via:
  "Can parse RESP3 bool"

* Make (connect) timeout in test config general

* Set error string in Unix connect with invalid timeout

Restructure testcase since redisConnectWithTimeout() and
redisConnectUnixWithTimeout() now behaves similar.

* Use quiet flag in lcov/genhtml instead of piping to /dev/null

* Fixup of redisCommandArgv test case

* Update test case to match what it covers

Use new test case info text since the previous one seemed copy&pasted.
The sought coverage was the handling of the parent-chaining
for a double object, which the test case now focuses on.

Co-authored-by: Ariel <ashtul@gmail.com>
2022-10-14 08:11:40 -07:00
michael-grunder
9c338a5981 Fix PUSH handler tests for Redis >= 7.0.5
Redis updated how invalidation push messages are sent to the client
after a FLUSHDB or FLUSHALL command.

See: redis/redis#8935
2022-09-27 14:33:26 -07:00
michael-grunder
560e664862 Minor refactor
Protect against a NULL pointer dereference, and remove unused write
to a variable.
2022-09-08 11:18:43 -07:00
Michael Grunder
61b5b299f0
Use a windows specific keepalive function. (#1104)
Use a windows specific keepalive function.

While it is possible to toggle `TCP_KEEPALIVE` in windows via
setsockopt, you have to use `WSAIoctl` to set the interval.

Since `WSAIoctl` can actually do all of this in one call (toggle the
option, and set the corresponding interval), just use that in Windows
and avoid the call to `setsockopt` alltogether.

Fixes: #1100
2022-09-03 12:39:57 -07:00
Björn Svensson
329eaf9bae Fix heap-buffer-overflow issue in redisvFormatCommad
A command with a faulty formatting string that lacks the
conversion specifier results in a ASAN heap-buffer-overflow.
This was due to that strchr() matches on null-termination,
which triggers a continuation of the string parsing.
2022-09-01 10:35:07 -07:00
bugwz
0a5fa3ddee Regression test for off-by-one parsing error
See: #916
2022-08-31 09:42:10 -07:00
michael-grunder
4ad99c69a2 Rework asSleep to be a generic millisleep function. 2022-08-29 16:22:20 -07:00
Arseniy Simonov
75cb6c1ea6 Do store command timeout in the context for redisSetTimeout (#593) 2022-08-29 16:22:20 -07:00
Michael Grunder
9219f7e7c3
Merge pull request #901 from devnexen/illumos_test_fix
Illumos test fixes, error message difference fot bad hostname test.
2022-08-29 11:35:13 -07:00
michael-grunder
6a3e96ad21 Maintain backward compatibiliy withour onConnect callback.
In f69fac7690, our async onConnect
callback was improved to take a non-const redisAsyncContext allowing it
to be reentrant.

Unfortunately, this is a breaking change we can't make until hiredis
v2.0.0.

This commit creates a separate callback member and corresponding
function that allows us to use the new functionality, while maintaining
our existing API for legacy code.

Fixes #1086
2022-08-26 10:14:47 -07:00
Kristján Valur Jónsson
f69fac7690
Drop const on redisAsyncContext in redisConnectCallback
Since the callback is now re-entrant, it can call apis such as redisAsyncDisconnect()
2022-07-08 13:52:43 +00:00
Kristján Valur Jónsson
6ed060920f
Add async regression test for issue #931 2022-07-08 13:52:22 +00:00
Kristján Valur Jónsson
2ccef30f3e Add regression test for issue #945 2022-07-05 11:17:30 +00:00
Kristján Valur Jónsson
4b901d44ad Initial async tests 2022-07-05 11:17:30 +00:00
Yossi Gottlieb
b455b33818 Handle push notifications before or after reply. 2022-04-22 15:35:55 +03:00
Björn Svensson
7123b87f6d Handle any pipelined unsubscribe in async
Redis responds to an unsubscribe with one or many replies, depending
on the current subscribe state. When channels/patterns names are
provided in a command each given name will trigger a reply even if
duplicated or not subscribed to.
To know when we can return from the subscribed state we need to do
bookkeeping on pending additional unsubscribe replies, and make sure
we receive them all before switching state.
2022-02-03 09:26:01 +01:00
Björn Svensson
b6fb548fc6 Ignore pubsub replies without a channel/pattern 2022-02-02 23:43:21 +01:00
Bjorn Svensson
be41ed60d7
Avoid incorrect call to the previous reply's callback (#1040)
* No reuse of the previous reply callback

When multiple replies are parsed from a socket in one read
a previously found callback might get reused when the current
reply has no known callback.

This can be triggered by the added testcase which unsubscribe to
subscribed (A,B) and a non-subscribed channel (X).
Without this correction a callback for wrong channel is called.
-  In 'unsubscribe B X A', B's callback is called when handling X.
-  Now this is not done, i.e. there is no callback called for X.

* Re-push monitor callback for each reply

MONITORING used the same callback for all replies while parsing
multiple responses. This handling was changed to avoid calling
the wrong callback in some scenarios.
Now also change monitorings repush to work with this change.

Includes an added async monitoring testcase.
2022-01-27 18:30:58 -08:00
Bjorn Svensson
f2ce5980e6
Allow sending commands after sending an unsubscribe (#1036)
* Add test of async commands after unsubscribe

Verify that commands are handled after unsubscribing from a channel.
A command is sent before the `unsubscribe` response is received,
which currently triggers an assert in async.c:567:

`redisProcessCallbacks: Assertion `(c->flags & REDIS_SUBSCRIBED || c->flags & REDIS_MONITORING)' failed.`

* Handle async commands after an unsubscribe

When unsubscribing from the last channel we move from the `subscribe`
state to a normal state. These states uses different holders for the
command callback information.
By moving the callback info during the state change the callback order
can be maintained.
2022-01-18 10:09:38 -08:00
Bjorn Svensson
ff860e55db
Correction for command timeout during pubsub (#1038)
* Add test of command timeout during pubsub

A timeout of a non-subscribe command will be ignored during pubsub.
It will be handled as an idle timeout and a response is awaited for.

* Correction for command timeout during pubsub

Disconnect when a sent non-subscribe command triggers a timeout.
2022-01-11 10:19:43 -08:00
Bjorn Svensson
58aacdac65
Handle array response in parallell with pubsub using RESP3 (#1014)
RESP3 allows sending commands in parallell with pubsub handling
and these commands might get responded with a REDIS_REPLY_ARRAY.
This conflicts with the pubsub response handling for RESP2 and
results in a faulty state when using RESP3.

Add functionality to keep track of PUSH/RESP3 support on the connection
and only expect the message type REDIS_REPLY_PUSH as subscribe messages
when once seen.
2021-12-22 10:44:29 -08:00
Bjorn Svensson
d3384260e7
Support PING while subscribing (RESP2) (#1027)
* Handle PING during pubsub in RESP2

* Rename invalid callback list

Some commands are valid to send during a subscribe in RESP2, and
most in RESP3. Renaming the callback list from `invalid` to `replies`
to detail this fact.

* Fix review comment
2021-12-16 12:38:15 -08:00
Bjorn Svensson
da5a4ff362
Add asynchronous test for pubsub using RESP3 (#1012)
* Include `unsubscribe` as a subscribe reply in RESP3

By providing the (p)unsubscribe message via the subscribe callback,
instead of via the push callback, we get the same behavior in RESP3
as in RESP2.

* Add asynchronous test for pubsub using RESP3

The testcase will subscribe to a channel, and via a second client
a message is published to the channel. After receiving the message
the testcase will unsubscribe and disconnect.

This RESP3 testcase reuses the subscribe callback from the RESP2
testcase to make sure we have a common behavior.
2021-12-01 11:43:23 -08:00
michael-grunder
7ad38dc4a8 Small tweaks of the async tests 2021-11-17 14:37:27 -08:00
Björn Svensson
4021726a69 Add asynchronous test for pubsub using RESP2
The testcase will subscribe to a channel, and via a second client
a message is published to the channel. After receiving the message
the testcase will unsubscribe and disconnect.
2021-10-27 16:46:37 +02:00
michael-grunder
fa900ef76f Fix unused variable warning. 2021-10-10 11:58:19 -07:00
michael-grunder
e489846b72 Minor refactor of CVE-2021-32765 fix.
Since `hi_calloc` always passes through one of our wrapper functions,
we can perform this overflow in the wrapper, and get protection
everywhere.

Previous commit: 76a7b10005

Related vuln ID: CVE-2021-32765
[Full Details](https://github.com/redis/hiredis/security/advisories/GHSA-hfm9-39pp-55p2)
2021-10-10 11:13:23 -07:00
michael-grunder
a39824a5df Merge branch 'release/v1.0.1'
Merge the v1.0.1 release branch and bump the dev version to 1.0.2-dev
2021-10-04 13:35:10 -07:00
Yossi Gottlieb
76a7b10005 Fix for integer/buffer overflow CVE-2021-32765
This fix prevents hiredis from trying to allocate more than `SIZE_MAX`
bytes, which would result in a buffer overrun.

[Full Details](https://github.com/redis/hiredis/security/advisories/GHSA-hfm9-39pp-55p2)
2021-10-04 11:56:31 -07:00
Alex Smith
83c1450425 read: Add support for the RESP3 bignum type 2021-02-25 21:25:17 -08:00
Alex Smith
e43061156c read: Additional validation and test case for RESP3 double
This ensures that malformed RESP3 double messages that include an
invalid null byte are not parsed as valid.
2021-02-25 21:25:17 -08:00
Alex Smith
0f92518847 test: Add test case for RESP3 set 2021-02-25 21:25:17 -08:00
Alex Smith
33c06dd503 test: Add test case for RESP3 map 2021-02-25 21:25:17 -08:00
Alex Smith
81c48a9821 test: Add test cases for RESP3 bool 2021-02-25 21:25:17 -08:00
Alex Smith
790b4d3b4d test: Add test cases for RESP3 nil 2021-02-25 21:25:17 -08:00
Alex Smith
96e8ea6110 test: Add test cases for infinite and NaN doubles 2021-02-25 21:25:17 -08:00
Alex Smith
8039c7d26c test: Add test case for doubles 2021-02-25 21:25:17 -08:00