[2/2] HACK: define NBD_SERVER_DEBUG to force malicious server

Message ID 20170811023759.26390-3-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake Aug. 11, 2017, 2:37 a.m.
---
 nbd/server.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch

diff --git a/nbd/server.c b/nbd/server.c
index 82a78bf439..d6fbd46370 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -919,6 +919,17 @@  static int nbd_send_reply(QIOChannel *ioc, NBDReply *reply, Error **errp)
     stl_be_p(buf + 4, reply->error);
     stq_be_p(buf + 8, reply->handle);

+    static int debug;
+    static int count;
+    if (!count++) {
+        const char *str = getenv("NBD_SERVER_DEBUG");
+        if (str) {
+            debug = atoi(str);
+        }
+    }
+    if (debug && !(count % debug)) {
+        buf[0] = 0;
+    }
     return nbd_write(ioc, buf, sizeof(buf), errp);
 }