Skip to content

Commit 51eac76

Browse files
cmd/jwk: check return from jose_jwk_thp_buf() properly
jose_jwk_thp_buf() returns, on success, the number of bytes written; otherwise, it returns SIZE_MAX. We now check its return properly, from jcmd_jwk_thp(), which is used by the CLI utility. While at it, let us also initialize the dec/enc buffers. Signed-off-by: Sergio Correia <[email protected]>
1 parent 874c665 commit 51eac76

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cmd/jwk/thp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,17 @@ jcmd_jwk_thp(int argc, char *argv[])
144144
const json_t *jwk = json_array_get(opt.keys, i);
145145

146146
for (const jose_hook_alg_t *a = jose_hook_alg_list(); a; a = a->next) {
147-
uint8_t dec[dlen];
148-
char enc[elen];
147+
uint8_t dec[dlen] = {};
148+
char enc[elen] = {};
149149

150150
if (a->kind != JOSE_HOOK_ALG_KIND_HASH)
151151
continue;
152152

153153
if (!opt.find && strcmp(opt.hash, a->name) != 0)
154154
continue;
155155

156-
if (!jose_jwk_thp_buf(NULL, jwk, opt.hash, dec, sizeof(dec))) {
156+
size_t nbytes = jose_jwk_thp_buf(NULL, jwk, opt.hash, dec, sizeof(dec));
157+
if (nbytes == 0 || nbytes == SIZE_MAX) {
157158
fprintf(stderr, "Error making thumbprint!\n");
158159
return EXIT_FAILURE;
159160
}

0 commit comments

Comments
 (0)