From 993b79f1bd98f604eb4434e3aaa30069b2df65d7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 29 Oct 2019 10:23:48 +0100 Subject: [PATCH] Removed strcpy use. --- channels/rdp2tcp/client/rdp2tcp_main.c | 2 +- libfreerdp/crypto/test/Test_x509_cert_info.c | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/channels/rdp2tcp/client/rdp2tcp_main.c b/channels/rdp2tcp/client/rdp2tcp_main.c index b9c17d7cb..930d938eb 100644 --- a/channels/rdp2tcp/client/rdp2tcp_main.c +++ b/channels/rdp2tcp/client/rdp2tcp_main.c @@ -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 | diff --git a/libfreerdp/crypto/test/Test_x509_cert_info.c b/libfreerdp/crypto/test/Test_x509_cert_info.c index 6a2d2c299..4076dfed5 100644 --- a/libfreerdp/crypto/test/Test_x509_cert_info.c +++ b/libfreerdp/crypto/test/Test_x509_cert_info.c @@ -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;