summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes2016-01-11 22:53:01 -0600
committerandroid-build-merger2016-01-11 22:53:01 -0600
commit34965eb1186041639a3e17057d7414c408ddd559 (patch)
tree55e6876919f5cd111b26b4915ed0264f16bb2c21 /libnetutils
parentc9e7c2da2d1ddb3c7c34f4722fe6326759a502fa (diff)
parentbe6d330c18f861fe10c0b238f74cecb2c9783205 (diff)
downloadplatform-system-core-34965eb1186041639a3e17057d7414c408ddd559.tar.gz
platform-system-core-34965eb1186041639a3e17057d7414c408ddd559.tar.xz
platform-system-core-34965eb1186041639a3e17057d7414c408ddd559.zip
Merge "libnetutils: Check socket() return value" am: e4b332c7e4
am: be6d330c18 * commit 'be6d330c18f861fe10c0b238f74cecb2c9783205': libnetutils: Check socket() return value
Diffstat (limited to 'libnetutils')
-rw-r--r--libnetutils/ifc_utils.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c
index aa18bc1f9..85ff070a7 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -261,6 +261,7 @@ int ifc_act_on_address(int action, const char *name, const char *address,
261 int prefixlen) { 261 int prefixlen) {
262 int ifindex, s, len, ret; 262 int ifindex, s, len, ret;
263 struct sockaddr_storage ss; 263 struct sockaddr_storage ss;
264 int saved_errno;
264 void *addr; 265 void *addr;
265 size_t addrlen; 266 size_t addrlen;
266 struct { 267 struct {
@@ -325,15 +326,21 @@ int ifc_act_on_address(int action, const char *name, const char *address,
325 memcpy(RTA_DATA(rta), addr, addrlen); 326 memcpy(RTA_DATA(rta), addr, addrlen);
326 327
327 s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); 328 s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
329 if (s < 0) {
330 return -errno;
331 }
332
328 if (send(s, &req, req.n.nlmsg_len, 0) < 0) { 333 if (send(s, &req, req.n.nlmsg_len, 0) < 0) {
334 saved_errno = errno;
329 close(s); 335 close(s);
330 return -errno; 336 return -saved_errno;
331 } 337 }
332 338
333 len = recv(s, buf, sizeof(buf), 0); 339 len = recv(s, buf, sizeof(buf), 0);
340 saved_errno = errno;
334 close(s); 341 close(s);
335 if (len < 0) { 342 if (len < 0) {
336 return -errno; 343 return -saved_errno;
337 } 344 }
338 345
339 // Parse the acknowledgement to find the return code. 346 // Parse the acknowledgement to find the return code.