Removed strcpy use.
authorArmin Novak <armin.novak@thincast.com>
Tue, 29 Oct 2019 09:23:48 +0000 (10:23 +0100)
committerArmin Novak <armin.novak@thincast.com>
Tue, 29 Oct 2019 10:58:43 +0000 (11:58 +0100)
channels/rdp2tcp/client/rdp2tcp_main.c
libfreerdp/crypto/test/Test_x509_cert_info.c

index b9c17d7..930d938 100644 (file)
@@ -300,7 +300,7 @@ BOOL VCAPITYPE VirtualChannelEntryEx(PCHANNEL_ENTRY_POINTS pEntryPoints, PVOID p
        if (init_external_addin(plugin) < 0)
                return FALSE;
 
-       strcpy(channelDef.name, RDP2TCP_CHAN_NAME);
+       strncpy(channelDef.name, RDP2TCP_CHAN_NAME, sizeof(channelDef.name));
        channelDef.options =
            CHANNEL_OPTION_INITIALIZED |
            CHANNEL_OPTION_ENCRYPT_RDP |
index 6a2d2c2..4076dfe 100644 (file)
@@ -13,13 +13,13 @@ typedef struct
        const char* expected_result;
 } certificate_test_t;
 
-char*   crypto_cert_subject_common_name_wo_length(X509* xcert)
+static char*   crypto_cert_subject_common_name_wo_length(X509* xcert)
 {
        int length;
        return crypto_cert_subject_common_name(xcert, & length);
 }
 
-char* certificate_path()
+static char* certificate_path(void)
 {
        /*
        Assume the .pem file is in the same directory as this source file.
@@ -37,9 +37,13 @@ char* certificate_path()
 
        if (last_dirsep)
        {
-               char* result = malloc(last_dirsep - file + 1 + strnlen(filename, sizeof(filename)) + 1);
-               strncpy(result, file, (last_dirsep - file + 1));
-               strcpy(result + (last_dirsep - file + 1), filename);
+               const size_t filenameLen = strnlen(filename, sizeof(filename));
+               const size_t dirsepLen = last_dirsep - file + 1;
+               char* result = malloc(dirsepLen + filenameLen + 1);
+               if (!result)
+                       return NULL;
+               strncpy(result, file, dirsepLen);
+               strncpy(result + dirsepLen, filename, filenameLen + 1);
                return result;
        }
        else
@@ -49,7 +53,7 @@ char* certificate_path()
        }
 }
 
-const certificate_test_t certificate_tests[] =
+static const certificate_test_t certificate_tests[] =
 {
 
        {
@@ -98,7 +102,7 @@ const certificate_test_t certificate_tests[] =
 
 
 
-int TestCertificateFile(const char* certificate_path, const certificate_test_t* certificate_tests,
+static int TestCertificateFile(const char* certificate_path, const certificate_test_t* certificate_tests,
                         int count)
 {
        X509*   certificate;