From 3c20b3fc2464cec5b79e4e23037794be5826f536 Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Tue, 10 Apr 2018 17:05:48 +0800 Subject: [PATCH 1/2] Bugfix: xadd command ID parse strictly check the string to be converted, strtoull() in libc may not set errno to EINVAL when the string contains invalid digits. --- src/t_stream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 4640f0b2..713b57b3 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -917,8 +917,10 @@ int string2ull(const char *s, unsigned long long *value) { return 1; } errno = 0; - *value = strtoull(s,NULL,10); - if (errno == EINVAL || errno == ERANGE) return 0; /* strtoull() failed. */ + char *endptr = NULL; + *value = strtoull(s,&endptr,10); + if (errno == EINVAL || errno == ERANGE || !(*s != '\0' && *endptr == '\0')) + return 0; /* strtoull() failed. */ return 1; /* Conversion done! */ } From b6b00f35ca08f586ea80e104dde2b343b9a843cf Mon Sep 17 00:00:00 2001 From: "dejun.xdj" Date: Tue, 10 Apr 2018 17:11:10 +0800 Subject: [PATCH 2/2] Return more accurate message when specified ID is invalid --- src/t_stream.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/t_stream.c b/src/t_stream.c index 713b57b3..f4d925a1 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -999,11 +999,10 @@ void xaddCommand(client *c) { maxlen_arg_idx = i; } else { /* If we are here is a syntax error or a valid ID. */ - if (streamParseIDOrReply(NULL,c->argv[i],&id,0) == C_OK) { + if (streamParseIDOrReply(c,c->argv[i],&id,0) == C_OK) { id_given = 1; break; } else { - addReply(c,shared.syntaxerr); return; } }