Author: trasz
Date: Tue Oct 28 10:25:59 2014
New Revision: 273768
URL: https://svnweb.freebsd.org/changeset/base/273768

Log:
  Remove the distinction between strings and numbers from ctld(8) yacc parser.
  This fixes problems with passing strings that look like numbers to clauses
  that expect strings; previously it caused syntax errors and had to be worked
  by user, using quotes.  The workaround introduced in r267833 is no longer
  neccessary.
  
  MFC after:    1 month
  Sponsored by: The FreeBSD Foundation

Modified:
  head/usr.sbin/ctld/parse.y
  head/usr.sbin/ctld/token.l

Modified: head/usr.sbin/ctld/parse.y
==============================================================================
--- head/usr.sbin/ctld/parse.y  Tue Oct 28 08:00:28 2014        (r273767)
+++ head/usr.sbin/ctld/parse.y  Tue Oct 28 10:25:59 2014        (r273768)
@@ -101,21 +101,45 @@ statement:
        target
        ;
 
-debug:         DEBUG NUM
+debug:         DEBUG STR
        {
-               conf->conf_debug = $2;
+               uint64_t tmp;
+
+               if (expand_number($2, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $2);
+                       free($2);
+                       return (1);
+               }
+                       
+               conf->conf_debug = tmp;
        }
        ;
 
-timeout:       TIMEOUT NUM
+timeout:       TIMEOUT STR
        {
-               conf->conf_timeout = $2;
+               uint64_t tmp;
+
+               if (expand_number($2, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $2);
+                       free($2);
+                       return (1);
+               }
+
+               conf->conf_timeout = tmp;
        }
        ;
 
-maxproc:       MAXPROC NUM
+maxproc:       MAXPROC STR
        {
-               conf->conf_maxproc = $2;
+               uint64_t tmp;
+
+               if (expand_number($2, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $2);
+                       free($2);
+                       return (1);
+               }
+
+               conf->conf_maxproc = tmp;
        }
        ;
 
@@ -583,9 +607,17 @@ target_lun:        LUN lun_number
        }
        ;
 
-lun_number:    NUM
+lun_number:    STR
        {
-               lun = lun_new(target, $1);
+               uint64_t tmp;
+
+               if (expand_number($1, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $1);
+                       free($1);
+                       return (1);
+               }
+
+               lun = lun_new(target, tmp);
                if (lun == NULL)
                        return (1);
        }
@@ -626,15 +658,23 @@ lun_backend:      BACKEND STR
        }
        ;
 
-lun_blocksize: BLOCKSIZE NUM
+lun_blocksize: BLOCKSIZE STR
        {
+               uint64_t tmp;
+
+               if (expand_number($2, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $2);
+                       free($2);
+                       return (1);
+               }
+
                if (lun->l_blocksize != 0) {
                        log_warnx("blocksize for lun %d, target \"%s\" "
                            "specified more than once",
                            lun->l_lun, target->t_name);
                        return (1);
                }
-               lun_set_blocksize(lun, $2);
+               lun_set_blocksize(lun, tmp);
        }
        ;
 
@@ -689,31 +729,26 @@ lun_serial:       SERIAL STR
                }
                lun_set_serial(lun, $2);
                free($2);
-       } |     SERIAL NUM
+       }
+       ;
+
+lun_size:      SIZE STR
        {
-               char *str = NULL;
+               uint64_t tmp;
 
-               if (lun->l_serial != NULL) {
-                       log_warnx("serial for lun %d, target \"%s\" "
-                           "specified more than once",
-                           lun->l_lun, target->t_name);
+               if (expand_number($2, &tmp) != 0) {
+                       log_warnx("invalid numeric value \"%s\"", $2);
+                       free($2);
                        return (1);
                }
-               asprintf(&str, "%ju", $2);
-               lun_set_serial(lun, str);
-               free(str);
-       }
-       ;
 
-lun_size:      SIZE NUM
-       {
                if (lun->l_size != 0) {
                        log_warnx("size for lun %d, target \"%s\" "
                            "specified more than once",
                            lun->l_lun, target->t_name);
                        return (1);
                }
-               lun_set_size(lun, $2);
+               lun_set_size(lun, tmp);
        }
        ;
 %%

Modified: head/usr.sbin/ctld/token.l
==============================================================================
--- head/usr.sbin/ctld/token.l  Tue Oct 28 08:00:28 2014        (r273767)
+++ head/usr.sbin/ctld/token.l  Tue Oct 28 10:25:59 2014        (r273768)
@@ -75,12 +75,6 @@ serial                       { return SERIAL; }
 size                   { return SIZE; }
 target                 { return TARGET; }
 timeout                        { return TIMEOUT; }
-[0-9]+[kKmMgGtTpPeE]?  { if (expand_number(yytext, &yylval.num) == 0)
-                               return NUM;
-                         else {
-                               yylval.str = strdup(yytext); return STR;
-                         }
-                       }
 \"[^"]+\"              { yylval.str = strndup(yytext + 1,
                            strlen(yytext) - 2); return STR; }
 [a-zA-Z0-9\.\-_/\:\[\]]+ { yylval.str = strdup(yytext); return STR; }
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to