slirp: Fix packet expiration
PATCH 1/1 slirp: Fix packet expiration
The two new variables "arp_requested" and "expiration_date" in the mbuf structure have been added after the variable-sized "m_dat_" array. The variables have to be added before the m_dat_ array instead. Without this patch, the expiration_date gets clobbered by code that accesses the m_dat_ array.
I experienced this problem with the code in slirp/tftp.c: The tftp_send_data() function created a new packet with the m_get() function (which fills-in a default expiration_date value). Then the TFTP code cleared the data section of the packet, which accidentially also cleared the expiration_date. This zeroed expiration_date then finally causes the packet to be discarded during if_start(), so that TFTP packets were not transmitted anymore.
-------
slirp/mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
slirp/mbuf.h +2 -2
@@ -82,12 +82,12 @@ struct m_hdr {struct mbuf {struct m_hdr m_hdr;Slirp *slirp; +bool arp_requested; +uint64_t expiration_date;union M_dat {char m_dat_[1 ];/* ANSI don't like 0 sized arrays */ char *m_ext_; } M_dat; -bool arp_requested; -uint64_t expiration_date; };#define m_next m_hdr.mh_next
Jan Kiszka
AppliedQuoted 28 lines · Thomas Huth
The two new variables "
arp_requested" and "expiration_date" in the mbuf structure have been added after the variable-sized "m_dat_" array. The variables have to be added before them_dat_array instead. Without this patch, theexpiration_dategets clobbered by code that accesses them_dat_array.
I experienced this problem with the code inslirp/tftp.c: Thetftp_send_data()function created a new packet with them_get()function (which fills-in a defaultexpiration_datevalue). Then the TFTP code cleared the data section of the packet, which accidentially also cleared theexpiration_date. This zeroedexpiration_datethen finally causes the packet to be discarded duringif_start(), so that TFTP packets were not transmitted anymore.Signed-off-by Thomas Huth <[email protected]>-------
slirp/mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)slirp/mbuf.h +1
-0@@ -82,12 +82,12 @@ struct m_hdr {struct mbuf {struct m_hdr m_hdr;Slirp *slirp; +bool arp_requested;
slirp/mbuf.h struct m_hdr { · line 93
Quoted 10 lines
slirp/mbuf.h +1
-2+uint64_t expiration_date;union M_dat {char m_dat_[1 ];/* ANSI don't like 0 sized arrays */ char *m_ext_; } M_dat; -bool arp_requested; -uint64_t expiration_date; };#define m_next m_hdr.mh_next
Thanks, applied.
What generates "-------" as separator? Confuses git am here. You may want to use standard "---" in the future.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux
Quoted 14 lines · Thomas Huth
The two new variables "
arp_requested" and "expiration_date" in the mbuf structure have been added after the variable-sized "m_dat_" array. The variables have to be added before them_dat_array instead. Without this patch, theexpiration_dategets clobbered by code that accesses them_dat_array.
I experienced this problem with the code inslirp/tftp.c: Thetftp_send_data()function created a new packet with them_get()function (which fills-in a defaultexpiration_datevalue). Then the TFTP code cleared the data section of the packet, which accidentially also cleared theexpiration_date. This zeroedexpiration_datethen finally causes the packet to be discarded duringif_start(), so that TFTP packets were not transmitted anymore.
Thanks for the patch Thomas.
I think we can add a comment to avoid this kind of mistake in the future.
/* This is a "flexible array member". It should always remain
* the last member of the structure.
*/
Quoted 25 lines
Signed-off-by Thomas Huth <[email protected]>-------
slirp/mbuf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)slirp/mbuf.h +2
-2@@ -82,12 +82,12 @@ struct m_hdr {struct mbuf {struct m_hdr m_hdr;Slirp *slirp; +bool arp_requested; +uint64_t expiration_date;union M_dat {char m_dat_[1 ];/* ANSI don't like 0 sized arrays */ char *m_ext_; } M_dat; -bool arp_requested; -uint64_t expiration_date; };#define m_next m_hdr.mh_next
Signature · 1 line
Fabien Chouteau
Quoted 16 lines · Fabien Chouteau
Quoted 14 lines · Thomas Huth
The two new variables "
arp_requested" and "expiration_date" in the mbuf structure have been added after the variable-sized "m_dat_" array. The variables have to be added before them_dat_array instead. Without this patch, theexpiration_dategets clobbered by code that accesses them_dat_array.
I experienced this problem with the code inslirp/tftp.c: Thetftp_send_data()function created a new packet with them_get()function (which fills-in a defaultexpiration_datevalue). Then the TFTP code cleared the data section of the packet, which accidentially also cleared theexpiration_date. This zeroedexpiration_datethen finally causes the packet to be discarded duringif_start(), so that TFTP packets were not transmitted anymore.
Quoted 8 lines
Thanks for the patch Thomas.
I think we can add a comment to avoid this kind of mistake in the future.
/* This is a "flexible array member". It should always remain
* the last member of the structure.
*/
Good point, folded something like that in.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux