Skip to content

Commit

Permalink
Replace strcpy with strncpy (#1157)
Browse files Browse the repository at this point in the history
* Replace strcpy with strncpy

* Fix CBMC
  • Loading branch information
tony-josi-aws authored Jun 18, 2024
1 parent b79b2e0 commit 4c4223a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS_Cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );


Expand Down
2 changes: 1 addition & 1 deletion source/FreeRTOS_DNS_Callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[
"--unwind 1",
"--unwindset strlen.0:{HOSTNAME_UNWIND}",
"--unwindset strcpy.0:{HOSTNAME_UNWIND}",
"--unwindset strncpy.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND}",
"--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND}",
"--nondet-static"
Expand Down

0 comments on commit 4c4223a

Please sign in to comment.