[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch ] (Now complete) Use inttypes macros for size_t format string


Hi there,

I changed all `%zu` into `PRIuS` makro.

Compiles on Linux glibc and MinGW... My server linked against the MinGW
lib / DLL works fine. I didn't do more tests though.

Should be tested on real Win, OS X, and ... ?

Best regards,
Till

From 9253a8609f1716b8c5173822710d3c7710af51f7 Mon Sep 17 00:00:00 2001
From: Till Wimmer <g4-lisz@xxxxxxxxxxxx>
Date: Wed, 15 Jan 2020 17:26:55 +0100
Subject: [PATCH] Use inttypes macros for size_t format string

Signed-off-by: Till Wimmer <g4-lisz@xxxxxxxxxxxx>
---
 include/libssh/priv.h       | 6 +++---
 src/bignum.c                | 4 ++--
 src/buffer.c                | 6 +++---
 src/channels.c              | 6 +++---
 src/curve25519.c            | 2 +-
 src/dh-gex.c                | 6 +++---
 src/gssapi.c                | 6 +++---
 src/libcrypto.c             | 4 ++--
 src/libmbedcrypto.c         | 8 ++++----
 src/misc.c                  | 2 +-
 src/packet.c                | 8 ++++----
 src/packet_crypt.c          | 2 +-
 src/pki_container_openssh.c | 6 +++---
 src/pki_ed25519_common.c    | 2 +-
 src/sftp.c                  | 4 ++--
 15 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index 31405d6b..cfca4581 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -66,8 +66,8 @@ char *strndup(const char *s, size_t n);
 #ifdef _WIN32
 
 /* Imitate define of inttypes.h */
-# ifndef PRIdS
-#  define PRIdS "Id"
+# ifndef PRIuS
+#  define PRIuS "Iu"
 # endif
 
 # ifndef PRIu64
@@ -162,7 +162,7 @@ int gettimeofday(struct timeval *__p, void *__t);
 #else /* _WIN32 */
 
 #include <unistd.h>
-#define PRIdS "zd"
+#define PRIuS "zu"
 
 #define _XCLOSESOCKET close
 
diff --git a/src/bignum.c b/src/bignum.c
index ef8de31f..f89995ad 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -44,7 +44,7 @@ ssh_string ssh_make_bignum_string(bignum num) {
 
 #ifdef DEBUG_CRYPTO
   SSH_LOG(SSH_LOG_TRACE,
-          "%zu bits, %zu bytes, %zu padding\n",
+          "%" PRIuS " bits, %" PRIuS " bytes, %" PRIuS " padding\n",
           bits, len, pad);
 #endif /* DEBUG_CRYPTO */
 
@@ -70,7 +70,7 @@ bignum ssh_make_string_bn(ssh_string string)
 
 #ifdef DEBUG_CRYPTO
     SSH_LOG(SSH_LOG_TRACE,
-            "Importing a %zu bits, %zu bytes object ...\n",
+            "Importing a %" PRIuS " bits, %" PRIuS " bytes object ...\n",
             len * 8, len);
 #endif /* DEBUG_CRYPTO */
 
diff --git a/src/buffer.c b/src/buffer.c
index a2e6246a..5ab37fc6 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -83,21 +83,21 @@ static void buffer_verify(ssh_buffer buf)
 
     if (buf->used > buf->allocated) {
         fprintf(stderr,
-                "BUFFER ERROR: allocated %zu, used %zu\n",
+                "BUFFER ERROR: allocated %" PRIuS ", used %" PRIuS "\n",
                 buf->allocated,
                 buf->used);
         do_abort = true;
     }
     if (buf->pos > buf->used) {
         fprintf(stderr,
-                "BUFFER ERROR: position %zu, used %zu\n",
+                "BUFFER ERROR: position %" PRIuS ", used %" PRIuS "\n",
                 buf->pos,
                 buf->used);
         do_abort = true;
     }
     if (buf->pos > buf->allocated) {
         fprintf(stderr,
-                "BUFFER ERROR: position %zu, allocated %zu\n",
+                "BUFFER ERROR: position %" PRIuS ", allocated %" PRIuS "\n",
                 buf->pos,
                 buf->allocated);
         do_abort = true;
diff --git a/src/channels.c b/src/channels.c
index a670d895..50a606bc 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -544,7 +544,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
   len = ssh_string_len(str);
 
   SSH_LOG(SSH_LOG_PACKET,
-      "Channel receiving %" PRIdS " bytes data in %d (local win=%d remote win=%d)",
+      "Channel receiving %" PRIuS " bytes data in %d (local win=%d remote win=%d)",
       len,
       is_stderr,
       channel->local_window,
@@ -553,7 +553,7 @@ SSH_PACKET_CALLBACK(channel_rcv_data){
   /* What shall we do in this case? Let's accept it anyway */
   if (len > channel->local_window) {
     SSH_LOG(SSH_LOG_RARE,
-        "Data packet too big for our window(%" PRIdS " vs %d)",
+        "Data packet too big for our window(%" PRIuS " vs %d)",
         len,
         channel->local_window);
   }
@@ -862,7 +862,7 @@ int channel_default_bufferize(ssh_channel channel,
   }
 
   SSH_LOG(SSH_LOG_PACKET,
-          "placing %zu bytes into channel buffer (%s)",
+          "placing %" PRIuS " bytes into channel buffer (%s)",
           len,
           is_stderr ? "stderr" : "stdout");
   if (!is_stderr) {
diff --git a/src/curve25519.c b/src/curve25519.c
index 1d482a71..362f8a2b 100644
--- a/src/curve25519.c
+++ b/src/curve25519.c
@@ -403,7 +403,7 @@ static SSH_PACKET_CALLBACK(ssh_packet_server_curve25519_init){
     if (ssh_string_len(q_c_string) != CURVE25519_PUBKEY_SIZE){
         ssh_set_error(session,
                       SSH_FATAL,
-                      "Incorrect size for server Curve25519 public key: %zu",
+                      "Incorrect size for server Curve25519 public key: %" PRIuS,
                       ssh_string_len(q_c_string));
         SSH_STRING_FREE(q_c_string);
         goto error;
diff --git a/src/dh-gex.c b/src/dh-gex.c
index 6c75c69e..01765eaf 100644
--- a/src/dh-gex.c
+++ b/src/dh-gex.c
@@ -405,7 +405,7 @@ static int ssh_retrieve_dhgroup_file(FILE *moduli,
         }
         ungetc(firstbyte, moduli);
         rc = fscanf(moduli,
-                    "%31s %zu %zu %zu %zu %31s %4095s\n",
+                    "%31s %"PRIuS" %"PRIuS" %"PRIuS" %"PRIuS" %31s %4095s\n",
                     timestamp,
                     &type,
                     &tests,
@@ -417,7 +417,7 @@ static int ssh_retrieve_dhgroup_file(FILE *moduli,
             if (rc == EOF) {
                 break;
             }
-            SSH_LOG(SSH_LOG_INFO, "Invalid moduli entry line %zu", line);
+            SSH_LOG(SSH_LOG_INFO, "Invalid moduli entry line %" PRIuS, line);
             do {
                 firstbyte = getc(moduli);
             } while(firstbyte != '\n' && firstbyte != EOF);
@@ -456,7 +456,7 @@ static int ssh_retrieve_dhgroup_file(FILE *moduli,
     }
     if (*best_size != 0) {
         SSH_LOG(SSH_LOG_INFO,
-                "Selected %zu bits modulus out of %zu candidates in %zu lines",
+                "Selected %" PRIuS " bits modulus out of %" PRIuS " candidates in %" PRIuS " lines",
                 *best_size,
                 best_nlines - 1,
                 line);
diff --git a/src/gssapi.c b/src/gssapi.c
index 488df582..095ce508 100644
--- a/src/gssapi.c
+++ b/src/gssapi.c
@@ -228,7 +228,7 @@ int ssh_gssapi_handle_userauth(ssh_session session, const char *user, uint32_t n
 
     for (i=0; i < supported->count; ++i){
         ptr = ssh_get_hexa(supported->elements[i].elements, supported->elements[i].length);
-        SSH_LOG(SSH_LOG_DEBUG, "Supported mech %zu: %s", i, ptr);
+        SSH_LOG(SSH_LOG_DEBUG, "Supported mech %" PRIuS ": %s", i, ptr);
         free(ptr);
     }
 
@@ -309,7 +309,7 @@ int ssh_gssapi_handle_userauth(ssh_session session, const char *user, uint32_t n
         oid.length = len - 2;
         gss_test_oid_set_member(&min_stat,&oid,selected,&present);
         if(present){
-            SSH_LOG(SSH_LOG_PACKET, "Selected oid %zu", i);
+            SSH_LOG(SSH_LOG_PACKET, "Selected oid %" PRIuS, i);
             break;
         }
     }
@@ -762,7 +762,7 @@ int ssh_gssapi_auth_mic(ssh_session session){
     }
 
     n_oids = selected->count;
-    SSH_LOG(SSH_LOG_PROTOCOL, "Sending %zu oids", n_oids);
+    SSH_LOG(SSH_LOG_PROTOCOL, "Sending %" PRIuS " oids", n_oids);
 
     oids = calloc(n_oids, sizeof(ssh_string));
     if (oids == NULL) {
diff --git a/src/libcrypto.c b/src/libcrypto.c
index dc3a24d5..39bf3fa8 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -618,7 +618,7 @@ static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
     }
     if (outlen != (int)len){
         SSH_LOG(SSH_LOG_WARNING,
-                "EVP_EncryptUpdate: output size %d for %zu in",
+                "EVP_EncryptUpdate: output size %d for %" PRIuS " in",
                 outlen,
                 len);
         return;
@@ -644,7 +644,7 @@ static void evp_cipher_decrypt(struct ssh_cipher_struct *cipher,
     }
     if (outlen != (int)len){
         SSH_LOG(SSH_LOG_WARNING,
-                "EVP_DecryptUpdate: output size %d for %zu in",
+                "EVP_DecryptUpdate: output size %d for %" PRIuS " in",
                 outlen,
                 len);
         return;
diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c
index 755c5ebe..f5cf4ef5 100644
--- a/src/libmbedcrypto.c
+++ b/src/libmbedcrypto.c
@@ -679,7 +679,7 @@ static void cipher_encrypt(struct ssh_cipher_struct *cipher,
     }
 
     if (total_len != len) {
-        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %zu for %zu",
+        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %" PRIuS " for %" PRIuS,
                 outlen, len);
         return;
     }
@@ -698,7 +698,7 @@ static void cipher_encrypt_cbc(struct ssh_cipher_struct *cipher, void *in, void
     }
 
     if (outlen != len) {
-        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %zu for %zu",
+        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %" PRIuS " for %" PRIuS,
                 outlen, len);
         return;
     }
@@ -737,7 +737,7 @@ static void cipher_decrypt(struct ssh_cipher_struct *cipher,
     total_len += outlen;
 
     if (total_len != len) {
-        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %zu for %zu",
+        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %" PRIuS " for %" PRIuS,
                 outlen, len);
         return;
     }
@@ -782,7 +782,7 @@ static void cipher_decrypt_cbc(struct ssh_cipher_struct *cipher, void *in, void
     }
 
     if (outlen != len) {
-        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %zu for %zu",
+        SSH_LOG(SSH_LOG_WARNING, "mbedtls_cipher_update: output size %" PRIuS " for %" PRIuS,
                 outlen, len);
         return;
     }
diff --git a/src/misc.c b/src/misc.c
index affb3eb4..1dc6cfda 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -516,7 +516,7 @@ void ssh_log_hexdump(const char *descr, const unsigned char *what, size_t len)
         return;
     } else {
         printed = snprintf(buffer + count, sizeof(buffer) - count,
-                           "(%zu bytes):", len);
+                           "(%" PRIuS " bytes):", len);
         if (printed < 0) {
             goto error;
         }
diff --git a/src/packet.c b/src/packet.c
index e9ae5648..bdc748a7 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -1105,7 +1105,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
     }
 #ifdef DEBUG_PACKET
     SSH_LOG(SSH_LOG_PACKET,
-            "rcv packet cb (len=%zu, state=%s)",
+            "rcv packet cb (len=%" PRIuS ", state=%s)",
             receivedlen,
             session->packet_state == PACKET_STATE_INIT ?
                 "INIT" :
@@ -1123,7 +1123,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
                  */
 #ifdef DEBUG_PACKET
                 SSH_LOG(SSH_LOG_PACKET,
-                        "Waiting for more data (%zu < %u)",
+                        "Waiting for more data (%" PRIuS " < %u)",
                         receivedlen,
                         lenfield_blocksize);
 #endif
@@ -1352,7 +1352,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
             if (processed < receivedlen) {
                 /* Handle a potential packet left in socket buffer */
                 SSH_LOG(SSH_LOG_PACKET,
-                        "Processing %" PRIdS " bytes left in socket buffer",
+                        "Processing %" PRIuS " bytes left in socket buffer",
                         receivedlen-processed);
 
                 ptr = ((uint8_t*)data) + processed;
@@ -1384,7 +1384,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
 
 error:
     session->session_state= SSH_SESSION_STATE_ERROR;
-    SSH_LOG(SSH_LOG_PACKET,"Packet: processed %" PRIdS " bytes", processed);
+    SSH_LOG(SSH_LOG_PACKET,"Packet: processed %" PRIuS " bytes", processed);
     return processed;
 }
 
diff --git a/src/packet_crypt.c b/src/packet_crypt.c
index 168fcc72..3aa4c09d 100644
--- a/src/packet_crypt.c
+++ b/src/packet_crypt.c
@@ -112,7 +112,7 @@ int ssh_packet_decrypt(ssh_session session,
         ssh_set_error(session,
                       SSH_FATAL,
                       "Cryptographic functions must be used on multiple of "
-                      "blocksize (received %" PRIdS ")",
+                      "blocksize (received %" PRIuS ")",
                       encrypted_size);
         return SSH_ERROR;
     }
diff --git a/src/pki_container_openssh.c b/src/pki_container_openssh.c
index ecde4cdd..e68cc474 100644
--- a/src/pki_container_openssh.c
+++ b/src/pki_container_openssh.c
@@ -144,7 +144,7 @@ static int pki_private_key_decrypt(ssh_string blob,
     }
     if (ssh_string_len(blob) % cipher.blocksize != 0) {
         SSH_LOG(SSH_LOG_WARN,
-                "Encrypted string not multiple of blocksize: %zu",
+                "Encrypted string not multiple of blocksize: %" PRIuS,
                 ssh_string_len(blob));
         return SSH_ERROR;
     }
@@ -172,7 +172,7 @@ static int pki_private_key_decrypt(ssh_string blob,
     }
 
     SSH_LOG(SSH_LOG_DEBUG,
-            "Decryption: %d key, %d IV, %d rounds, %zu bytes salt",
+            "Decryption: %d key, %d IV, %d rounds, %" PRIuS " bytes salt",
             cipher.keysize/8,
             cipher.blocksize,
             rounds,
@@ -478,7 +478,7 @@ static int pki_private_key_encrypt(ssh_buffer privkey_buffer,
         return SSH_ERROR;
     }
 
-    SSH_LOG(SSH_LOG_WARN, "Encryption: %d key, %d IV, %d rounds, %zu bytes salt",
+    SSH_LOG(SSH_LOG_WARN, "Encryption: %d key, %d IV, %d rounds, %" PRIuS " bytes salt",
                 cipher.keysize/8,
                 cipher.blocksize, rounds, ssh_string_len(salt));
 
diff --git a/src/pki_ed25519_common.c b/src/pki_ed25519_common.c
index 738825f5..6b11eac0 100644
--- a/src/pki_ed25519_common.c
+++ b/src/pki_ed25519_common.c
@@ -261,7 +261,7 @@ int pki_signature_from_ed25519_blob(ssh_signature sig, ssh_string sig_blob)
 
     len = ssh_string_len(sig_blob);
     if (len != ED25519_SIG_LEN){
-        SSH_LOG(SSH_LOG_WARN, "Invalid ssh-ed25519 signature len: %zu", len);
+        SSH_LOG(SSH_LOG_WARN, "Invalid ssh-ed25519 signature len: %" PRIuS, len);
         return SSH_ERROR;
     }
 
diff --git a/src/sftp.c b/src/sftp.c
index b64aad61..afe33eeb 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -1982,7 +1982,7 @@ ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
       if (datalen > count) {
         ssh_set_error(sftp->session, SSH_FATAL,
             "Received a too big DATA packet from sftp server: "
-            "%" PRIdS " and asked for %" PRIdS,
+            "%" PRIuS " and asked for %" PRIuS,
             datalen, count);
         SSH_STRING_FREE(datastring);
         return -1;
@@ -2104,7 +2104,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
       if (ssh_string_len(datastring) > size) {
         ssh_set_error(sftp->session, SSH_FATAL,
             "Received a too big DATA packet from sftp server: "
-            "%" PRIdS " and asked for %u",
+            "%" PRIuS " and asked for %u",
             ssh_string_len(datastring), size);
         SSH_STRING_FREE(datastring);
         return SSH_ERROR;
-- 
2.20.1


Archive administrator: postmaster@lists.cynapses.org