diff --git a/src/networking.c b/src/networking.c index 2fa05f0d6..20d05a9e3 100644 --- a/src/networking.c +++ b/src/networking.c @@ -356,6 +356,17 @@ void _addReplyProtoToList(client *c, const char *s, size_t len) { void _addReplyToBufferOrList(client *c, const char *s, size_t len) { if (c->flags & CLIENT_CLOSE_AFTER_REPLY) return; + /* Replicas should normally not cause any writes to the reply buffer. In case a rogue replica sent a command on the + * replication link that caused a reply to be generated we'll simply disconnect it. + * Note this is the simplest way to check a command added a response. Replication links are used to write data but + * not for responses, so we should normally never get here on a replica client. */ + if (getClientType(c) == CLIENT_TYPE_SLAVE) { + serverLog(LL_WARNING, "Replica generated a reply to command %s, disconnecting it", + c->lastcmd ? c->lastcmd->name : ""); + freeClientAsync(c); + return; + } + size_t reply_len = _addReplyToBuffer(c,s,len); if (len > reply_len) _addReplyProtoToList(c,s+reply_len,len-reply_len); }