NetworkBlockDevice / nbd

Network Block Device
GNU General Public License v2.0
459 stars 119 forks source link

/etc/nbdtab causes endless loop #118

Closed m4rkusxxl closed 3 years ago

m4rkusxxl commented 3 years ago

When using "cacertfile=" (or other parameters) in nbdtab, nbd-client will be stuck in an endless loop trying to parse the parameters in get_from_config.

m4rkusxxl commented 3 years ago
diff -Nur nbd-3.21.orig/nbd-client.c nbd-3.21/nbd-client.c
--- nbd-3.21.orig/nbd-client.c  2021-05-09 17:01:35.664324760 +0200
+++ nbd-3.21/nbd-client.c       2021-05-09 17:01:45.479201371 +0200
@@ -744,6 +744,7 @@
                }
                if(!strncmp(loc, "port=", 5)) {
                        *port = strndup(loc+5, strcspn(loc+5, ","));
+                       loc += strcspn(loc, ",");
                        goto next;
                }
                if(!strncmp(loc, "persist", 7)) {
@@ -768,22 +769,27 @@
                }
                if(!strncmp(loc, "certfile=", 9)) {
                        *certfile = strndup(loc+9, strcspn(loc+9, ","));
+                       loc += strcspn(loc, ",");
                        goto next;
                }
                if(!strncmp(loc, "keyfile=", 8)) {
                        *keyfile = strndup(loc+8, strcspn(loc+8, ","));
+                       loc += strcspn(loc, ",");
                        goto next;
                }
                if(!strncmp(loc, "cacertfile=", 11)) {
                        *cacertfile = strndup(loc+11, strcspn(loc+11, ","));
+                       loc += strcspn(loc, ",");
                        goto next;
                }
-               if(!strncmp(loc, "tlshostname=", 9)) {
-                       *tlshostname = strndup(loc+9, strcspn(loc+9, ","));
+               if(!strncmp(loc, "tlshostname=", 12)) {
+                       *tlshostname = strndup(loc+12, strcspn(loc+12, ","));
+                       loc += strcspn(loc, ",");
                        goto next;
                }
                if(!strncmp(loc, "no_optgo", 8)) {
                        *can_opt_go = false;
+                       loc += 8;
                        goto next;
                }
                // skip unknown options, with a warning unless they start with a '_'