I have peers with description containing spaces but bgplg won't accept that by
default.

I'd like some comments on that diff.
It is OK for bgplgsh (show ip bgp in "Peer 1" feels OK) but not for bgplg as I
have to quote the peer description in the input box (feels rather unnatural).

Index: bgplg.c
===================================================================
RCS file: /cvs/src/usr.bin/bgplg/bgplg.c,v
retrieving revision 1.19
diff -u -p -r1.19 bgplg.c
--- bgplg.c     5 Mar 2018 10:53:37 -0000       1.19
+++ bgplg.c     24 Oct 2018 14:32:22 -0000
@@ -112,7 +112,7 @@ lg_getenv(const char *name, int *lenp)
                *lenp = len;
 
 #define allowed_in_string(_x)                                           \
-       (isalnum((unsigned char)_x) || strchr("-_.:/= ", _x))
+       (isalnum((unsigned char)_x) || strchr("\"-_.:/= ", _x))
 
        for (i = 0; i < len; i++) {
                if (ptr[i] == '&')
@@ -155,13 +155,18 @@ lg_arg2argv(char *arg, int *argc)
 {
        char **argv, *ptr = arg;
        size_t len;
-       u_int i, c = 1;
+       u_int i, c = 1, instr = 0;
 
        len = strlen(arg);
 
        /* Count elements */
        for (i = 0; i < len; i++) {
-               if (isspace((unsigned char)arg[i])) {
+               if (arg[i] == '\"') {
+                       instr++;
+                       memmove(&arg[i], &arg[i+1], (len-i)*sizeof(char));
+                       len--;
+               }
+               if (isspace((unsigned char)arg[i]) && !(instr%2)) {
                        /* filter out additional options */
                        if (arg[i + 1] == '-') {
                                printf("invalid input\n");
Index: bgplgsh.c
===================================================================
RCS file: /cvs/src/usr.bin/bgplg/bgplgsh.c,v
retrieving revision 1.8
diff -u -p -r1.8 bgplgsh.c
--- bgplgsh.c   9 Dec 2015 17:52:24 -0000       1.8
+++ bgplgsh.c   24 Oct 2018 14:32:22 -0000
@@ -79,7 +79,7 @@ lg_arg2argv(char *arg, int *argc)
 {
        char **argv, *ptr = arg;
        size_t len;
-       u_int i, c = 1;
+       u_int i, c = 1, instr = 0;
 
        if (lg_checkarg(arg) != 0)
                return (NULL);
@@ -88,7 +88,12 @@ lg_arg2argv(char *arg, int *argc)
 
        /* Count elements */
        for (i = 0; i < len; i++) {
-               if (isspace((unsigned char)arg[i])) {
+               if (arg[i] == '\"') {
+                       instr++;
+                       memmove(&arg[i], &arg[i+1], (len-i)*sizeof(char));
+                       len--;
+               }
+               if (isspace((unsigned char)arg[i]) && !(instr%2)) {
                        /* filter out additional options */
                        if (arg[i + 1] == '-') {
                                printf("invalid input\n");

Reply via email to