Patchwork [v2] slirp: Don't crash on packets from 0.0.0.0/8.

login
register
mail settings
Submitter Nickolai Zeldovich
Date Nov. 12, 2012, 4:59 p.m.
Message ID <1352739589-5264-1-git-send-email-nickolai@csail.mit.edu>
Download mbox | patch
Permalink /patch/198427/
State New
Headers show

Comments

Nickolai Zeldovich - Nov. 12, 2012, 4:59 p.m.
LWIP can generate packets with a source of 0.0.0.0, which triggers an
assertion failure in arp_table_add().  Instead of crashing, simply return
to avoid adding an invalid ARP table entry.

Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
---
 slirp/arp_table.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Change from v1: adhere to qemu's code style (put braces around all
indentation blocks).
Jan Kiszka - Nov. 15, 2012, 9:27 a.m.
On 2012-11-12 17:59, Nickolai Zeldovich wrote:
> LWIP can generate packets with a source of 0.0.0.0, which triggers an
> assertion failure in arp_table_add().  Instead of crashing, simply return
> to avoid adding an invalid ARP table entry.
> 
> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
> ---
>  slirp/arp_table.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Change from v1: adhere to qemu's code style (put braces around all
> indentation blocks).
> 
> 
> diff --git a/slirp/arp_table.c b/slirp/arp_table.c
> index 5d7b8ac..bf698c1 100644
> --- a/slirp/arp_table.c
> +++ b/slirp/arp_table.c
> @@ -38,7 +38,9 @@ void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
>                  ethaddr[3], ethaddr[4], ethaddr[5]));
>  
>      /* Check 0.0.0.0/8 invalid source-only addresses */
> -    assert((ip_addr & htonl(~(0xf << 28))) != 0);
> +    if ((ip_addr & htonl(~(0xf << 28))) == 0) {
> +        return;
> +    }
>  
>      if (ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
>          /* Do not register broadcast addresses */
> 

Thanks, applied to slirp queue.

Jan

Patch

diff --git a/slirp/arp_table.c b/slirp/arp_table.c
index 5d7b8ac..bf698c1 100644
--- a/slirp/arp_table.c
+++ b/slirp/arp_table.c
@@ -38,7 +38,9 @@  void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
                 ethaddr[3], ethaddr[4], ethaddr[5]));
 
     /* Check 0.0.0.0/8 invalid source-only addresses */
-    assert((ip_addr & htonl(~(0xf << 28))) != 0);
+    if ((ip_addr & htonl(~(0xf << 28))) == 0) {
+        return;
+    }
 
     if (ip_addr == 0xffffffff || ip_addr == broadcast_addr) {
         /* Do not register broadcast addresses */