[sr-dev] [kamailio/kamailio] ndb_redis: redis_cmd() doesn't return error with a faulty command (#2300)

Victor Seva notifications at github.com
Fri Apr 24 09:39:25 CEST 2020


### Description

Detected that a command like this was not returning <0 
```
if(redis_cmd("test", "HSET dd field1", "r")) {
  [...]
}
```
Same command on redis-cli:
```
# redis-cli
127.0.0.1:6379> HSET dd field1
(error) ERR wrong number of arguments for 'hset' command
```

### Troubleshooting

#### Reproduction

I've added some debug to the code and I find out that the command is returning:
```
Apr 23 10:55:02 spce proxy[12880]: DEBUG: ndb_redis [redis_client.c:956]: redisc_exec(): rpl->rplRedis->type:3
```
That's an INTEGER. From hiredis/read.h:
```
#define REDIS_REPLY_INTEGER 3
#define REDIS_REPLY_NIL 4
#define REDIS_REPLY_STATUS 5
#define REDIS_REPLY_ERROR 6
```
I've created a simple test code to check the same command:
```
#include <stdio.h>
#include <stdarg.h>
#include "hiredis.h"

void check(redisContext *c, const char *cmd, ...) {
        va_list ap;
        va_start(ap,cmd);
        redisReply *r = redisvCommand(c, cmd, ap);
        va_end(ap);

        if(r == NULL) {
                printf("reply NULL\n");
        }
        printf("reply->type:%d\n", r->type);
        freeReplyObject(r);
}

int main(void) {
        redisContext *c = redisConnect("127.0.0.1", 6379);

        if (c == NULL || c->err) {
            if (c) {
                printf("Error: %s\n", c->errstr);
            } else {
                printf("Can't allocate redis context\n");
            }
            return 1;
        }
        check(c, "HSET dd field");
        redisFree(c);
        return 0;
}
```
```
root at spce:/usr/local/devel# cc t.c -o t -lhiredis -I/usr/include/hiredis
root at spce:/usr/local/devel# ./t
reply->type:6
```
No problems there. The reply is ERROR.

### Additional Information

  * **Kamailio Version** - output of `kamailio -v`

```
version: kamailio 5.3.3 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, NO_SIG_DEBUG, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 8.3.0
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/2300
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20200424/f37f8570/attachment.html>


More information about the sr-dev mailing list