Commit 6dcd6416 authored by Oran Agra's avatar Oran Agra
Browse files

Trim trailing spaces in error replies coming from rejectCommand (#7668)

65a3307b 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.

(cherry picked from commit cdd925b2)
parent 11805375
...@@ -412,10 +412,14 @@ void addReplyError(client *c, const char *err) { ...@@ -412,10 +412,14 @@ void addReplyError(client *c, const char *err) {
* is emitted. */ * is emitted. */
void addReplyErrorSafe(client *c, char *s, size_t len) { void addReplyErrorSafe(client *c, char *s, size_t len) {
size_t j; 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++) { for (j = 0; j < len; j++) {
if (s[j] == '\r' || s[j] == '\n') s[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, ...) { void addReplyErrorFormat(client *c, const char *fmt, ...) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment