Browse code

shared/optparser.c: remove surrounding whitespace in non-quoted strings (bb#1518)

git-svn: trunk@5007

Tomasz Kojm authored on 2009/04/02 21:03:41
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Thu Apr  2 14:02:33 CEST 2009 (tk)
2
+----------------------------------
3
+ * shared/optparser.c: remove surrounding whitespace in non-quoted strings
4
+		       (bb#1518)
5
+
1 6
 Thu Apr  2 12:45:52 CEST 2009 (tk)
2 7
 ----------------------------------
3 8
  * clamscan/manager.c: check rlim_cur instead of rlim_max
... ...
@@ -719,7 +719,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
719 719
 		break;
720 720
 	    }
721 721
 
722
-	    if(!(pt = strchr(buff, ' '))) {
722
+	    if(!(pt = strpbrk(buff, " \t"))) {
723 723
 		if(verbose)
724 724
 		    fprintf(stderr, "ERROR: Missing argument for option at line %d\n", line);
725 725
 		err = 1;
... ...
@@ -727,7 +727,7 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
727 727
 	    }
728 728
 	    name = buff;
729 729
 	    *pt++ = 0;
730
-	    for(i = 0; i < (int) strlen(pt) - 1 && pt[i] == ' '; i++);
730
+	    for(i = 0; i < (int) strlen(pt) - 1 && (pt[i] == ' ' || pt[i] == '\t'); i++);
731 731
 	    pt += i;
732 732
 	    if((i = strlen(pt)) && pt[i - 1] == '\n')
733 733
 		pt[i-- - 1] = 0;
... ...
@@ -754,6 +754,15 @@ struct optstruct *optparse(const char *cfgfile, int argc, char **argv, int verbo
754 754
 		    err = 1;
755 755
 		    break;
756 756
 		}
757
+	    } else {
758
+		for(i = strlen(pt); i >= 1 && (pt[i - 1] == ' ' || pt[i - 1] == '\t'); i--);
759
+		if(!i) {
760
+		    if(verbose)
761
+			fprintf(stderr, "ERROR: Missing argument for option at line %u\n", line);
762
+		    err = 1;
763
+		    break;
764
+		}
765
+		pt[i] = 0;
757 766
 	    }
758 767
 
759 768
 	} else {