mirror of
https://github.com/open62541/open62541.git
synced 2025-06-03 04:00:21 +00:00
fix(plugins): Increase token number for JSON config parsing / Fix jumping over unknown elements
If parseJSONConfig() met unknown complex 1st layer item (array or object) it couldn't parse following items correctly since context->index was pointing to the internal elements of unknown item instead of next 1st layer item. So skipUnknownItem() function was added which skip all internal elements of unknown 1st layer item be it object, array of objects, array of array or anything else.
This commit is contained in:
parent
115325d44b
commit
7c500a1242
@ -12,15 +12,15 @@
|
||||
#include "open62541/plugin/certificategroup_default.h"
|
||||
#endif
|
||||
|
||||
#define MAX_TOKENS 256
|
||||
#define MAX_TOKENS 1024
|
||||
|
||||
typedef struct {
|
||||
const char *json;
|
||||
const cj5_token *tokens;
|
||||
cj5_result result;
|
||||
unsigned int tokensSize;
|
||||
size_t tokensSize;
|
||||
size_t index;
|
||||
UA_Byte depth;
|
||||
cj5_result result;
|
||||
} ParsingCtx;
|
||||
|
||||
static UA_ByteString
|
||||
@ -870,6 +870,20 @@ const parseJsonSignature parseJsonJumpTable[UA_SERVERCONFIGFIELDKINDS] = {
|
||||
(parseJsonSignature)RuleHandlingField_parseJson,
|
||||
};
|
||||
|
||||
/* Skips unknown item (simple, object or array) in config file.
|
||||
* Unknown items may happen if we don't support some features.
|
||||
* E.g. if UA_ENABLE_ENCRYPTION is not defined and config file
|
||||
* contains "securityPolicies" entry.
|
||||
*/
|
||||
static void
|
||||
skipUnknownItem(ParsingCtx* ctx) {
|
||||
unsigned int end = ctx->tokens[ctx->index].end;
|
||||
do {
|
||||
ctx->index++;
|
||||
} while (ctx->index < ctx->tokensSize &&
|
||||
ctx->tokens[ctx->index].start < end);
|
||||
}
|
||||
|
||||
static UA_StatusCode
|
||||
parseJSONConfig(UA_ServerConfig *config, UA_ByteString json_config) {
|
||||
// Parsing json config
|
||||
@ -980,7 +994,7 @@ parseJSONConfig(UA_ServerConfig *config, UA_ByteString json_config) {
|
||||
else if(strcmp(field, "pubsubEnabled") == 0)
|
||||
retval = parseJsonJumpTable[UA_SERVERCONFIGFIELD_BOOLEAN](&ctx, &config->pubsubEnabled, NULL);
|
||||
else if(strcmp(field, "pubsub") == 0)
|
||||
retval = parseJsonJumpTable[UA_SERVERCONFIGFIELD_PUBSUBCONFIGURATION](&ctx, config, NULL);
|
||||
retval = parseJsonJumpTable[UA_SERVERCONFIGFIELD_PUBSUBCONFIGURATION](&ctx, &config->pubSubConfig, NULL);
|
||||
#endif
|
||||
#ifdef UA_ENABLE_ENCRYPTION
|
||||
else if(strcmp(field, "securityPolicies") == 0)
|
||||
@ -990,6 +1004,14 @@ parseJSONConfig(UA_ServerConfig *config, UA_ByteString json_config) {
|
||||
#endif
|
||||
else {
|
||||
UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Field name '%s' unknown or misspelled. Maybe the feature is not enabled either.", field);
|
||||
/* skip the name of item */
|
||||
++ctx.index;
|
||||
/* skip value of unknown item */
|
||||
skipUnknownItem(&ctx);
|
||||
/* after skipUnknownItem() ctx->index points to the name of the following item.
|
||||
We must decrement index in oder following increment will
|
||||
still set index to the right position (name of the following item) */
|
||||
--ctx.index;
|
||||
}
|
||||
UA_free(field);
|
||||
if(retval != UA_STATUSCODE_GOOD) {
|
||||
|
Loading…
Reference in New Issue
Block a user