Fixed sign-compare warnings
authorArmin Novak <armin.novak@thincast.com>
Thu, 7 Feb 2019 13:18:02 +0000 (14:18 +0100)
committerArmin Novak <armin.novak@thincast.com>
Fri, 5 Apr 2019 07:13:24 +0000 (09:13 +0200)
libfreerdp/crypto/certificate.c
libfreerdp/crypto/crypto.c
libfreerdp/crypto/tls.c

index 6edbcdb..1898060 100644 (file)
@@ -500,6 +500,8 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store,
                                          certificate_known_hosts_file, pline);
                        else
                        {
+                               int res;
+
                                /* If this is the replaced hostname, use the updated fingerprint. */
                                if ((strcmp(hostname, certificate_data->hostname) == 0) &&
                                    (port == certificate_data->port))
@@ -508,7 +510,15 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store,
                                        rc = TRUE;
                                }
 
-                               size = _snprintf(NULL, 0, "%s %"PRIu16" %s %s %s\n", hostname, port, fingerprint, subject, issuer);
+                               res = _snprintf(NULL, 0, "%s %"PRIu16" %s %s %s\n", hostname, port, fingerprint, subject, issuer);
+                               if (res < 0)
+                               {
+                                       free(data);
+                                       CloseHandle(fp);
+                                       return FALSE;
+                               }
+                               size = (size_t)res;
+
                                tdata = malloc(size + 1);
 
                                if (!tdata)
@@ -520,8 +530,17 @@ BOOL certificate_data_replace(rdpCertificateStore* certificate_store,
                                        return FALSE;
                                }
 
-                               if (_snprintf(tdata, size + 1, "%s %"PRIu16" %s %s %s\n", hostname, port, fingerprint, subject,
-                                             issuer) != size)
+                               res = _snprintf(tdata, size + 1, "%s %"PRIu16" %s %s %s\n", hostname, port, fingerprint, subject,
+                                             issuer);
+                               if (res < 0)
+                               {
+                                       free(tdata);
+                                       free(data);
+                                       CloseHandle(fp);
+                                       return FALSE;
+                               }
+
+                               if ((size_t)res != size)
                                {
                                        WLog_ERR(TAG, "_snprintf(%s) returned %s [0x%08X]",
                                                 certificate_store->file, strerror(errno), errno);
@@ -600,6 +619,7 @@ BOOL certificate_split_line(char* line, char** host, UINT16* port, char** subjec
 BOOL certificate_data_print(rdpCertificateStore* certificate_store,
                             rdpCertificateData* certificate_data)
 {
+       int rc;
        HANDLE fp;
        char* tdata;
        UINT64 size;
@@ -621,10 +641,14 @@ BOOL certificate_data_print(rdpCertificateStore* certificate_store,
                return FALSE;
        }
 
-       size = _snprintf(NULL, 0, "%s %"PRIu16" %s %s %s\n", certificate_data->hostname,
+       rc = _snprintf(NULL, 0, "%s %"PRIu16" %s %s %s\n", certificate_data->hostname,
                         certificate_data->port,
                         certificate_data->fingerprint, certificate_data->subject,
                         certificate_data->issuer);
+       if (rc < 0)
+               return FALSE;
+       size = (size_t)rc;
+
        tdata = malloc(size + 1);
 
        if (!tdata)
@@ -635,10 +659,12 @@ BOOL certificate_data_print(rdpCertificateStore* certificate_store,
                return FALSE;
        }
 
-       if (_snprintf(tdata, size + 1, "%s %"PRIu16" %s %s %s\n", certificate_data->hostname,
+       rc = _snprintf(tdata, size + 1, "%s %"PRIu16" %s %s %s\n", certificate_data->hostname,
                      certificate_data->port,
                      certificate_data->fingerprint, certificate_data->subject,
-                     certificate_data->issuer) != size)
+                     certificate_data->issuer);
+
+       if ((rc < 0) || ((size_t)rc != size))
        {
                WLog_ERR(TAG, "_snprintf(%s) returned %s [0x%08X]",
                         certificate_store->file, strerror(errno), errno);
index 0e2bd51..727c62c 100644 (file)
@@ -315,7 +315,7 @@ static const char*   general_name_type_labels[] = { "OTHERNAME",
 static const char* general_name_type_label(int general_name_type)
 {
        if ((0 <= general_name_type)
-           && (general_name_type < ARRAYSIZE(general_name_type_labels)))
+           && ((size_t)general_name_type < ARRAYSIZE(general_name_type_labels)))
        {
                return general_name_type_labels[general_name_type];
        }
index 6e00571..b8b4e7f 100644 (file)
@@ -1229,7 +1229,7 @@ static BOOL tls_extract_pem(CryptoCert cert, BYTE** PublicKey, DWORD* PublicKeyL
        BIO* bio;
        int status;
        size_t offset;
-       int length = 0;
+       size_t length = 0;
        BOOL rc = FALSE;
        BYTE* pemCert = NULL;
 
@@ -1275,7 +1275,7 @@ static BOOL tls_extract_pem(CryptoCert cert, BYTE** PublicKey, DWORD* PublicKeyL
                goto fail;
        }
 
-       offset += status;
+       offset += (size_t)status;
 
        while (offset >= length)
        {