From d8a8fef84ac4c6550977a13544a87bc443d1e965 Mon Sep 17 00:00:00 2001 From: tony-josi-aws Date: Mon, 17 Jun 2024 11:33:25 +0530 Subject: [PATCH] Replace strcpy with strncpy --- source/FreeRTOS_DNS.c | 2 +- source/FreeRTOS_DNS_Cache.c | 2 +- source/FreeRTOS_DNS_Callback.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 7ebda549a6..0eb249e4c3 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -1517,7 +1517,7 @@ uxIndex = uxStart + 1U; /* Copy in the host name. */ - ( void ) strcpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName ); + ( void ) strncpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName, strlen( pcHostName ) + 1U ); /* Walk through the string to replace the '.' characters with byte * counts. pucStart holds the address of the byte count. Walking the diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index 4c3f5715ae..7c8e236383 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -448,7 +448,7 @@ /* Add or update the item. */ if( strlen( pcName ) < ( size_t ) ipconfigDNS_CACHE_NAME_LENGTH ) { - ( void ) strcpy( xDNSCache[ uxFreeEntry ].pcName, pcName ); + ( void ) strncpy( xDNSCache[ uxFreeEntry ].pcName, pcName, ipconfigDNS_CACHE_NAME_LENGTH ); ( void ) memcpy( &( xDNSCache[ uxFreeEntry ].xAddresses[ 0 ] ), pxIP, sizeof( *pxIP ) ); diff --git a/source/FreeRTOS_DNS_Callback.c b/source/FreeRTOS_DNS_Callback.c index 5a040c90be..15bddbfe51 100644 --- a/source/FreeRTOS_DNS_Callback.c +++ b/source/FreeRTOS_DNS_Callback.c @@ -155,7 +155,7 @@ vDNSTimerReload( FreeRTOS_min_uint32( 1000U, ( uint32_t ) uxTimeout ) ); } - ( void ) strcpy( pxCallback->pcName, pcHostName ); + ( void ) strncpy( pxCallback->pcName, pcHostName, lLength + 1U ); pxCallback->pCallbackFunction = pCallbackFunction; pxCallback->pvSearchID = pvSearchID; pxCallback->uxRemainingTime = uxTimeout;