Skip to contentSkip to conversation

acd: check fd return to satisfy static analysis

PATCH Applied James Prestwood 2 participants 6 messages Feb 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 acd: check fd return to satisfy static analysis

---
 ell/acd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
ell/acd.c +8 -1
index 6381747..d5c5024 100644
@@ -129,6 +129,9 @@ static int acd_send_packet(struct l_acd *acd, uint32_t source_ip)
 	int n;
 	int fd = l_io_get_fd(acd->io);
 
+	if (fd < 0)
+		return fd;
+
 	memset(&dest, 0, sizeof(dest));
 	memset(&p, 0, sizeof(p));
 
@@ -260,9 +263,13 @@ static bool acd_read_handler(struct l_io *io, void *user_data)
 	int source_conflict;
 	int target_conflict;
 	bool probe;
+	int fd = l_io_get_fd(acd->io);
+
+	if (fd < 0)
+		return true;
 
 	memset(&arp, 0, sizeof(arp));
-	len = read(l_io_get_fd(acd->io), &arp, sizeof(arp));
+	len = read(fd, &arp, sizeof(arp));
 	if (len < 0)
 		return false;
 
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/3 dhcp: free rtnl address on error

---
 ell/dhcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ell/dhcp.c +3 -1
index f212e9b..d05ec70 100644
@@ -740,8 +740,10 @@ static int dhcp_client_receive_ack(struct l_dhcp_client *client,
 						client, NULL);
 		if (client->rtnl_add_cmdid)
 			client->rtnl_configured_address = a;
-		else
+		else {
 			CLIENT_DEBUG("Configuring address via RTNL failed");
+			l_rtnl_address_free(a);
+		}
 	}
 
 	return r;
Signature · 1 line
2.26.2
#2 lore raw

Re: [PATCH 2/3] dhcp: free rtnl address on error

Hi James,

Quoted 4 lines · James Prestwood
---
  ell/dhcp.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis

#3 lore raw

PATCH 3/3 unit: free cli_addr at end of test

In reply to James Prestwood
---
 unit/test-dhcp.c | 1 +
 1 file changed, 1 insertion(+)
unit/test-dhcp.c +1 -0
index ad06c14..d67b1b5 100644
@@ -1001,6 +1001,7 @@ static void test_expired_ip_reuse(const void *data)
 	assert(lease);
 	cli_addr = l_dhcp_lease_get_address(lease);
 	assert(!strcmp(cli_addr, "192.168.1.2"));
+	l_free(cli_addr);
 }
 
 int main(int argc, char *argv[])
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH 3/3] unit: free cli_addr at end of test

Hi James,

Quoted 4 lines · James Prestwood
---
  unit/test-dhcp.c | 1 +
  1 file changed, 1 insertion(+)

I pushed out almost the same patch in commit
a0d6a77dd3b5ccac976fca54836200f350427013

Regards,
-Denis

#5 lore raw
In reply to James Prestwood

Hi James,

Quoted 9 lines · James Prestwood
---
  ell/acd.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
ell/acd.c +0 -0
index 6381747..d5c5024 100644

ell/acd.c static int acd_send_packet(struct l_acd *acd, uint32_t source_ip) · line 134

Quoted 6 lines
ell/acd.c +3 -0
@@ -129,6 +129,9 @@ static int acd_send_packet(struct l_acd *acd, uint32_t source_ip)
  	int n;
  	int fd = l_io_get_fd(acd->io);
 
+	if (fd < 0)
+		return fd;
+

Nah, don't bother with these. If the socket is invalid, the destroy handler should be set / notified.

ell/acd.c static bool acd_read_handler(struct l_io *io, void *user_data) · line 269

Quoted 11 lines
ell/acd.c +4 -0
  	memset(&dest, 0, sizeof(dest));
  	memset(&p, 0, sizeof(p));
 
@@ -260,9 +263,13 @@ static bool acd_read_handler(struct l_io *io, void *user_data)
  	int source_conflict;
  	int target_conflict;
  	bool probe;
+	int fd = l_io_get_fd(acd->io);
+
+	if (fd < 0)
+		return true;

And it can't be negative in the read handler anyway.

ell/acd.c static bool acd_read_handler(struct l_io *io, void *user_data)

Quoted 8 lines
ell/acd.c +1 -1
  	memset(&arp, 0, sizeof(arp));
-	len = read(l_io_get_fd(acd->io), &arp, sizeof(arp));
+	len = read(fd, &arp, sizeof(arp));
  	if (len < 0)
  		return false;
 
 

Regards,
-Denis