summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root@avtech.domain.avtechpulse.com>1970-01-01 09:53:17 +0900
committerroot <root@avtech.domain.avtechpulse.com>1970-01-01 09:53:17 +0900
commitb3b9289e331287a6869fd4a91df62c479f30508c (patch)
treece9d3036bbc449d3bcd182e74dd5b5ada2acd75c
parenteb0f47ea5e8367c6462d0dbe904afc495e04af4b (diff)
stronger checking of numeric parameter formats
-rw-r--r--parser.c47
-rw-r--r--string_utils.c28
-rw-r--r--string_utils.h1
3 files changed, 65 insertions, 11 deletions
diff --git a/parser.c b/parser.c
index de3e9af..39f6fe2 100644
--- a/parser.c
+++ b/parser.c
@@ -53,13 +53,13 @@ static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char
static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char *store_string,int command_type);
static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char *store_string,int command_type);
static int Go_eprom_siz_86(gchar** response, int channel, int command_type);
-static int Go_sys_net_91(gchar** response, int channel, char *loc_string,char *store_string,int command_type);
+static int Go_sys_net_91(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_ampl_26(gchar** response, int channel, char *parameter,char *units,int command_type,char *mode);
static int Go_pw_36(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_duty_37(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_offset_29(gchar** response, int channel, char *parameter,char *units,int command_type,char *mode);
-static int Go_idn_5(gchar** response, int channel, char *loc_string,char *store_string,int command_type);
+static int Go_idn_5(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_freq_32_33(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_period_35(gchar** response, int channel, char *parameter,char *units,int command_type);
static int Go_delay_39(gchar** response, int channel, char *parameter,char *units,int command_type);
@@ -1172,6 +1172,10 @@ static int Go_Str_eprom_47(gchar** response, int channel, char *loc_string,char
/* diag:eprom:string - 47 */
int eprom_loc;
+ if (!String_is_it_pos_int(loc_string)) {
+ return SyntaxError;
+ }
+
eprom_loc = atoi(loc_string);
/* convert location string to a number */
@@ -1217,6 +1221,10 @@ static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char
int eprom_loc;
short the_number;
+ if (!String_is_it_pos_int(loc_string)) {
+ return SyntaxError;
+ }
+
eprom_loc = atoi(loc_string);
/* convert location string to a number */
@@ -1226,6 +1234,9 @@ static int Go_int_eprom_48(gchar** response, int channel, char *loc_string,char
switch (command_type) {
case command_param_units:
+ if (!String_is_it_pos_neg_int(store_string)) {
+ return SyntaxError;
+ }
the_number=(short) atoi(store_string);
*(short *)(&globals.Flash.flash_start + eprom_loc) = the_number;
writeUserBlock(&globals.Flash, eprom_loc, sizeof (the_number));
@@ -1251,6 +1262,10 @@ static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char
int eprom_loc;
float the_number;
+ if (!String_is_it_pos_int(loc_string)) {
+ return SyntaxError;
+ }
+
eprom_loc = atoi(loc_string);
/* convert location string to a number */
@@ -1261,6 +1276,9 @@ static int Go_Float_eprom51(gchar** response, int channel, char *loc_string,char
switch (command_type) {
case command_param_units:
+ if (!String_is_it_numeric(store_string)) {
+ return SyntaxError;
+ }
the_number=atof(store_string);
*(float *)(&globals.Flash.flash_start + eprom_loc)=the_number;
writeUserBlock(&globals.Flash, eprom_loc, sizeof(the_number));
@@ -1303,6 +1321,10 @@ static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char
int eprom_loc;
char the_number;
+ if (!String_is_it_pos_int(loc_string)) {
+ return SyntaxError;
+ }
+
eprom_loc = atoi(loc_string);
/* convert location string to a number */
@@ -1312,6 +1334,9 @@ static int Go_char_eprom_70(gchar** response, int channel, char *loc_string,char
switch (command_type) {
case command_param_units:
+ if (!String_is_it_pos_int(store_string)) {
+ return SyntaxError;
+ }
the_number=(char) atoi(store_string);
*(char *)(&globals.Flash.flash_start + eprom_loc)=the_number;
writeUserBlock(&globals.Flash, eprom_loc, sizeof(the_number));
@@ -1348,7 +1373,7 @@ static int Go_eprom_siz_86(gchar** response, int channel, int command_type)
}
-static int Go_sys_net_91(gchar **response, int channel, char *loc_string,char *store_string,int command_type)
+static int Go_sys_net_91(gchar **response, int channel, char *parameter,char *units,int command_type)
{
nicinfo info;
@@ -1556,7 +1581,7 @@ static int process_int_param (char *parameter, int *value, int item_count, int *
min_val = valid_nums[0];
max_val = valid_nums[item_count - 1];
- if (String_is_it_numeric(parameter)) {
+ if (String_is_it_pos_neg_int(parameter)) {
*value = atoi(parameter);
int i;
for (i = 0; (i < item_count) && (is_valid == 0); i++) {
@@ -1587,7 +1612,7 @@ static int process_int_range (char *parameter, int *value, int min_val, int max_
int status;
status = OK;
- if (String_is_it_numeric(parameter)) {
+ if (String_is_it_pos_neg_int(parameter)) {
*value = atoi(parameter);
if ((*value<min_val) || (*value>max_val)) {
status = OutOfRange;
@@ -1896,7 +1921,7 @@ static int Go_offset_29(gchar** response, int channel, char *parameter,char *uni
}
-static int Go_idn_5(gchar** response, int channel, char *loc_string,char *store_string,int command_type)
+static int Go_idn_5(gchar** response, int channel, char *parameter,char *units,int command_type)
{
/* *idn? - 5 */
@@ -3357,14 +3382,14 @@ static int Go_dly_shift_82(gchar** response, int channel, char *parameter,char *
switch (command_type) {
case command_param_units:
/* if param=point number, and units=measurement, then update calibration */
- if (String_is_it_numeric(parameter) && String_is_it_numeric(units)) {
+ if (String_is_it_pos_int(parameter) && String_is_it_numeric(units)) {
value=atoi(parameter);
if (value>num_of_dly_shift_points || value<1) {
return IllegalParameter;
}
cal_point=atof(units);
return Set_Dly_Shr_Cal(channel,value,cal_point);
- } else if (String_is_it_numeric(parameter) && !strcmp(units,"go")) {
+ } else if (String_is_it_pos_int(parameter) && !strcmp(units,"go")) {
value=atoi(parameter);
if (value>num_of_dly_shift_points || value<1) {
return IllegalParameter;
@@ -3470,14 +3495,14 @@ static int Go_amp_pnt_83(gchar** response, int channel, char *parameter,char *un
switch (command_type) {
case command_param_units:
/* if param=point number, and units=measurement, then update calibration */
- if (String_is_it_numeric(parameter) && String_is_it_numeric(units)) {
+ if (String_is_it_pos_int(parameter) && String_is_it_numeric(units)) {
value=atoi(parameter);
if (value>Get_VI_Num_Pnts(cal_type,channel) || value<1) {
return IllegalParameter;
}
cal_point=atof(units);
return Set_VI_Cal_Pnt(cal_type,channel,value,cal_point);
- } else if (String_is_it_numeric(parameter) && !strcmp(units,"go")) {
+ } else if (String_is_it_pos_int(parameter) && !strcmp(units,"go")) {
value=atoi(parameter);
if (value>Get_VI_Num_Pnts(cal_type,channel) || value<1) {
return IllegalParameter;
@@ -3485,7 +3510,7 @@ static int Go_amp_pnt_83(gchar** response, int channel, char *parameter,char *un
if (status=Set_Cal_Nom(channel,value,cal_type,NULL)) {
return status;
}
- } else if (String_is_it_numeric(parameter) && !strcmp(units,"delete")) {
+ } else if (String_is_it_pos_int(parameter) && !strcmp(units,"delete")) {
value=atoi(parameter);
if (value>Get_VI_Num_Pnts(cal_type,channel) || value<1) {
return IllegalParameter;
diff --git a/string_utils.c b/string_utils.c
index 3087060..264a6bd 100644
--- a/string_utils.c
+++ b/string_utils.c
@@ -37,6 +37,34 @@ gboolean String_is_it_numeric(char *parameter)
}
+gboolean String_is_it_pos_int(char *parameter)
+{
+
+ GRegex *numeric_regex = g_regex_new ( "^\\s*[+]?\\d+\\s*$",
+ G_REGEX_CASELESS,
+ 0,
+ NULL);
+
+ gboolean match = g_regex_match (numeric_regex, parameter, 0, NULL);
+ g_regex_unref (numeric_regex);
+ return match;
+}
+
+
+gboolean String_is_it_pos_neg_int(char *parameter)
+{
+
+ GRegex *numeric_regex = g_regex_new ( "^\\s*[+-]?\\d+\\s*$",
+ G_REGEX_CASELESS,
+ 0,
+ NULL);
+
+ gboolean match = g_regex_match (numeric_regex, parameter, 0, NULL);
+ g_regex_unref (numeric_regex);
+ return match;
+}
+
+
void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
char *start_string,char *units,gchar **LCD_string,int show_plus_sign, int width_of_column)
{
diff --git a/string_utils.h b/string_utils.h
index 96c3583..73398da 100644
--- a/string_utils.h
+++ b/string_utils.h
@@ -5,6 +5,7 @@
void Float_To_Text(int decimal_digits,float number_in, gchar** text_out);
gboolean String_is_it_numeric(char *parameter);
+gboolean String_is_it_pos_int(char *parameter);
void String_Parameter_To_Text(float Float_To_Convert, int significant_digits,
char *start_string,char *units,gchar **LCD_string,int show_plus_sign, int width_of_column);
gchar* conditional_regex_replace (gboolean do_it, gchar* in_string, gchar* regex_string, gchar* replace_with);