]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curlx_base64_encode: use uint8_t* for input
authorStefan Eissing <stefan@eissing.org>
Thu, 27 Nov 2025 12:18:09 +0000 (13:18 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 27 Nov 2025 13:35:01 +0000 (14:35 +0100)
Change `inputbuff` parameter from `const char *` to `const uint8_t *` to
reflect the binary nature of the input bytes. Half the code was casting
unsigned char to signed already in calling.

Closes #19722

19 files changed:
lib/curl_sasl.c
lib/curlx/base64.c
lib/curlx/base64.h
lib/http.c
lib/http2.c
lib/http_ntlm.c
lib/ldap.c
lib/openldap.c
lib/vauth/digest.c
lib/vauth/spnego_sspi.c
lib/vssh/libssh2.c
lib/vtls/openssl.c
lib/vtls/vtls.c
lib/vtls/wolfssl.c
lib/vtls/x509asn1.c
lib/ws.c
src/tool_ssls.c
src/var.c
tests/unit/unit1302.c

index 1c9f259de47141ac9f0e151acd6ef4aec918ba53..f6ec668bfd45acd20862ebb4aa584179247e7fe8 100644 (file)
@@ -267,7 +267,7 @@ static CURLcode build_message(struct SASL *sasl, struct bufref *msg)
       char *base64;
       size_t base64len;
 
-      result = curlx_base64_encode((const char *) Curl_bufref_ptr(msg),
+      result = curlx_base64_encode(Curl_bufref_ptr(msg),
                                    Curl_bufref_len(msg), &base64, &base64len);
       if(!result)
         Curl_bufref_set(msg, base64, base64len, curl_free);
index ef07243dd3c5f14694cfa3bbdaa4e487168da2f5..3fcd709d1ce8bea3b9e3a7c790d707f4f55a74e4 100644 (file)
@@ -66,7 +66,7 @@ static const unsigned char decodetable[] =
  * @unittest: 1302
  */
 CURLcode curlx_base64_decode(const char *src,
-                             unsigned char **outptr, size_t *outlen)
+                             uint8_t **outptr, size_t *outlen)
 {
   size_t srclen = 0;
   size_t padding = 0;
@@ -170,8 +170,8 @@ bad:
 }
 
 static CURLcode base64_encode(const char *table64,
-                              unsigned char padbyte,
-                              const char *inputbuff, size_t insize,
+                              uint8_t padbyte,
+                              const uint8_t *inputbuff, size_t insize,
                               char **outptr, size_t *outlen)
 {
   char *output;
@@ -245,7 +245,7 @@ static CURLcode base64_encode(const char *table64,
  *
  * @unittest: 1302
  */
-CURLcode curlx_base64_encode(const char *inputbuff, size_t insize,
+CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize,
                              char **outptr, size_t *outlen)
 {
   return base64_encode(Curl_base64encdec, '=',
@@ -267,7 +267,7 @@ CURLcode curlx_base64_encode(const char *inputbuff, size_t insize,
  *
  * @unittest: 1302
  */
-CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize,
+CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize,
                                 char **outptr, size_t *outlen)
 {
   return base64_encode(base64url, 0, inputbuff, insize, outptr, outlen);
index 31cfcb36e76739d645c875b38e996ed58cd4caa2..3c97ecc9fec11c2df5c809415d99cd9d86abcef5 100644 (file)
  *
  ***************************************************************************/
 
-CURLcode curlx_base64_encode(const char *inputbuff, size_t insize,
+CURLcode curlx_base64_encode(const uint8_t *inputbuff, size_t insize,
                              char **outptr, size_t *outlen);
-CURLcode curlx_base64url_encode(const char *inputbuff, size_t insize,
+CURLcode curlx_base64url_encode(const uint8_t *inputbuff, size_t insize,
                                 char **outptr, size_t *outlen);
 CURLcode curlx_base64_decode(const char *src,
-                             unsigned char **outptr, size_t *outlen);
+                             uint8_t **outptr, size_t *outlen);
 
 extern const char Curl_base64encdec[];
 
index 0319be3b657b9c1b3450002aaa0e86f32141d9c9..672183db0ef26121c2c90bd83787d953b34bb178 100644 (file)
@@ -367,7 +367,8 @@ static CURLcode http_output_basic(struct Curl_easy *data, bool proxy)
   if(!out)
     return CURLE_OUT_OF_MEMORY;
 
-  result = curlx_base64_encode(out, strlen(out), &authorization, &size);
+  result = curlx_base64_encode((uint8_t *)out, strlen(out),
+                               &authorization, &size);
   if(result)
     goto fail;
 
index 4f5f5ea52dd30a37b90b12f6b252b672990add41..4f49efe768b4f2af4f4a5737018709a1f35d3c6b 100644 (file)
@@ -1847,8 +1847,7 @@ CURLcode Curl_http2_request_upgrade(struct dynbuf *req,
     return CURLE_FAILED_INIT;
   }
 
-  result = curlx_base64url_encode((const char *)binsettings, binlen,
-                                  &base64, &blen);
+  result = curlx_base64url_encode(binsettings, binlen, &base64, &blen);
   if(result) {
     curlx_dyn_free(req);
     return result;
index fa375b49bfc6670228caf10a1982b91a361ba104..8cb6403fdb8bd9dbda7451c7963d177ebf2c0de9 100644 (file)
@@ -205,7 +205,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
                                                  hostname, ntlm, &ntlmmsg);
     if(!result) {
       DEBUGASSERT(Curl_bufref_len(&ntlmmsg) != 0);
-      result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg),
+      result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg),
                                   Curl_bufref_len(&ntlmmsg), &base64, &len);
       if(!result) {
         free(*allocuserpwd);
@@ -224,7 +224,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
     result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp,
                                                  ntlm, &ntlmmsg);
     if(!result && Curl_bufref_len(&ntlmmsg)) {
-      result = curlx_base64_encode((const char *) Curl_bufref_ptr(&ntlmmsg),
+      result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg),
                                    Curl_bufref_len(&ntlmmsg), &base64, &len);
       if(!result) {
         free(*allocuserpwd);
index fa1a4a4d25c512b01c4daa6c6f90d73f7abe6a61..7f2af366432568583ebffe5d34aa41ae552e3bd5 100644 (file)
@@ -626,7 +626,8 @@ static CURLcode ldap_do(struct Curl_easy *data, bool *done)
              curl_strequal(";binary", attr + (attr_len - 7)) ) {
             /* Binary attribute, encode to base64. */
             if(vals[i]->bv_len) {
-              result = curlx_base64_encode(vals[i]->bv_val, vals[i]->bv_len,
+              result = curlx_base64_encode((uint8_t *)vals[i]->bv_val,
+                                           vals[i]->bv_len,
                                            &val_b64, &val_b64_sz);
               if(result) {
                 ldap_value_free_len(vals);
index 41419df21b2003eee94454d0b041b3d31fd775b8..806ccb33ccd172586dd2b887f94be9a682feb6cd 100644 (file)
@@ -1213,7 +1213,8 @@ static CURLcode oldap_recv(struct Curl_easy *data, int sockindex, char *buf,
 
           /* Binary value, encode to base64. */
           if(bvals[i].bv_len)
-            result = curlx_base64_encode(bvals[i].bv_val, bvals[i].bv_len,
+            result = curlx_base64_encode((uint8_t *)bvals[i].bv_val,
+                                         bvals[i].bv_len,
                                          &val_b64, &val_b64_sz);
           if(!result)
             result = client_write(data, STRCONST(": "), val_b64, val_b64_sz,
index c1c0ab2ab2195095d45ee88ef4287244a5c82a3c..16045707fd1ea4ae74399b1576736066607f7e5c 100644 (file)
@@ -710,7 +710,7 @@ static CURLcode auth_create_digest_http_message(
     if(result)
       return result;
 
-    result = curlx_base64_encode(cnoncebuf, sizeof(cnoncebuf),
+    result = curlx_base64_encode((uint8_t *)cnoncebuf, sizeof(cnoncebuf),
                                  &cnonce, &cnonce_sz);
     if(result)
       return result;
index 9cf554d3b06194e5bc90067cf92bd7fc70633674..b36535557bd9105bf636a1d8b689d3c591ceef56 100644 (file)
@@ -301,7 +301,7 @@ CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
                                          char **outptr, size_t *outlen)
 {
   /* Base64 encode the already generated response */
-  CURLcode result = curlx_base64_encode((const char *)nego->output_token,
+  CURLcode result = curlx_base64_encode(nego->output_token,
                                         nego->output_token_length, outptr,
                                         outlen);
   if(!result && (!*outptr || !*outlen)) {
index 1c9fe5ac0154d3ce08aa1131211130ea3e7a19c5..e4ceda8c3494547963143988a083d015ff1a1aa9 100644 (file)
@@ -602,7 +602,7 @@ static CURLcode ssh_check_fingerprint(struct Curl_easy *data,
 
     /* The length of fingerprint is 32 bytes for SHA256.
      * See libssh2_hostkey_hash documentation. */
-    if(curlx_base64_encode(fingerprint, 32, &fingerprint_b64,
+    if(curlx_base64_encode((const uint8_t *)fingerprint, 32, &fingerprint_b64,
                            &fingerprint_b64_len) != CURLE_OK) {
       myssh_state(data, sshc, SSH_SESSION_FREE);
       return CURLE_PEER_FAILED_VERIFICATION;
index 2f526479c5f4062802218e2d676c5151f02c4178..7ff5698e7c306cbaa4db33ef28b72aa677cd2104 100644 (file)
@@ -4132,7 +4132,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl,
   int rv = 1;
 # ifndef HAVE_BORINGSSL_LIKE
   char *inner = NULL;
-  unsigned char *rcs = NULL;
+  uint8_t *rcs = NULL;
   char *outer = NULL;
 # else
   const char *inner = NULL;
@@ -4156,7 +4156,7 @@ static void ossl_trace_ech_retry_configs(struct Curl_easy *data, SSL* ssl,
     char *b64str = NULL;
     size_t blen = 0;
 
-    result = curlx_base64_encode((const char *)rcs, rcl, &b64str, &blen);
+    result = curlx_base64_encode(rcs, rcl, &b64str, &blen);
     if(!result && b64str) {
       infof(data, "ECH: retry_configs %s", b64str);
       free(b64str);
index d116ec91edb39f0f910bbbf230973eeeef843fdd..9c76ca7ed32cf380c7bd49cb0f7dfd6b25af78fe 100644 (file)
@@ -790,7 +790,7 @@ CURLcode Curl_pin_peer_pubkey(struct Curl_easy *data,
                                  sha256sumdigest, CURL_SHA256_DIGEST_LENGTH);
 
     if(!encode)
-      encode = curlx_base64_encode((char *)sha256sumdigest,
+      encode = curlx_base64_encode(sha256sumdigest,
                                    CURL_SHA256_DIGEST_LENGTH,
                                    &cert_hash, &cert_hash_len);
     Curl_safefree(sha256sumdigest);
index c8fc8c4add1a065aeca57af80b0cb926750acb5b..e622f909e50bd320bdac59ec1c32d1ba2167c00b 100644 (file)
@@ -1816,7 +1816,7 @@ static CURLcode wssl_handshake(struct Curl_cfilter *cf,
         char *b64str = NULL;
         size_t blen = 0;
 
-        result = curlx_base64_encode((const char *)echConfigs, echConfigsLen,
+        result = curlx_base64_encode(echConfigs, echConfigsLen,
                                      &b64str, &blen);
         if(!result && b64str)
           infof(data, "ECH: (not yet) retry_configs %s", b64str);
index 96eb512b9038584162b448094e782fc2a8ec0a31..417a5382d873f92e66b71708a07b0bc419310c46 100644 (file)
@@ -1228,7 +1228,7 @@ CURLcode Curl_extract_certinfo(struct Curl_easy *data,
   curlx_dyn_reset(&out);
 
   /* Generate PEM certificate. */
-  result = curlx_base64_encode(cert.certificate.beg,
+  result = curlx_base64_encode((const uint8_t *)cert.certificate.beg,
                                cert.certificate.end - cert.certificate.beg,
                                &certptr, &clen);
   if(result)
index 36191b2fac0d11b09d3f7a00d8c054a0b6db743d..15dc2e9aea7e6f2c5885e60db7444980d62ccb6f 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -1276,7 +1276,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req)
   result = Curl_rand(data, rand, sizeof(rand));
   if(result)
     return result;
-  result = curlx_base64_encode((char *)rand, sizeof(rand), &randstr, &randlen);
+  result = curlx_base64_encode(rand, sizeof(rand), &randstr, &randlen);
   if(result)
     return result;
   DEBUGASSERT(randlen < sizeof(keyval));
index 40e67a8044c948a24f773c65c04f5ef954d3c2ce..2b67be9baaf8b38da12920537362815d4650b010 100644 (file)
@@ -159,7 +159,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr,
           "# This file was generated by libcurl! Edit at your own risk.\n",
           ctx->fp);
 
-  r = curlx_base64_encode((const char *)shmac, shmac_len, &enc, &enc_len);
+  r = curlx_base64_encode(shmac, shmac_len, &enc, &enc_len);
   if(r)
     goto out;
   r = CURLE_WRITE_ERROR;
@@ -168,7 +168,7 @@ static CURLcode tool_ssls_exp(CURL *easy, void *userptr,
   if(EOF == fputc(':', ctx->fp))
     goto out;
   tool_safefree(enc);
-  r = curlx_base64_encode((const char *)sdata, sdata_len, &enc, &enc_len);
+  r = curlx_base64_encode(sdata, sdata_len, &enc, &enc_len);
   if(r)
     goto out;
   r = CURLE_WRITE_ERROR;
index 94d79695acc98bea9c8f538a3877a09280bb2616..5cedf1d24a2c1cbb36381ba535950dd66ecb9cfd 100644 (file)
--- a/src/var.c
+++ b/src/var.c
@@ -150,7 +150,7 @@ static ParameterError varfunc(char *c, /* content */
       if(clen) {
         char *enc;
         size_t elen;
-        CURLcode result = curlx_base64_encode(c, clen, &enc, &elen);
+        CURLcode result = curlx_base64_encode((uint8_t *)c, clen, &enc, &elen);
         if(result) {
           err = PARAM_NO_MEM;
           break;
index 2c4404d72702ff7e91e69062d9990c1e0aaa9ea3..911432a8c833ba7a7be2fbe28aef5d14a41187ad 100644 (file)
@@ -133,7 +133,7 @@ static CURLcode test_unit1302(const char *arg)
     size_t dlen;
 
     /* first encode */
-    rc = curlx_base64_encode(e->input, e->ilen, &out, &olen);
+    rc = curlx_base64_encode((const uint8_t *)e->input, e->ilen, &out, &olen);
     abort_unless(rc == CURLE_OK, "return code should be CURLE_OK");
     abort_unless(olen == e->olen, "wrong output size");
     if(memcmp(out, e->output, e->olen)) {
@@ -166,7 +166,8 @@ static CURLcode test_unit1302(const char *arg)
     struct etest *e = &url[i];
     char *out;
     size_t olen;
-    rc = curlx_base64url_encode(e->input, e->ilen, &out, &olen);
+    rc = curlx_base64url_encode((const uint8_t *)e->input, e->ilen,
+                                &out, &olen);
     abort_unless(rc == CURLE_OK, "return code should be CURLE_OK");
     if(olen != e->olen) {
       curl_mfprintf(stderr, "Test %u URL encoded output length %zu "