{
struct sample alg_smp, key_smp;
enum jwt_vrfy_status ret;
+ struct buffer *input = NULL;
+ struct buffer *alg = NULL;
+ struct buffer *key = NULL;
+ int retval = 0;
+
+ /* The two following calls to 'sample_conv_var2smp_str' will both make
+ * use of the preallocated trash buffer (via get_trash_chunk call in
+ * smp_dup) which would end up erasing the contents of the 'smp' input
+ * buffer.
+ */
+ input = alloc_trash_chunk();
+ if (!input)
+ return 0;
+ alg = alloc_trash_chunk();
+ if (!alg)
+ goto end;
+ key = alloc_trash_chunk();
+ if (!key)
+ goto end;
+
+ if (!chunk_cpy(input, &smp->data.u.str))
+ goto end;
smp_set_owner(&alg_smp, smp->px, smp->sess, smp->strm, smp->opt);
- smp_set_owner(&key_smp, smp->px, smp->sess, smp->strm, smp->opt);
if (!sample_conv_var2smp_str(&args[0], &alg_smp))
- return 0;
+ goto end;
+ if (chunk_printf(alg, "%.*s", (int)b_data(&alg_smp.data.u.str), b_orig(&alg_smp.data.u.str)) <= 0)
+ goto end;
+
+ smp_set_owner(&key_smp, smp->px, smp->sess, smp->strm, smp->opt);
if (!sample_conv_var2smp_str(&args[1], &key_smp))
- return 0;
+ goto end;
+ if (chunk_printf(key, "%.*s", (int)b_data(&key_smp.data.u.str), b_orig(&key_smp.data.u.str)) <= 0)
+ goto end;
- ret = jwt_verify(&smp->data.u.str, &alg_smp.data.u.str, &key_smp.data.u.str);
+ ret = jwt_verify(input, alg, key);
smp->data.type = SMP_T_SINT;
smp->data.u.sint = ret;
- return 1;
+
+ retval = 1;
+
+end:
+ free_trash_chunk(input);
+ free_trash_chunk(alg);
+ free_trash_chunk(key);
+ return retval;
}