Skip to contentSkip to conversation

batctl: Fix static buffer for resolved mac adddress

PATCH Applied Sven Eckelmann 2 participants 4 messages Oct 15, 2013 – Oct 26, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 batctl: Fix static buffer for resolved mac adddress

The resolve_mac_* functions are currently not reentrant-safe because they are using ether_aton. Thus all functions returning a mac address in a similar way must also ensure that their data is in a statically allocated buffer and not on a stack.

resolve_mac_from_cache did that for the wrong buffer.

---
 functions.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
functions.c +2 -2
index 9e03e72..959784b 100644
@@ -630,8 +630,8 @@ static int resolve_mac_from_cache_parse(struct ndmsg *ndmsg, size_t len_payload,
 static struct ether_addr *resolve_mac_from_cache(int ai_family,
 						 const void *l3addr)
 {
-	static uint8_t l3addr_tmp[16];
-	struct ether_addr mac_tmp;
+	uint8_t l3addr_tmp[16];
+	static struct ether_addr mac_tmp;
 	struct ether_addr *mac_result = NULL;
 	void *buf = NULL;
 	size_t buflen;
Signature · 1 line
1.8.4.rc3
#1 lore raw

PATCH 2/2 batctl: Finish resolving of mac address early

It is not necessary to check the remaining msg buffer coming from the kernel when already the correct mac address was found.

---
 functions.c | 1 +
 1 file changed, 1 insertion(+)
functions.c +1 -0
index 959784b..f2b23f2 100644
@@ -683,6 +683,7 @@ static struct ether_addr *resolve_mac_from_cache(int ai_family,
 			if (parsed) {
 				if (memcmp(&l3addr_tmp, l3addr, l3_len) == 0) {
 					mac_result = &mac_tmp;
+					finished = 1;
 					break;
 				}
 			}
Signature · 1 line
1.8.4.rc3
#2 lore raw

Re: [B.A.T.M.A.N.] [PATCH 2/2] batctl: Finish resolving of mac address early

Quoted 7 lines · On Tuesday 15 October 2013 18:01:09 Sven Eckelmann wrote:

It is not necessary to check the remaining msg buffer coming from the kernel when already the correct mac address was found.

---
 functions.c | 1 +
 1 file changed, 1 insertion(+)

Applied in revision 7cd9934.

Thanks,
Marek

#3 lore raw
In reply to Sven Eckelmann
Quoted 11 lines · On Tuesday 15 October 2013 18:01:08 Sven Eckelmann wrote:

The resolve_mac_* functions are currently not reentrant-safe because they are using ether_aton. Thus all functions returning a mac address in a similar way must also ensure that their data is in a statically allocated buffer and not on a stack.

resolve_mac_from_cache did that for the wrong buffer.

---
 functions.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied in revision ef41a8d.

Thanks,
Marek