]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Sync up with libcups code (minor changes).
authorMichael R Sweet <msweet@msweet.org>
Mon, 5 May 2025 22:42:18 +0000 (18:42 -0400)
committerMichael R Sweet <msweet@msweet.org>
Mon, 5 May 2025 22:42:18 +0000 (18:42 -0400)
cups/jwt.c
cups/oauth.c

index 4743a15f89d5839aa3aeefe20ecbfe52e60721a5..d097bdedab8255e809205a2ae3194414e8d2b7ca 100644 (file)
@@ -1,7 +1,7 @@
 //
 // JSON Web Token API implementation for CUPS.
 //
-// Copyright © 2023-2024 by OpenPrinting.
+// Copyright © 2023-2025 by OpenPrinting.
 //
 // Licensed under Apache License v2.0.  See the file "LICENSE" for more
 // information.
@@ -10,6 +10,7 @@
 #include "cups-private.h"
 #include "jwt.h"
 #include "json-private.h"
+#include <assert.h>
 #ifdef HAVE_OPENSSL
 #  include <openssl/ecdsa.h>
 #  include <openssl/evp.h>
@@ -450,6 +451,7 @@ cupsJWTHasValidSignature(
 
 #ifdef HAVE_OPENSSL
         hash_len = cupsHashData(cups_jwa_algorithms[jwt->sigalg], text, text_len, hash, sizeof(hash));
+        assert(hash_len > 0);
 
         if ((rsa = make_rsa(jwk)) != NULL)
         {
@@ -486,6 +488,7 @@ cupsJWTHasValidSignature(
 
 #ifdef HAVE_OPENSSL
         hash_len = cupsHashData(cups_jwa_algorithms[jwt->sigalg], text, text_len, hash, sizeof(hash));
+        assert(hash_len > 0);
 
         if ((ec = make_ec_key(jwk, true)) != NULL)
         {
@@ -2107,6 +2110,8 @@ make_signature(cups_jwt_t    *jwt,        // I  - JWT
     if ((rsa = make_rsa(jwk)) != NULL)
     {
       hash_len = cupsHashData(cups_jwa_algorithms[alg], text, text_len, hash, sizeof(hash));
+      assert(hash_len > 0);
+
       if (RSA_sign(nids[alg - CUPS_JWA_RS256], hash, hash_len, signature, &siglen, rsa) == 1)
       {
         *sigsize = siglen;
@@ -2154,6 +2159,8 @@ make_signature(cups_jwt_t    *jwt,        // I  - JWT
     if ((ec = make_ec_key(jwk, false)) != NULL)
     {
       hash_len = cupsHashData(cups_jwa_algorithms[alg], text, text_len, hash, sizeof(hash));
+      assert(hash_len > 0);
+
       if ((ec_sig = ECDSA_do_sign(hash, hash_len, ec)) != NULL)
       {
         // Get the raw coordinates...
index cd0c0b7447bfff778de40ac91dc2a73d56370d55..c9f8a0ebda1dc87b692390ad2a66b5d286db892e 100644 (file)
@@ -1464,8 +1464,12 @@ oauth_copy_response(http_t *http)        // I - HTTP connection
   // Allocate memory for string...
   initial_state = httpGetState(http);
 
-  if ((bodylen = (size_t)httpGetLength(http)) == 0 || bodylen > 65536)
+  if ((bytes = httpGetLength(http)) < 0)
+    return (NULL);
+  else if (bytes == 0 || bytes > 65536)
     bodylen = 65536;                   // Accept up to 64k for GETs/POSTs
+  else
+    bodylen = (size_t)bytes;
 
   if ((body = calloc(1, bodylen + 1)) != NULL)
   {
@@ -1799,9 +1803,9 @@ oauth_make_path(
 //
 // (Has the advantage of being easily identified, too...)
 //
-// For CUPS 3.0.x:
+// For CUPS 2.5.x:
 //
-//   43555053-0300-8010-8011-4F4175746820
+//   43555053-0205-8010-8011-4F4175746820
 //
 
 static char *                          // O - UUID string