Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable strcpy_s, strncpy_s, strcat_s, sprintf_s,strtoull_s #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions adapters/httpapi_compact.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ static int ParseStringToDecimalAndRemaining(const char *src, int* dst, char* rem
{
cLen = maxRemainingSize - 1;
}
(void)strcpy_s(remaining, cLen + 1, next);
(void)azure_c_shared_utility_strcpy_s(remaining, cLen + 1, next);
remaining[maxRemainingSize - 1] = 0;
}
}
return result;
}

Expand Down Expand Up @@ -1283,7 +1283,7 @@ static bool validRequestType(HTTPAPI_REQUEST_TYPE requestType)
}

HTTPAPI_RESULT HTTPAPI_ExecuteRequest_Internal(HTTP_HANDLE handle, HTTPAPI_REQUEST_TYPE requestType, const char* relativePath,
HTTP_HEADERS_HANDLE httpHeadersHandle, const unsigned char* content, size_t contentLength,
HTTP_HEADERS_HANDLE httpHeadersHandle, const unsigned char* content, size_t contentLength,
unsigned int* statusCode, char* reasonPhrase, const size_t maxReasonPhraseSize, HTTP_HEADERS_HANDLE responseHeadersHandle,
BUFFER_HANDLE responseContent, ON_CHUNK_RECEIVED onChunkReceived, void* onChunkReceivedContext)
{
Expand Down Expand Up @@ -1377,7 +1377,7 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest_With_Reason_Phrase(HTTP_HANDLE handle, HTT
size_t contentLength, unsigned int* statusCode, char* reasonPhrase, const size_t maxReasonPhraseSize,
HTTP_HEADERS_HANDLE responseHeadersHandle, BUFFER_HANDLE responseContent)
{
return HTTPAPI_ExecuteRequest_Internal(handle, requestType, relativePath, httpHeadersHandle,
return HTTPAPI_ExecuteRequest_Internal(handle, requestType, relativePath, httpHeadersHandle,
content, contentLength, statusCode, reasonPhrase, maxReasonPhraseSize, responseHeadersHandle, responseContent, NULL, NULL);
}

Expand All @@ -1389,7 +1389,7 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest_With_Streaming(HTTP_HANDLE handle, HTTPAPI
size_t contentLength, unsigned int* statusCode, char* reasonPhrase, const size_t maxReasonPhraseSize,
HTTP_HEADERS_HANDLE responseHeadersHandle, ON_CHUNK_RECEIVED onChunkReceived, void* onChunkReceivedContext)
{
return HTTPAPI_ExecuteRequest_Internal(handle, requestType, relativePath, httpHeadersHandle,
return HTTPAPI_ExecuteRequest_Internal(handle, requestType, relativePath, httpHeadersHandle,
content, contentLength, statusCode, reasonPhrase, maxReasonPhraseSize, responseHeadersHandle, NULL, onChunkReceived, onChunkReceivedContext);
}

Expand Down Expand Up @@ -1432,7 +1432,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_064: [ If the HTTPAPI_SetOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(http_instance->certificate, len + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(http_instance->certificate, len + 1, (const char*)value);
result = HTTPAPI_OK;
}
}
Expand All @@ -1452,7 +1452,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
}
else
{
(void)strcpy_s(http_instance->tlsIoVersion, len + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(http_instance->tlsIoVersion, len + 1, (const char*)value);
result = HTTPAPI_OK;
}
}
Expand All @@ -1475,7 +1475,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_064: [ If the HTTPAPI_SetOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(http_instance->x509ClientCertificate, len + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(http_instance->x509ClientCertificate, len + 1, (const char*)value);
result = HTTPAPI_OK;
}
}
Expand All @@ -1498,7 +1498,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_064: [ If the HTTPAPI_SetOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(http_instance->x509ClientPrivateKey, len + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(http_instance->x509ClientPrivateKey, len + 1, (const char*)value);
result = HTTPAPI_OK;
}
}
Expand Down Expand Up @@ -1542,7 +1542,7 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_072: [ If the HTTPAPI_CloneOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(tempCert, certLen + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(tempCert, certLen + 1, (const char*)value);
*savedValue = tempCert;
result = HTTPAPI_OK;
}
Expand All @@ -1559,7 +1559,7 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_072: [ If the HTTPAPI_CloneOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(tempCert, certLen + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(tempCert, certLen + 1, (const char*)value);
*savedValue = tempCert;
result = HTTPAPI_OK;
}
Expand All @@ -1576,7 +1576,7 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co
else
{
/*Codes_SRS_HTTPAPI_COMPACT_21_072: [ If the HTTPAPI_CloneOption get success setting the option, it shall return HTTPAPI_OK. ]*/
(void)strcpy_s(tempCert, certLen + 1, (const char*)value);
(void)azure_c_shared_utility_strcpy_s(tempCert, certLen + 1, (const char*)value);
*savedValue = tempCert;
result = HTTPAPI_OK;
}
Expand Down
14 changes: 7 additions & 7 deletions adapters/httpapi_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName)
}
else
{
if ((strcpy_s(httpHandleData->hostURL, hostURL_size, "https://") == 0) &&
(strcat_s(httpHandleData->hostURL, hostURL_size, hostName) == 0))
if ((azure_c_shared_utility_strcat_s(httpHandleData->hostURL, hostURL_size, "https://") == 0) &&
(azure_c_shared_utility_strcat_s(httpHandleData->hostURL, hostURL_size, hostName) == 0))
{
httpHandleData->curl = curl_easy_init();
if (httpHandleData->curl == NULL)
Expand Down Expand Up @@ -267,7 +267,7 @@ static CURLcode ssl_ctx_callback(CURL *curl, void *ssl_ctx, void *userptr)
result = CURLE_SSL_CERTPROBLEM;
}
else if (
(httpHandleData->certificates != NULL) &&
(httpHandleData->certificates != NULL) &&
(wolfSSL_CTX_load_verify_buffer(ssl_ctx, (const unsigned char*)httpHandleData->certificates, strlen(httpHandleData->certificates), SSL_FILETYPE_PEM) != SSL_SUCCESS)
)
{
Expand Down Expand Up @@ -331,8 +331,8 @@ HTTPAPI_RESULT HTTPAPI_ExecuteRequest(HTTP_HANDLE handle, HTTPAPI_REQUEST_TYPE r
result = HTTPAPI_SET_OPTION_FAILED;
LogError("failed to set CURLOPT_VERBOSE (result = %s)", ENUM_TO_STRING(HTTPAPI_RESULT, result));
}
else if ((strcpy_s(tempHostURL, tempHostURL_size, httpHandleData->hostURL) != 0) ||
(strcat_s(tempHostURL, tempHostURL_size, relativePath) != 0))
else if ((azure_c_shared_utility_strcpy_s(tempHostURL, tempHostURL_size, httpHandleData->hostURL) != 0) ||
(azure_c_shared_utility_strcat_s(tempHostURL, tempHostURL_size, relativePath) != 0))
{
result = HTTPAPI_STRING_PROCESSING_ERROR;
LogError("(result = %s)", ENUM_TO_STRING(HTTPAPI_RESULT, result));
Expand Down Expand Up @@ -763,7 +763,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con

HTTP_PROXY_OPTIONS* proxy_data = (HTTP_PROXY_OPTIONS*)value;

if (sprintf_s(proxy, MAX_HOSTNAME_LEN, "%s:%d", proxy_data->host_address, proxy_data->port) <= 0)
if (azure_c_shared_utility_sprintf_s(proxy, MAX_HOSTNAME_LEN, "%s:%d", proxy_data->host_address, proxy_data->port) <= 0)
{
LogError("failure constructing proxy address");
result = HTTPAPI_ERROR;
Expand All @@ -789,7 +789,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
else
{
// From curl website 'Pass a char * as parameter, which should be [user name]:[password]'
if (sprintf_s(proxy_auth, MAX_HOSTNAME_LEN, "%s:%s", proxy_data->username, proxy_data->password) <= 0)
if (azure_c_shared_utility_sprintf_s(proxy_auth, MAX_HOSTNAME_LEN, "%s:%s", proxy_data->username, proxy_data->password) <= 0)
{
LogError("failure constructing proxy authentication");
result = HTTPAPI_ERROR;
Expand Down
8 changes: 4 additions & 4 deletions adapters/httpapi_wince.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int SSLInit(SOCKET s)
SSLVALIDATECERTHOOK hook;
SSLPROTOCOLS protocolsToUse;
int ret;


if (setsockopt(s, SOL_SOCKET, SO_SECURE, (LPSTR)&optval, sizeof(optval)) ==
SOCKET_ERROR)
{
Expand Down Expand Up @@ -129,9 +129,9 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName)
{
LogInfo("HTTPAPI_CreateConnection::Connecting to %s", hostName);
handle = new HTTP_HANDLE_DATA();
if (strcpy_s(handle->host, MAX_HOSTNAME, hostName) != 0)
if (azure_c_shared_utility_strcpy_s(handle->host, MAX_HOSTNAME, hostName) != 0)
{
LogError("HTTPAPI_CreateConnection::Could not strcpy_s");
LogError("HTTPAPI_CreateConnection::Could not azure_c_shared_utility_strcpy_s");
delete handle;
handle = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/httpapi_winhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
}
else
{
if (sprintf_s(proxyAddressAndPort, MAX_HOSTNAME_LEN, "%s:%d", proxy_data->host_address, proxy_data->port) <= 0)
if (azure_c_shared_utility_sprintf_s(proxyAddressAndPort, MAX_HOSTNAME_LEN, "%s:%d", proxy_data->host_address, proxy_data->port) <= 0)
{
LogError("failure constructing proxy address");
result = HTTPAPI_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion adapters/tlsio_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ static int load_cert_crl_http(
char* realmBase64;
long length = BIO_get_mem_data(bioBase64, &realmBase64);

sprintf_s(authData, sizeof(authData), "Basic %.*s", length, realmBase64);
azure_c_shared_utility_sprintf_s(authData, sizeof(authData), "Basic %.*s", length, realmBase64);

BIO_pop(bioPlain);
BIO_free_all(bioBase64);
Expand Down
18 changes: 13 additions & 5 deletions inc/azure_c_shared_utility/crt_abstractions.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ typedef unsigned char bool;
/* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */
/* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/
#ifdef _MSC_VER
#define azure_c_shared_utility_sprintf_s sprintf_s
#define azure_c_shared_utility_strcat_s strcat_s
#define azure_c_shared_utility_strncpy_s strncpy_s
#define azure_c_shared_utility_sprintf_s sprintf_s
#define azure_c_shared_utility_strcpy_s strcpy_s

#else // _MSC_VER

/* Adding definitions from errno.h & crtdefs.h */
Expand All @@ -93,12 +99,14 @@ typedef unsigned char bool;
#define STRUNCATE 80
#endif /* !defined (STRUNCATE) */

extern int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src);
extern int strcat_s(char* dst, size_t dstSizeInBytes, const char* src);
extern int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
extern int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);
extern int azure_c_shared_utility_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src);
extern int azure_c_shared_utility_strcat_s(char* dst, size_t dstSizeInBytes, const char* src);
extern int azure_c_shared_utility_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount);
extern int azure_c_shared_utility_sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...);

#endif // _MSC_VER


extern unsigned long long strtoull_s(const char* nptr, char** endPtr, int base);
extern float strtof_s(const char* nptr, char** endPtr);
extern long double strtold_s(const char* nptr, char** endPtr);
Expand Down Expand Up @@ -137,7 +145,7 @@ extern "C++" {
#define ISNAN std::isnan
}
#else // __cplusplus
#error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard
#error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard
#endif // __cplusplus

#endif // __STDC_VERSION__
Expand Down
2 changes: 1 addition & 1 deletion src/connection_string_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int connectionstringparser_splitHostName_from_char(const char* hostName, STRING_
}
runHostName++;
}

if ((*runHostName) == '\0')
{
/* Codes_SRS_CONNECTIONSTRINGPARSER_21_030: [If the hostName is not a valid host name, connectionstringparser_splitHostName_from_char shall return __FAILURE__.]*/
Expand Down
36 changes: 18 additions & 18 deletions src/crt_abstractions.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#ifdef _MSC_VER
#else

/*Codes_SRS_CRT_ABSTRACTIONS_99_008: [strcat_s shall append the src to dst and terminates the resulting string with a null character.]*/
int strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
/*Codes_SRS_CRT_ABSTRACTIONS_99_008: [azure_c_shared_utility_strcat_s shall append the src to dst and terminates the resulting string with a null character.]*/
int azure_c_shared_utility_strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
{
int result;
/*Codes_SRS_CRT_ABSTRACTIONS_99_004: [If dst is NULL or unterminated, the error code returned shall be EINVAL & dst shall not be modified.]*/
Expand Down Expand Up @@ -96,7 +96,7 @@ int strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_003: [strcat_s shall return Zero upon success.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_003: [azure_c_shared_utility_strcat_s shall return Zero upon success.]*/
result = 0;
}
}
Expand All @@ -107,7 +107,7 @@ int strcat_s(char* dst, size_t dstSizeInBytes, const char* src)
}

/*Codes_SRS_CRT_ABSTRACTIONS_99_025: [strncpy_s shall copy the first N characters of src to dst, where N is the lesser of MaxCount and the length of src.]*/
int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount)
int azure_c_shared_utility_strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount)
{
int result;
int truncationFlag = 0;
Expand All @@ -127,7 +127,7 @@ int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount
{
result = EINVAL;
}
else
else
{
size_t srcLength = strlen(src);
if (maxCount != _TRUNCATE)
Expand All @@ -148,7 +148,7 @@ int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount
{
(void)strncpy(dst, src, srcLength);
dst[srcLength] = '\0';
/*Codes_SRS_CRT_ABSTRACTIONS_99_018: [strncpy_s shall return Zero upon success]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_018: [azure_c_shared_utility_strncpy_s shall return Zero upon success]*/
result = 0;
}
}
Expand All @@ -175,8 +175,8 @@ int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount
return result;
}

/* Codes_SRS_CRT_ABSTRACTIONS_99_016: [strcpy_s shall copy the contents in the address of src, including the terminating null character, to the location that's specified by dst.]*/
int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
/* Codes_SRS_CRT_ABSTRACTIONS_99_016: [azure_c_shared_utility_strcpy_s shall copy the contents in the address of src, including the terminating null character, to the location that's specified by dst.]*/
int azure_c_shared_utility_strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
{
int result;

Expand Down Expand Up @@ -209,20 +209,20 @@ int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src)
else
{
(void)memcpy(dst, src, neededBuffer + 1);
/*Codes_SRS_CRT_ABSTRACTIONS_99_011: [strcpy_s shall return Zero upon success]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_011: [azure_c_shared_utility_strcpy_s shall return Zero upon success]*/
result = 0;
}
}

return result;
}

/*Codes_SRS_CRT_ABSTRACTIONS_99_029: [The sprintf_s function shall format and store series of characters and values in dst. Each argument (if any) is converted and output according to the corresponding Format Specification in the format variable.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_029: [The azure_c_shared_utility_sprintf_s function shall format and store series of characters and values in dst. Each argument (if any) is converted and output according to the corresponding Format Specification in the format variable.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_031: [A null character is appended after the last character written.]*/
int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...)
int azure_c_shared_utility_sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...)
{
int result;
/*Codes_SRS_CRT_ABSTRACTIONS_99_028: [If dst or format is a null pointer, sprintf_s shall return -1 and set errno to EINVAL]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_028: [If dst or format is a null pointer, azure_c_shared_utility_sprintf_s shall return -1 and set errno to EINVAL]*/
if ((dst == NULL) ||
(format == NULL))
{
Expand All @@ -231,9 +231,9 @@ int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...)
}
else
{
/*Codes_SRS_CRT_ABSTRACTIONS_99_033: [sprintf_s shall check the format string for valid formatting characters. If the check fails, the function returns -1.]*/
/*Codes_SRS_CRT_ABSTRACTIONS_99_033: [azure_c_shared_utility_sprintf_s shall check the format string for valid formatting characters. If the check fails, the function returns -1.]*/

#if defined _MSC_VER
#if defined _MSC_VER
#error crt_abstractions is not provided for Microsoft Compilers
#else
/*not Microsoft compiler... */
Expand Down Expand Up @@ -338,7 +338,7 @@ unsigned long long strtoull_s(const char* nptr, char** endptr, int base)
runner++;
}
}

if(base == 0)
{
/*Codes_SRS_CRT_ABSTRACTIONS_21_007: [If the base is 0 and no special chars precedes the number, strtoull_s must convert to a decimal (base 10).]*/
Expand Down Expand Up @@ -524,7 +524,7 @@ static FLOAT_STRING_TYPE splitFloatString(const char* nptr, char** endptr, int *
result = FST_OVERFLOW;
}
}

if (((**endptr) == 'e') || ((**endptr) == 'E'))
{
startptr = (*endptr) + 1;
Expand Down Expand Up @@ -692,7 +692,7 @@ int mallocAndStrcpy_s(char** destination, const char* source)
{
size_t l = strlen(source);
char* temp = (char*)malloc(l + 1);

/*Codes_SRS_CRT_ABSTRACTIONS_99_037: [Upon failure to allocate memory for the destination, the function will return ENOMEM.]*/
if (temp == NULL)
{
Expand All @@ -702,7 +702,7 @@ int mallocAndStrcpy_s(char** destination, const char* source)
{
*destination = temp;
/*Codes_SRS_CRT_ABSTRACTIONS_99_039: [mallocAndstrcpy_s shall copy the contents in the address source, including the terminating null character into location specified by the destination pointer after the memory allocation.]*/
copied_result = strcpy_s(*destination, l + 1, source);
copied_result = azure_c_shared_utility_strcpy_s(*destination, l + 1, source);
if (copied_result < 0) /*strcpy_s error*/
{
free(*destination);
Expand Down
Loading