diff options
author | Oran Agra <oran@redislabs.com> | 2020-08-18 08:28:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-18 08:28:43 +0300 |
commit | cdd925b2898ac270afdf3d72f065410a96980f80 (patch) | |
tree | effa5d0d6b3a295c4430f8b1b23f4d91cf7fee97 /src | |
parent | 64c360c5156ca6ee6d1eb52bfeb3fa48f3b25da5 (diff) | |
download | redis-cdd925b2898ac270afdf3d72f065410a96980f80.tar.gz |
Trim trailing spaces in error replies coming from rejectCommand (#7668)
65a3307bc9 added rejectCommand which takes an robj reply and passes it
through addReplyErrorSafe to addReplyErrorLength.
The robj contains newline at it's end, but addReplyErrorSafe converts it
to spaces, and passes it to addReplyErrorLength which adds the protocol
newlines.
The result was that most error replies (like OOM) had extra two trailing
spaces in them.
Diffstat (limited to 'src')
-rw-r--r-- | src/networking.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c index 8ec85b393..f0ebe4134 100644 --- a/src/networking.c +++ b/src/networking.c @@ -412,10 +412,14 @@ void addReplyError(client *c, const char *err) { * is emitted. */ void addReplyErrorSafe(client *c, char *s, size_t len) { size_t j; + /* Trim any newlines at the end (ones will be added by addReplyErrorLength) */ + while (s[len-1] == '\r' || s[len-1] == '\n') + len--; + /* Replace any newlines in the rest of the string with spaces. */ for (j = 0; j < len; j++) { if (s[j] == '\r' || s[j] == '\n') s[j] = ' '; } - addReplyErrorLength(c,s,sdslen(s)); + addReplyErrorLength(c,s,len); } void addReplyErrorFormat(client *c, const char *fmt, ...) { |