2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-29 13:27:59 +00:00

ovsdb: Require database, table, column names to be valid identifiers.

Database, table, and column names have always been required by the OVSDB
specification to be identifiers (e.g. valid C identifiers), but this has
never been enforced.

This commit adds enforcement and fixes one instance of an invalid column
name in the vswitch schema.
This commit is contained in:
Ben Pfaff 2009-11-19 16:48:12 -08:00
parent b9edf64b05
commit b966380b45
5 changed files with 10 additions and 4 deletions

View File

@ -41,8 +41,8 @@ ovsdb_parser_init(struct ovsdb_parser *parser, const struct json *json,
} }
} }
static bool bool
is_id(const char *string) ovsdb_parser_is_id(const char *string)
{ {
unsigned char c; unsigned char c;
@ -83,7 +83,7 @@ ovsdb_parser_member(struct ovsdb_parser *parser, const char *name,
if ((value->type >= 0 && value->type < JSON_N_TYPES if ((value->type >= 0 && value->type < JSON_N_TYPES
&& types & (1u << value->type)) && types & (1u << value->type))
|| (types & OP_ID && value->type == JSON_STRING || (types & OP_ID && value->type == JSON_STRING
&& is_id(value->u.string))) && ovsdb_parser_is_id(value->u.string)))
{ {
svec_add(&parser->used, name); svec_add(&parser->used, name);
return value; return value;

View File

@ -71,4 +71,6 @@ struct ovsdb_error *ovsdb_parser_get_error(const struct ovsdb_parser *);
struct ovsdb_error *ovsdb_parser_finish(struct ovsdb_parser *) struct ovsdb_error *ovsdb_parser_finish(struct ovsdb_parser *)
WARN_UNUSED_RESULT; WARN_UNUSED_RESULT;
bool ovsdb_parser_is_id(const char *string);
#endif /* ovsdb-parser.h */ #endif /* ovsdb-parser.h */

View File

@ -107,6 +107,8 @@ ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap)
if (node->name[0] == '_') { if (node->name[0] == '_') {
error = ovsdb_syntax_error(json, NULL, "names beginning with " error = ovsdb_syntax_error(json, NULL, "names beginning with "
"\"_\" are reserved"); "\"_\" are reserved");
} else if (!ovsdb_parser_is_id(node->name)) {
error = ovsdb_syntax_error(json, NULL, "name must be a valid id");
} else { } else {
error = ovsdb_table_schema_from_json(node->data, node->name, error = ovsdb_table_schema_from_json(node->data, node->name,
&table); &table);

View File

@ -111,6 +111,8 @@ ovsdb_table_schema_from_json(const struct json *json, const char *name,
if (node->name[0] == '_') { if (node->name[0] == '_') {
error = ovsdb_syntax_error(json, NULL, "names beginning with " error = ovsdb_syntax_error(json, NULL, "names beginning with "
"\"_\" are reserved"); "\"_\" are reserved");
} else if (!ovsdb_parser_is_id(node->name)) {
error = ovsdb_syntax_error(json, NULL, "name must be a valid id");
} else { } else {
error = ovsdb_column_from_json(node->data, node->name, &column); error = ovsdb_column_from_json(node->data, node->name, &column);
} }

View File

@ -160,6 +160,6 @@
"certificate": { "certificate": {
"comment": "Name of a PEM file containing a certificate, signed by the certificate authority (CA) used by the controller and manager, that certifies the switch's private key, identifying a trustworthy switch.", "comment": "Name of a PEM file containing a certificate, signed by the certificate authority (CA) used by the controller and manager, that certifies the switch's private key, identifying a trustworthy switch.",
"type": "string"}, "type": "string"},
"ca-cert": { "ca_cert": {
"comment": "Name of a PEM file containing the CA certificate used to verify that the switch is connected to a trustworthy controller.", "comment": "Name of a PEM file containing the CA certificate used to verify that the switch is connected to a trustworthy controller.",
"type": "string"}}}}} "type": "string"}}}}}