Skip to content

Commit 64023d6

Browse files
committed
Fix the DNS_ParseDNSReply CBMC proofs
All four DNS_ParseDNSReply configurations failed with an unwinding assertion on DNS_DecodeName.0. The decoder was reached from DNS_ParseDNSReply() on the path where a response carries no question and the name has to be taken from the first answer instead, and that loop is not in those proofs' unwindsets, so --unwind 1 applied to it. Take the name with DNS_ReadNameField() there instead of DNS_DecodeName(). The decoder was only used to reach it under the same condition that the answer-name validation is compiled under, and widening the declaration of DNS_ReadNameField() to the condition its definition already uses achieves that without adding a loop to this entry point. Nothing precedes those records but the header, so the name cannot usefully be a compression pointer; should it be one anyway, the name stays empty and every answer record fails the validation. Bounding DNS_DecodeName.0 in those proofs instead would have worked, but it made the two NetworkBufferSize configurations far more expensive: the IPv4 dynamic one exhausted the SAT solver's memory locally. With this change the four proofs take 1s, 1s, 87s and 108s and all report SUCCESS.
1 parent 3a984fe commit 64023d6

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

‎source/FreeRTOS_DNS_Parser.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,17 @@
356356

357357
/* There is no question to take the name from, so
358358
* take it from the first answer instead. The answer
359-
* records are validated against it below, so it has
360-
* to be filled in under the same conditions as that
361-
* check is compiled under. The parse position is
359+
* records are validated against it, so it has to be
360+
* filled in under the same conditions that the
361+
* validation is compiled under. Nothing precedes
362+
* these records but the header, so the name cannot
363+
* usefully be a compression pointer; should it be
364+
* one anyway, the name stays empty and every record
365+
* fails the validation. The parse position is
362366
* deliberately not advanced. */
363-
( void ) DNS_DecodeName( xSet.pucUDPPayloadBuffer,
364-
xSet.uxBufferLength,
365-
xSet.pucByte,
366-
xSet.uxSourceBytesRemaining,
367-
xSet.pcName,
368-
sizeof( xSet.pcName ) );
367+
uxResult = DNS_ReadNameField( &xSet,
368+
sizeof( xSet.pcName ) );
369+
( void ) uxResult;
369370
#endif
370371
}
371372
}

‎source/include/FreeRTOS_DNS_Parser.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@
5050
/** @brief Flag DNS parsing errors in situations where an IPv4 address is the return
5151
* type. */
5252

53-
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 )
53+
/* Declared under the same condition that the definition in
54+
* FreeRTOS_DNS_Parser.c is compiled under, and that ParseSet_t::pcName exists
55+
* under. */
56+
#if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) )
5457
size_t DNS_ReadNameField( ParseSet_t * pxSet,
5558
size_t uxDestLen );
56-
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */
59+
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */
5760

5861
/*
5962
* Simple routine that jumps over the NAME field of a resource record.

0 commit comments

Comments
 (0)