Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ v3.0.3 - YYYY-MM-DD
- Fixed the example RPM spec file (Issue #150)
- Fixed the `ipptool` "get-printer-attributes-suite.test" test file (Issue #154)
- Fixed potential buffer overflow in `cupsCopyDestConflicts`.
- Fixed a buffer overflow in `cupsJWTSign` when the EC key curve did not match the algorithm.


v3.0.2 - 2026-06-05
Expand Down
31 changes: 18 additions & 13 deletions cups/jwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2132,12 +2132,18 @@ make_signature(cups_jwt_t *jwt, // I - JWT
s_len = (unsigned)BN_num_bytes(s);
*sigsize = sig_sizes[alg - CUPS_JWA_ES256];
sig_len = *sigsize / 2;
ret = true;

// 0-pad raw coordinates
memset(signature, 0, *sigsize);
BN_bn2bin(r, signature + sig_len - r_len);
BN_bn2bin(s, signature + *sigsize - s_len);
// The key's curve has to match the algorithm - a larger curve gives
// coordinates that don't fit and `BN_bn2bin` would write before the
// buffer...
if (r_len <= sig_len && s_len <= sig_len)
{
// 0-pad raw coordinates
memset(signature, 0, *sigsize);
BN_bn2bin(r, signature + sig_len - r_len);
BN_bn2bin(s, signature + *sigsize - s_len);
ret = true;
}

// Free the signature
ECDSA_SIG_free(ec_sig);
Expand All @@ -2161,16 +2167,15 @@ make_signature(cups_jwt_t *jwt, // I - JWT
sig_len = *sigsize / 2;
gnutls_decode_rs_value(&sig_datum, &r, &s);

memset(signature, 0, *sigsize);
if (r.size < sig_len)
// The key's curve has to match the algorithm - a larger curve gives
// coordinates that don't fit in the signature...
if (r.size <= sig_len && s.size <= sig_len)
{
memset(signature, 0, *sigsize);
memcpy(signature + sig_len - r.size, r.data, r.size);
else
memcpy(signature, r.data + r.size - sig_len, sig_len);
if (s.size < sig_len)
memcpy(signature + *sigsize - s.size, s.data, s.size);
else
memcpy(signature + sig_len, s.data + s.size - sig_len, sig_len);
ret = true;
ret = true;
}

gnutls_free(r.data);
gnutls_free(s.data);
Expand Down
7 changes: 7 additions & 0 deletions cups/testjwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ main(int argc, // I - Number of command-line arguments
cupsJSONDelete(jwk);
cupsJSONDelete(pubjwk);

// Signing with a key whose curve is larger than the algorithm (ES256 wants
// P-256, this is P-521) has to fail rather than write past the signature...
testBegin("cupsJWTSign(ES256 with mismatched P-521 key)");
jwk = cupsJWTMakePrivateKey(CUPS_JWA_ES512);
testEnd(!cupsJWTSign(jwt, CUPS_JWA_ES256, jwk));
cupsJSONDelete(jwk);

testBegin("cupsJWTDelete()");
cupsJWTDelete(jwt);
testEnd(true);
Expand Down