From 196accb9b79d39029a9ee07d1191eedf9d588127 Mon Sep 17 00:00:00 2001 From: Nicolas Tsiftes Date: Mon, 20 Aug 2018 15:21:36 +0200 Subject: [PATCH] Check if too many relations are inserted. --- os/storage/antelope/aql-adt.c | 15 +++++++++++++++ os/storage/antelope/aql.h | 7 ++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/os/storage/antelope/aql-adt.c b/os/storage/antelope/aql-adt.c index d78f3f3c5..e07bffd7a 100644 --- a/os/storage/antelope/aql-adt.c +++ b/os/storage/antelope/aql-adt.c @@ -90,6 +90,21 @@ aql_clear(aql_adt_t *adt) memset(adt->aggregators, 0, sizeof(adt->aggregators)); } +db_result_t +aql_add_relation(aql_adt_t *adt, const char *name) +{ + if(adt->relation_count >= AQL_RELATION_LIMIT) { + return DB_LIMIT_ERROR; + } + + strncpy(adt->relations[adt->relation_count], name, + sizeof(adt->relations[0]) - 1); + adt->relations[adt->relation_count][sizeof(adt->relations[0]) - 1] = '\0'; + adt->relation_count++; + + return DB_OK; +} + db_result_t aql_add_attribute(aql_adt_t *adt, char *name, domain_t domain, unsigned element_size, int processed_only) diff --git a/os/storage/antelope/aql.h b/os/storage/antelope/aql.h index ab29f7e5d..4b898c4ac 100644 --- a/os/storage/antelope/aql.h +++ b/os/storage/antelope/aql.h @@ -188,10 +188,10 @@ typedef struct aql_adt aql_adt_t; #define AQL_SET_FLAG(adt, flag) (((adt)->flags) |= (flag)) #define AQL_GET_FLAGS(adt) ((adt)->flags) -#define AQL_ADD_RELATION(adt, rel) \ - strcpy((adt)->relations[(adt)->relation_count++], (rel)) #define AQL_RELATION_COUNT(adt) ((adt)->relation_count) -#define AQL_ADD_ATTRIBUTE(adt, attr, dom, size) \ +#define AQL_ADD_RELATION(adt, name) \ + aql_add_relation(adt, name) +#define AQL_ADD_ATTRIBUTE(adt, attr, dom, size) \ aql_add_attribute(adt, attr, dom, size, 0) #define AQL_ADD_PROCESSING_ATTRIBUTE(adt, attr) \ aql_add_attribute((adt), (attr), DOMAIN_UNSPECIFIED, 0, 1) @@ -211,6 +211,7 @@ void lexer_rewind(lexer_t *); void aql_clear(aql_adt_t *adt); aql_status_t aql_parse(aql_adt_t *adt, char *query_string); +db_result_t aql_add_relation(aql_adt_t *adt, const char *name); db_result_t aql_add_attribute(aql_adt_t *adt, char *name, domain_t domain, unsigned element_size, int processed_only);