Commit 2d6dc9a1 authored by Claes Sjofors's avatar Claes Sjofors

Xtt and wb, input syntax check for erroneous characters at end (refs #147)

parent eff2ae46
...@@ -74,10 +74,11 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value ...@@ -74,10 +74,11 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value
void *buffer_ptr, int buff_size, int attr_size) void *buffer_ptr, int buff_size, int attr_size)
{ {
int sts; int sts;
char s[100];
switch ( type_id ) { switch ( type_id ) {
case pwr_eType_Boolean: { case pwr_eType_Boolean: {
if ( sscanf( value_str, "%d", (pwr_tBoolean *)buffer_ptr) != 1) if ( sscanf( value_str, "%d%s", (pwr_tBoolean *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
if ( *(pwr_tBoolean *)buffer_ptr > 1) if ( *(pwr_tBoolean *)buffer_ptr > 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
...@@ -92,14 +93,14 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value ...@@ -92,14 +93,14 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value
*(float *)buffer_ptr = FLT_MAX; *(float *)buffer_ptr = FLT_MAX;
else if ( strcmp( value_str, "FLT_NMAX") == 0) else if ( strcmp( value_str, "FLT_NMAX") == 0)
*(float *)buffer_ptr = -FLT_MAX; *(float *)buffer_ptr = -FLT_MAX;
else if ( sscanf( value_str, "%f", (float *)buffer_ptr) != 1) else if ( sscanf( value_str, "%f%s", (float *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Float64: { case pwr_eType_Float64: {
pwr_tFloat32 f; pwr_tFloat32 f;
pwr_tFloat64 d; pwr_tFloat64 d;
if ( sscanf( value_str, "%f", &f) != 1) if ( sscanf( value_str, "%f%s", &f, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
d = f; d = f;
memcpy( buffer_ptr, (char *) &d, sizeof(d)); memcpy( buffer_ptr, (char *) &d, sizeof(d));
...@@ -112,21 +113,21 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value ...@@ -112,21 +113,21 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value
c = '\0'; c = '\0';
memcpy( buffer_ptr, &c, sizeof(c)); memcpy( buffer_ptr, &c, sizeof(c));
} }
else if ( sscanf( value_str, "%c", (char *)buffer_ptr) != 1) else if ( sscanf( value_str, "%c%s", (char *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int8: { case pwr_eType_Int8: {
pwr_tInt8 i8; pwr_tInt8 i8;
pwr_tInt16 i16; pwr_tInt16 i16;
if ( sscanf( value_str, "%hd", &i16) != 1) if ( sscanf( value_str, "%hd%s", &i16, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
break; break;
} }
case pwr_eType_Int16: { case pwr_eType_Int16: {
if ( sscanf( value_str, "%hd", (short *)buffer_ptr) != 1) if ( sscanf( value_str, "%hd%s", (short *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
...@@ -135,47 +136,47 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value ...@@ -135,47 +136,47 @@ int wnav_attr_string_to_value( ldh_tSesContext ldhses, int type_id, char *value
*(int *)buffer_ptr = INT_MIN; *(int *)buffer_ptr = INT_MIN;
else if ( strcmp( value_str, "INT_MAX") == 0) else if ( strcmp( value_str, "INT_MAX") == 0)
*(int *)buffer_ptr = INT_MAX; *(int *)buffer_ptr = INT_MAX;
else if ( sscanf( value_str, "%d", (int *)buffer_ptr) != 1) else if ( sscanf( value_str, "%d%s", (int *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int64: { case pwr_eType_Int64: {
if ( sscanf( value_str, pwr_dFormatInt64, (pwr_tUInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatInt64 "%s", (pwr_tUInt64 *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt8: { case pwr_eType_UInt8: {
pwr_tUInt8 i8; pwr_tUInt8 i8;
pwr_tUInt16 i16; pwr_tUInt16 i16;
if ( sscanf( value_str, "%hu", &i16) != 1) if ( sscanf( value_str, "%hu%s", &i16, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
break; break;
} }
case pwr_eType_UInt16: { case pwr_eType_UInt16: {
if ( sscanf( value_str, "%hu", (pwr_tUInt16 *)buffer_ptr) != 1) if ( sscanf( value_str, "%hu%s", (pwr_tUInt16 *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt32: case pwr_eType_UInt32:
case pwr_eType_DisableAttr: { case pwr_eType_DisableAttr: {
if ( sscanf( value_str, "%u", (pwr_tDisableAttr *)buffer_ptr) != 1) if ( sscanf( value_str, "%u%s", (pwr_tDisableAttr *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt64: { case pwr_eType_UInt64: {
if ( sscanf( value_str, pwr_dFormatUInt64, (pwr_tUInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatUInt64 "%s", (pwr_tUInt64 *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Enum: { case pwr_eType_Enum: {
if ( sscanf( value_str, "%d", (pwr_tEnum *)buffer_ptr) != 1) if ( sscanf( value_str, "%d%s", (pwr_tEnum *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Mask: { case pwr_eType_Mask: {
if ( sscanf( value_str, "%u", (pwr_tMask *)buffer_ptr) != 1) if ( sscanf( value_str, "%u%s", (pwr_tMask *)buffer_ptr, s) != 1)
return WNAV__INPUT_SYNTAX; return WNAV__INPUT_SYNTAX;
break; break;
} }
......
...@@ -637,6 +637,8 @@ void XttGtk::valchanged_cmd_input( GtkWidget *w, gpointer data) ...@@ -637,6 +637,8 @@ void XttGtk::valchanged_cmd_input( GtkWidget *w, gpointer data)
xtt->set_prompt( ""); xtt->set_prompt( "");
xtt->input_open = 0; xtt->input_open = 0;
xtt->xnav->set_inputfocus(); xtt->xnav->set_inputfocus();
if ( EVEN(sts))
xtt->message( 'E', XNav::get_message(sts));
} }
else if ( xtt->command_open) { else if ( xtt->command_open) {
sts = xtt->xnav->command( text); sts = xtt->xnav->command( text);
......
...@@ -5337,12 +5337,13 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5337,12 +5337,13 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
void *buffer_ptr, int buff_size, int attr_size) void *buffer_ptr, int buff_size, int attr_size)
{ {
int sts; int sts;
char s[100];
switch ( type_id ) switch ( type_id )
{ {
case pwr_eType_Boolean: case pwr_eType_Boolean:
{ {
if ( sscanf( value_str, "%d", (pwr_tBoolean *)buffer_ptr) != 1) if ( sscanf( value_str, "%d%s", (pwr_tBoolean *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
if ( *(pwr_tBoolean *)buffer_ptr > 1) if ( *(pwr_tBoolean *)buffer_ptr > 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
...@@ -5350,7 +5351,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5350,7 +5351,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
} }
case pwr_eType_Float32: case pwr_eType_Float32:
{ {
if ( sscanf( value_str, "%f", (float *)buffer_ptr) != 1) if ( sscanf( value_str, "%f%s", (float *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
...@@ -5358,7 +5359,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5358,7 +5359,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
{ {
pwr_tFloat32 f; pwr_tFloat32 f;
pwr_tFloat64 d; pwr_tFloat64 d;
if ( sscanf( value_str, "%f", &f) != 1) if ( sscanf( value_str, "%f%s", &f, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
d = f; d = f;
memcpy( buffer_ptr, (char *) &d, sizeof(d)); memcpy( buffer_ptr, (char *) &d, sizeof(d));
...@@ -5367,7 +5368,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5367,7 +5368,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
} }
case pwr_eType_Char: case pwr_eType_Char:
{ {
if ( sscanf( value_str, "%c", (char *)buffer_ptr) != 1) if ( sscanf( value_str, "%c%s", (char *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
...@@ -5375,7 +5376,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5375,7 +5376,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
{ {
pwr_tInt8 i8; pwr_tInt8 i8;
pwr_tInt16 i16; pwr_tInt16 i16;
if ( sscanf( value_str, "%hd", &i16) != 1) if ( sscanf( value_str, "%hd%s", &i16, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
...@@ -5383,20 +5384,20 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5383,20 +5384,20 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
} }
case pwr_eType_Int16: case pwr_eType_Int16:
{ {
if ( sscanf( value_str, "%hd", (short *)buffer_ptr) != 1) if ( sscanf( value_str, "%hd%s", (short *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int32: case pwr_eType_Int32:
case pwr_eType_Enum: case pwr_eType_Enum:
{ {
if ( sscanf( value_str, "%d", (int *)buffer_ptr) != 1) if ( sscanf( value_str, "%d%s", (int *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int64: case pwr_eType_Int64:
{ {
if ( sscanf( value_str, pwr_dFormatInt64, (pwr_tInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatInt64 "%s", (pwr_tInt64 *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
...@@ -5404,7 +5405,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5404,7 +5405,7 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
{ {
pwr_tUInt8 i8; pwr_tUInt8 i8;
pwr_tUInt16 i16; pwr_tUInt16 i16;
if ( sscanf( value_str, "%hu", &i16) != 1) if ( sscanf( value_str, "%hu%s", &i16, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
...@@ -5412,20 +5413,20 @@ int graph_attr_string_to_value( int type_id, const char *value_str, ...@@ -5412,20 +5413,20 @@ int graph_attr_string_to_value( int type_id, const char *value_str,
} }
case pwr_eType_UInt16: case pwr_eType_UInt16:
{ {
if ( sscanf( value_str, "%hu", (unsigned short *)buffer_ptr) != 1) if ( sscanf( value_str, "%hu%s", (unsigned short *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt32: case pwr_eType_UInt32:
case pwr_eType_Mask: case pwr_eType_Mask:
{ {
if ( sscanf( value_str, "%lu", (unsigned long *)buffer_ptr) != 1) if ( sscanf( value_str, "%lu%s", (unsigned long *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt64: case pwr_eType_UInt64:
{ {
if ( sscanf( value_str, pwr_dFormatUInt64, (pwr_tUInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatUInt64 "%s", (pwr_tUInt64 *)buffer_ptr, s) != 1)
return GE__INPUT_SYNTAX; return GE__INPUT_SYNTAX;
break; break;
} }
......
...@@ -248,10 +248,11 @@ int XNav::attr_string_to_value( int type_id, char *value_str, ...@@ -248,10 +248,11 @@ int XNav::attr_string_to_value( int type_id, char *value_str,
void *buffer_ptr, int buff_size, int attr_size) void *buffer_ptr, int buff_size, int attr_size)
{ {
int sts; int sts;
char s[100];
switch ( type_id ) { switch ( type_id ) {
case pwr_eType_Boolean: { case pwr_eType_Boolean: {
if ( sscanf( value_str, "%d", (pwr_tBoolean *)buffer_ptr) != 1) if ( sscanf( value_str, "%d%s", (pwr_tBoolean *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
if ( *(pwr_tBoolean *)buffer_ptr > 1) if ( *(pwr_tBoolean *)buffer_ptr > 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
...@@ -266,14 +267,14 @@ int XNav::attr_string_to_value( int type_id, char *value_str, ...@@ -266,14 +267,14 @@ int XNav::attr_string_to_value( int type_id, char *value_str,
*(float *)buffer_ptr = FLT_MAX; *(float *)buffer_ptr = FLT_MAX;
else if ( strcmp( value_str, "FLT_NMAX") == 0) else if ( strcmp( value_str, "FLT_NMAX") == 0)
*(float *)buffer_ptr = -FLT_MAX; *(float *)buffer_ptr = -FLT_MAX;
else if ( sscanf( value_str, "%f", (float *)buffer_ptr) != 1) else if ( sscanf( value_str, "%f%s", (float *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Float64: { case pwr_eType_Float64: {
pwr_tFloat32 f; pwr_tFloat32 f;
pwr_tFloat64 d; pwr_tFloat64 d;
if ( sscanf( value_str, "%f", &f) != 1) if ( sscanf( value_str, "%f%s", &f, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
d = f; d = f;
memcpy( buffer_ptr, (char *) &d, sizeof(d)); memcpy( buffer_ptr, (char *) &d, sizeof(d));
...@@ -281,14 +282,14 @@ int XNav::attr_string_to_value( int type_id, char *value_str, ...@@ -281,14 +282,14 @@ int XNav::attr_string_to_value( int type_id, char *value_str,
break; break;
} }
case pwr_eType_Char: { case pwr_eType_Char: {
if ( sscanf( value_str, "%c", (char *)buffer_ptr) != 1) if ( sscanf( value_str, "%c%s", (char *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int8: { case pwr_eType_Int8: {
pwr_tInt8 i8; pwr_tInt8 i8;
pwr_tInt16 i16; pwr_tInt16 i16;
if ( sscanf( value_str, "%hd", &i16) != 1) if ( sscanf( value_str, "%hd%s", &i16, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
...@@ -306,19 +307,19 @@ int XNav::attr_string_to_value( int type_id, char *value_str, ...@@ -306,19 +307,19 @@ int XNav::attr_string_to_value( int type_id, char *value_str,
*(int *)buffer_ptr = INT_MIN; *(int *)buffer_ptr = INT_MIN;
else if ( strcmp( value_str, "INT_MAX") == 0) else if ( strcmp( value_str, "INT_MAX") == 0)
*(int *)buffer_ptr = INT_MAX; *(int *)buffer_ptr = INT_MAX;
else if ( sscanf( value_str, "%d", (int *)buffer_ptr) != 1) else if ( sscanf( value_str, "%d%s", (int *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_Int64: { case pwr_eType_Int64: {
if ( sscanf( value_str, pwr_dFormatInt64, ( pwr_tInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatInt64 "%s", ( pwr_tInt64 *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt8: { case pwr_eType_UInt8: {
pwr_tUInt8 i8; pwr_tUInt8 i8;
pwr_tUInt16 i16; pwr_tUInt16 i16;
if ( sscanf( value_str, "%hu", &i16) != 1) if ( sscanf( value_str, "%hu%s", &i16, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
i8 = i16; i8 = i16;
memcpy( buffer_ptr, (char *)&i8, sizeof(i8)); memcpy( buffer_ptr, (char *)&i8, sizeof(i8));
...@@ -333,12 +334,12 @@ int XNav::attr_string_to_value( int type_id, char *value_str, ...@@ -333,12 +334,12 @@ int XNav::attr_string_to_value( int type_id, char *value_str,
case pwr_eType_Mask: case pwr_eType_Mask:
case pwr_eType_Enum: case pwr_eType_Enum:
case pwr_eType_DisableAttr: { case pwr_eType_DisableAttr: {
if ( sscanf( value_str, "%lu", (unsigned long *)buffer_ptr) != 1) if ( sscanf( value_str, "%lu%s", (unsigned long *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
case pwr_eType_UInt64: { case pwr_eType_UInt64: {
if ( sscanf( value_str, pwr_dFormatUInt64, (pwr_tUInt64 *)buffer_ptr) != 1) if ( sscanf( value_str, pwr_dFormatUInt64 "%s", (pwr_tUInt64 *)buffer_ptr, s) != 1)
return XNAV__INPUT_SYNTAX; return XNAV__INPUT_SYNTAX;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment