summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Andersson2015-12-29 13:17:05 -0600
committerBjorn Andersson2015-12-29 13:17:05 -0600
commit292997420c6fc385f31e568620476b0b71de97be (patch)
tree383672a502accb1287de1747c36db420cbea7695 /libnetutils
parent0f0498ad508e6747dc7b72a6e63de2f2befa2e1c (diff)
downloadplatform-system-core-292997420c6fc385f31e568620476b0b71de97be.tar.gz
platform-system-core-292997420c6fc385f31e568620476b0b71de97be.tar.xz
platform-system-core-292997420c6fc385f31e568620476b0b71de97be.zip
libnetutils: Check socket() return value
Add a check for socket() errors and make sure to preserve errno over the subsequent close() calls. Change-Id: If52d76cd3cb45044eaaf7fea9bfd4471dc66a078
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 956ed30c3..e0a9f7f88 100644
--- a/libnetutils/ifc_utils.c
+++ b/libnetutils/ifc_utils.c
@@ -253,6 +253,7 @@ int ifc_act_on_address(int action, const char *name, const char *address,
253 int prefixlen) { 253 int prefixlen) {
254 int ifindex, s, len, ret; 254 int ifindex, s, len, ret;
255 struct sockaddr_storage ss; 255 struct sockaddr_storage ss;
256 int saved_errno;
256 void *addr; 257 void *addr;
257 size_t addrlen; 258 size_t addrlen;
258 struct { 259 struct {
@@ -317,15 +318,21 @@ int ifc_act_on_address(int action, const char *name, const char *address,
317 memcpy(RTA_DATA(rta), addr, addrlen); 318 memcpy(RTA_DATA(rta), addr, addrlen);
318 319
319 s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE); 320 s = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_ROUTE);
321 if (s < 0) {
322 return -errno;
323 }
324
320 if (send(s, &req, req.n.nlmsg_len, 0) < 0) { 325 if (send(s, &req, req.n.nlmsg_len, 0) < 0) {
326 saved_errno = errno;
321 close(s); 327 close(s);
322 return -errno; 328 return -saved_errno;
323 } 329 }
324 330
325 len = recv(s, buf, sizeof(buf), 0); 331 len = recv(s, buf, sizeof(buf), 0);
332 saved_errno = errno;
326 close(s); 333 close(s);
327 if (len < 0) { 334 if (len < 0) {
328 return -errno; 335 return -saved_errno;
329 } 336 }
330 337
331 // Parse the acknowledgement to find the return code. 338 // Parse the acknowledgement to find the return code.