diff mbox series

[6/9] libtraceveal: Add type checks to traceeval_data vals and keys

Message ID 20230817222422.118568-7-rostedt@goodmis.org (mailing list archive)
State Superseded
Headers show
Series libtraceeval: Even more updates! | expand

Commit Message

Steven Rostedt Aug. 17, 2023, 10:24 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Now that the traceeval_data has a type, add checks to traceeval_insert()
and traceveal_query() as well as traceeval_stat() to make sure the keys
and vals match the types that were for the traceeval.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/histograms.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Ross Zwisler Aug. 24, 2023, 9:23 p.m. UTC | #1
On Thu, Aug 17, 2023 at 06:24:19PM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Now that the traceeval_data has a type, add checks to traceeval_insert()
> and traceveal_query() as well as traceeval_stat() to make sure the keys
> and vals match the types that were for the traceeval.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  src/histograms.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/src/histograms.c b/src/histograms.c
> index 7c0eef6cf421..560046cc8d96 100644
> --- a/src/histograms.c
> +++ b/src/histograms.c
> @@ -479,10 +479,16 @@ static int get_entry(struct traceeval *teval, const struct traceeval_data *keys,
>  	struct hash_item *item;
>  	unsigned key;
>  	int check = 0;
> +	int i;
>  
>  	if (!teval || !keys)
>  		return -1;
>  
> +	for (i = 0; i < teval->nr_key_types; i++) {
> +		if (keys[i].type != teval->key_types[i].type)
> +			return -1;
> +	}
> +
>  	key = make_hash(teval, keys, hist->bits);
>  
>  	for (iter = hash_iter_bucket(hist, key); (item = hash_iter_bucket_next(iter)); ) {
> @@ -928,10 +934,16 @@ int traceeval_insert(struct traceeval *teval,
>  {
>  	struct entry *entry;
>  	int check;
> +	int i;
>  
>  	entry = NULL;
>  	check = get_entry(teval, keys, &entry);
>  
> +	for (i = 0; i < teval->nr_val_types; i++) {
> +		if (vals[i].type != teval->val_types[i].type)
> +			return -1;
> +	}

I think we should have a similar type check in the update path, so do all the
checks in a loop like this in update_entry(), or we can check each entry
individually in copy_traceeval_data().

That will make sure we don't update an entry with mismatched typed values.

> +
>  	if (check == -1)
>  		return check;
>  
> -- 
> 2.40.1
>
diff mbox series

Patch

diff --git a/src/histograms.c b/src/histograms.c
index 7c0eef6cf421..560046cc8d96 100644
--- a/src/histograms.c
+++ b/src/histograms.c
@@ -479,10 +479,16 @@  static int get_entry(struct traceeval *teval, const struct traceeval_data *keys,
 	struct hash_item *item;
 	unsigned key;
 	int check = 0;
+	int i;
 
 	if (!teval || !keys)
 		return -1;
 
+	for (i = 0; i < teval->nr_key_types; i++) {
+		if (keys[i].type != teval->key_types[i].type)
+			return -1;
+	}
+
 	key = make_hash(teval, keys, hist->bits);
 
 	for (iter = hash_iter_bucket(hist, key); (item = hash_iter_bucket_next(iter)); ) {
@@ -928,10 +934,16 @@  int traceeval_insert(struct traceeval *teval,
 {
 	struct entry *entry;
 	int check;
+	int i;
 
 	entry = NULL;
 	check = get_entry(teval, keys, &entry);
 
+	for (i = 0; i < teval->nr_val_types; i++) {
+		if (vals[i].type != teval->val_types[i].type)
+			return -1;
+	}
+
 	if (check == -1)
 		return check;