[GRASS-SVN] r62105 - grass/trunk/lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Sep 26 20:10:02 PDT 2014
Author: glynn
Date: 2014-09-26 20:10:02 -0700 (Fri, 26 Sep 2014)
New Revision: 62105
Modified:
grass/trunk/lib/gis/parser.c
Log:
Check that option names are valid
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2014-09-26 23:44:35 UTC (rev 62104)
+++ grass/trunk/lib/gis/parser.c 2014-09-27 03:10:02 UTC (rev 62105)
@@ -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;
@@ -655,7 +659,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) {
@@ -871,6 +875,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