net.c: add check of the first received buffer when using memcmp
authorSimon Guinot <simon.guinot@sequanux.org>
Thu, 21 Nov 2019 21:58:04 +0000 (22:58 +0100)
committerSimon Guinot <simon.guinot@sequanux.org>
Thu, 21 Nov 2019 21:58:45 +0000 (22:58 +0100)
The first received buffer is not checked when the "memcmp" method is
selected. This patch adds the missing check.

net.c

diff --git a/net.c b/net.c
index 8facae4..cfcb04d 100644 (file)
--- a/net.c
+++ b/net.c
@@ -401,11 +401,16 @@ static int recv_data_messages(int sock, struct netsum_ctrl *ctrl,
                        ret = -1;
                        goto err_free;
                }
-               if (i == 0)
-                       memcpy(template, buff, ctrl->size);
-               /* On error, fall back on buffer_is_valid(). */
-               if (use_memcmp && !memcmp(buff, template, ctrl->size))
-                       continue;
+               if (use_memcmp) {
+                       /*
+                        * For the first buffer received or on error, fall back
+                        * on buffer_is_valid().
+                        */
+                       if (i == 0)
+                               memcpy(template, buff, ctrl->size);
+                       else if (!memcmp(buff, template, ctrl->size))
+                               continue;
+               }
                if (!buffer_is_valid(buff, ctrl->size, true)) {
                        fprintf(stdout,
                                "Reference buffer stored in file: ref\n");