Temporary patch for arpd
Subsystems (2)
PATCH 1/1 Temporary patch for arpd
Hello. I found wonderful bug in arpd daemon of iproute2 package. Somehow arpd is absolute unworkable if run program with -f flag. On my amd64 server i got "Segmentation fault" regardless -f mac-list.txt file content.
The source of misc/arpd.c is not hard and i found that cause of this bug is commit dd50247dba85255538d659551305b4bb75bcae62. I'm not c++ developer, but i suppose segfault occured because argument of dbase->put() has non-initialized dbdat.data argument.
Also arpd.c has strange condition "if (do_load || do_list)" that not allows to run program with -f argument.
I did pull out the hexstring_a2n function from utils.c of previous commit aeb199d5ce86c6c72decaac333cad5a7d7b38b3a and used it to populate dbdat.data value after which program works fine.
I hurriedly make the patch that makes program alive. Please inspect this problem, fix this bug and test program with -f key.
PS: sorry for my english =)
From 433147a7303c418845bdb5668910caababf79453 Mon Sep 17 00:00:00 2001
From: Pascal <[email protected]>
Date: Wed, 12 Oct 2016 03:13:53 +0800
Subject: [PATCH] Temporary patch for arpd
--- misc/arpd.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-)
misc/arpd.c +42 -2
@@ -584,6 +584,43 @@ static void send_stats(void) do_stats =0 ; } +__u8 *hexstring_a2n_old (const char *str,__u8 *buf,int blen) +{ +int cnt =0 ; + +for (;;) { +unsigned acc; +char ch; + + acc =0 ; + +while ((ch = *str) !=':' && ch !=0 ) { +if (ch >='0' && ch <='9' ) + ch -='0' ; +else if (ch >='a' && ch <='f' ) + ch -='a' -10 ; +else if (ch >='A' && ch <='F' ) + ch -='A' -10 ; +else +return NULL ; + acc = (acc<<4 ) + ch; + str++; + } + +if (acc >255 ) +return NULL ; +if (cnt < blen) { + buf[cnt] = acc; + cnt++; + } +if (ch ==0 ) +break ; + ++str; + } +if (cnt < blen) +memset (buf+cnt,0 , blen-cnt); +return buf; +}int main (int argc,char **argv) {
@@ -715,8 +752,11 @@ int main(int argc, char **argv) goto do_abort; } -if (ll_addr_a2n ((char *) b1,6 , macbuf) !=6 ) + dbdat.data =hexstring_a2n_old (macbuf, b1,6 ); +if (dbdat.data ==NULL ) { +fprintf (stderr,"Invalid MAC address: \"%s\"\n" , macbuf); goto do_abort; + } dbdat.size =6 ;if (dbase->put (dbase, &dbkey, &dbdat,0 )) {
@@ -754,7 +794,7 @@ int main(int argc, char **argv) } } -if (do_load || do_list) +if (do_list) goto out; pset[0 ].fd =socket (PF_PACKET ,SOCK_DGRAM ,0 );
Signature · 1 line
2.7.0.windows.2