All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pascal <pascal@pascalhp.net>
To: netdev@vger.kernel.org
Subject: [PATCH] Temporary patch for arpd
Date: Wed, 12 Oct 2016 05:50:36 +0800	[thread overview]
Message-ID: <1006734637.20161012055036@pascalhp.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

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 =)

[-- Attachment #2: 0001-Temporary-patch-for-arpd.patch --]
[-- Type: application/octet-stream, Size: 1694 bytes --]

From 433147a7303c418845bdb5668910caababf79453 Mon Sep 17 00:00:00 2001
From: Pascal <pascal@pascalhp.net>
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(-)

diff --git a/misc/arpd.c b/misc/arpd.c
index bfab445..567df5b 100644
--- a/misc/arpd.c
+++ b/misc/arpd.c
@@ -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);
-- 
2.7.0.windows.2


                 reply	other threads:[~2016-10-11 21:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1006734637.20161012055036@pascalhp.net \
    --to=pascal@pascalhp.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.