[GRASS-SVN] r62926 - in grass/branches/releasebranch_7_0: . lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 25 03:04:02 PST 2014


Author: martinl
Date: 2014-11-25 03:04:02 -0800 (Tue, 25 Nov 2014)
New Revision: 62926

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/lib/gis/parser.c
Log:
libgis: Check that option names are valid
      (merge r62105 from trunk)



Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:60817,61096,61141,62179-62180,62182,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62566,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62691,62705,62709,62723,62730,62739,62741,62743,62746,62750,62752,62757,62762,62785,62798,62800-62801,62803,62805,62812,62822,62824,62831,62838,62847,62856,62879,62881,62907-62908,62910,62912,62914,62916,62918,62920
   + /grass/trunk:60817,61096,61141,62105,62179-62180,62182,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62566,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62691,62705,62709,62723,62730,62739,62741,62743,62746,62750,62752,62757,62762,62785,62798,62800-62801,62803,62805,62812,62822,62824,62831,62838,62847,62856,62879,62881,62907-62908,62910,62912,62914,62916,62918,62920

Modified: grass/branches/releasebranch_7_0/lib/gis/parser.c
===================================================================
--- grass/branches/releasebranch_7_0/lib/gis/parser.c	2014-11-25 10:59:01 UTC (rev 62925)
+++ grass/branches/releasebranch_7_0/lib/gis/parser.c	2014-11-25 11:04:02 UTC (rev 62926)
@@ -101,6 +101,7 @@
 /* local prototypes */
 static void set_flag(int);
 static int contains(const char *, int);
+static int valid_option_name(const char *);
 static int is_option(const char *);
 static void set_option(const char *);
 static void check_opts(void);
@@ -337,10 +338,13 @@
     /* Stash default answers */
 
     opt = &st->first_option;
-    while (opt) {
+    while (st->n_opts && opt) {
 	if (opt->required)
 	    st->has_required = 1;
 
+	if (!valid_option_name(opt->key))
+	    G_warning(_("BUG in option name, '%s' is not valid"), opt->key);
+
 	/* Parse options */
 	if (opt->options) {
 	    int cnt = 0;
@@ -658,7 +662,7 @@
     }
 
     opt = &st->first_option;
-    while (opt) {
+    while (st->n_opts && opt) {
 	if (opt->answer && opt->answers && opt->answers[0]) {
 	    slen = strlen(opt->key) + strlen(opt->answers[0]) + 4;	/* +4 for: ' ' = " " */
 	    if (len + slen >= nalloced) {
@@ -874,6 +878,23 @@
     return FALSE;
 }
 
+static int valid_option_name(const char *string)
+{
+    int m = strlen(string);
+    int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");
+
+    if (!m)
+	return 0;
+
+    if (m != n)
+	return 0;
+
+    if (string[m-1] == '_')
+	return 0;
+
+    return 1;
+}
+
 static int is_option(const char *string)
 {
     int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");



More information about the grass-commit mailing list