Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH 01/10] gdhcp: Check setsockopt() retval
      (Peter Meerwald-Stadler)
   2. [PATCH 03/10] firewall-ntables: Return correct errno value
      (Peter Meerwald-Stadler)
   3. [PATCH 00/10] Coverity warnings cleanup and fixes
      (Peter Meerwald-Stadler)
   4. [PATCH 04/10] gdhcp: Fix potential NULL deref
      (Peter Meerwald-Stadler)
   5. [PATCH 08/10] util: Make file handle of /dev/urandom static
      (Peter Meerwald-Stadler)
   6. [PATCH 05/10] ofono: Fix potential NULL deref
      (Peter Meerwald-Stadler)
   7. [PATCH 07/10] dhcpv6: Remove pointless compute_random()
      helper (Peter Meerwald-Stadler)
   8. [PATCH 06/10] peer_service: Setting retval ignored, always
      overwritten (Peter Meerwald-Stadler)
   9. [PATCH 02/10] gdhcp: Return correct errno value
      (Peter Meerwald-Stadler)
  10. [PATCH 10/10] shared: Drop unused shared/debugfs.c|.h
      (Peter Meerwald-Stadler)


----------------------------------------------------------------------

Message: 1
Date: Sat, 15 Oct 2016 12:35:05 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 01/10] gdhcp: Check setsockopt() retval
Message-ID: <[email protected]>

CID 1075205, 1075204, 1352468
---
 gdhcp/common.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/gdhcp/common.c b/gdhcp/common.c
index 3817bcc..7c89e3e 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -490,7 +490,11 @@ int dhcpv6_send_packet(int index, struct dhcpv6_packet 
*dhcp_pkt, int len)
        if (fd < 0)
                return -errno;
 
-       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
+               int err = errno;
+               close(fd);
+               return -err;
+       }
 
        memset(&src, 0, sizeof(src));
        src.sin6_family = AF_INET6;
@@ -641,7 +645,11 @@ int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
        if (fd < 0)
                return -errno;
 
-       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
+               int err = errno;
+               close(fd);
+               return -err;
+       }
 
        memset(&client, 0, sizeof(client));
        client.sin_family = AF_INET;
@@ -682,7 +690,11 @@ int dhcp_l3_socket(int port, const char *interface, int 
family)
        if (fd < 0)
                return -errno;
 
-       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
+               int err = errno;
+               close(fd);
+               return -err;
+       }
 
        if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
                                interface, strlen(interface) + 1) < 0) {
-- 
2.7.4



------------------------------

Message: 2
Date: Sat, 15 Oct 2016 12:35:07 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 03/10] firewall-ntables: Return correct errno value
Message-ID: <[email protected]>

---
 src/firewall-nftables.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/firewall-nftables.c b/src/firewall-nftables.c
index c88ba6a..d36e90b 100644
--- a/src/firewall-nftables.c
+++ b/src/firewall-nftables.c
@@ -261,8 +261,9 @@ static int socket_open_and_bind(struct mnl_socket **n)
         err = mnl_socket_bind(nl, 1 << (NFNLGRP_NFTABLES-1),
                                MNL_SOCKET_AUTOPID);
         if (err < 0) {
+               err = errno;
                mnl_socket_close(nl);
-                return -errno;
+                return -err;
        }
 
         *n = nl;
-- 
2.7.4



------------------------------

Message: 3
Date: Sat, 15 Oct 2016 12:35:04 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 00/10] Coverity warnings cleanup and fixes
Message-ID: <[email protected]>

I'm sending again the patch series posted Sept 17, addressing various Coverity 
warnings

this updated series addresses Patrik's review comments and adds patches (#2, 
#3) to fix the issue
of returning the correct errno:

  if (write(fd, ...) < 0) {
     close(fd);
     return -errno; 
  }

should be

  if (write(fd, ...) < 0) {
     int err = errno;
     close(fd);
     return -err; 
  }

I am not resending the proposed unification of get_random()

Peter Meerwald-Stadler (10):
  gdhcp: Check setsockopt() retval
  gdhcp: Return correct errno value
  firewall-ntables: Return correct errno value
  gdhcp: Fix potential NULL deref
  ofono: Fix potential NULL deref
  peer_service: Setting retval ignored, always overwritten
  dhcpv6: Remove pointless compute_random() helper
  util: Make file handle of /dev/urandom static
  util: Reading from /dev/urandom ignores the number of bytes read
  shared: Drop unused shared/debugfs.c|.h

 gdhcp/client.c          |  2 ++
 gdhcp/common.c          | 50 ++++++++++++++++++++++++++-----------
 gdhcp/ipv4ll.c          |  6 +++--
 plugins/ofono.c         |  3 ++-
 src/dhcpv6.c            | 14 +++--------
 src/firewall-nftables.c |  3 ++-
 src/peer_service.c      |  3 ---
 src/shared/debugfs.c    | 66 -------------------------------------------------
 src/shared/debugfs.h    | 24 ------------------
 src/util.c              | 11 ++++++---
 10 files changed, 58 insertions(+), 124 deletions(-)
 delete mode 100644 src/shared/debugfs.c
 delete mode 100644 src/shared/debugfs.h

-- 
2.7.4



------------------------------

Message: 4
Date: Sat, 15 Oct 2016 12:35:08 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 04/10] gdhcp: Fix potential NULL deref
Message-ID: <[email protected]>

packet6 is not set if dhcpv6_recv_l3_packet() returns an error

CID 1352473
---
 gdhcp/client.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gdhcp/client.c b/gdhcp/client.c
index e9e38e7..af1b953 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -2289,6 +2289,8 @@ static gboolean listener_event(GIOChannel *channel, 
GIOCondition condition,
                if (dhcp_client->type == G_DHCP_IPV6) {
                        re = dhcpv6_recv_l3_packet(&packet6, buf, sizeof(buf),
                                                dhcp_client->listener_sockfd);
+                       if (re < 0)
+                           return TRUE;
                        pkt_len = re;
                        pkt = packet6;
                        xid = packet6->transaction_id[0] << 16 |
-- 
2.7.4



------------------------------

Message: 5
Date: Sat, 15 Oct 2016 12:35:12 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 08/10] util: Make file handle of /dev/urandom static
Message-ID: <[email protected]>

---
 src/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util.c b/src/util.c
index da32cc5..d9cb905 100644
--- a/src/util.c
+++ b/src/util.c
@@ -36,7 +36,7 @@
 
 #define URANDOM "/dev/urandom"
 
-int f = -1;
+static int f = -1;
 
 int __connman_util_get_random(uint64_t *val)
 {
-- 
2.7.4



------------------------------

Message: 6
Date: Sat, 15 Oct 2016 12:35:09 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 05/10] ofono: Fix potential NULL deref
Message-ID: <[email protected]>

could probably also remove
if (!modem->context_list)
and assert that modem->context_list is NULL

CID 1352472
---
 plugins/ofono.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/plugins/ofono.c b/plugins/ofono.c
index 651cdaa..b6616e7 100644
--- a/plugins/ofono.c
+++ b/plugins/ofono.c
@@ -1801,7 +1801,8 @@ static void add_cdma_network(struct modem_data *modem)
                context = network_context_alloc(modem->path);
                modem->context_list = g_slist_prepend(modem->context_list,
                                                        context);
-       }
+       } else
+               context = modem->context_list->data;
 
        if (!modem->name)
                modem->name = g_strdup("CDMA Network");
-- 
2.7.4



------------------------------

Message: 7
Date: Sat, 15 Oct 2016 12:35:11 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 07/10] dhcpv6: Remove pointless compute_random()
        helper
Message-ID: <[email protected]>

the comment "Make sure the value is always positive so strip MSB" is not
appropriate, a guint is always positive, no need to strip one bit
---
 src/dhcpv6.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index 1bd0000..4346817 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -105,20 +105,14 @@ static void clear_timer(struct connman_dhcpv6 *dhcp)
        }
 }
 
-static inline guint get_random(void)
+static guint compute_random(guint val)
 {
-       uint64_t val;
-
-       __connman_util_get_random(&val);
+       uint64_t rand;
 
-       /* Make sure the value is always positive so strip MSB */
-       return ((uint32_t)val) >> 1;
-}
+       __connman_util_get_random(&rand);
 
-static guint compute_random(guint val)
-{
        return val - val / 10 +
-               (get_random() % (2 * 1000)) * val / 10 / 1000;
+               ((guint) rand % (2 * 1000)) * val / 10 / 1000;
 }
 
 /* Calculate a random delay, RFC 3315 chapter 14 */
-- 
2.7.4



------------------------------

Message: 8
Date: Sat, 15 Oct 2016 12:35:10 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 06/10] peer_service: Setting retval ignored, always
        overwritten
Message-ID: <[email protected]>

CID 1352484
---
 src/peer_service.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/peer_service.c b/src/peer_service.c
index 053672a..a457bff 100644
--- a/src/peer_service.c
+++ b/src/peer_service.c
@@ -293,9 +293,6 @@ int __connman_peer_service_register(const char *owner, 
DBusMessage *msg,
        if (service) {
                DBG("Found one existing service %p", service);
 
-               if (g_strcmp0(service->owner, owner))
-                       ret = -EBUSY;
-
                if (service->pending)
                        ret = -EINPROGRESS;
                else
-- 
2.7.4



------------------------------

Message: 9
Date: Sat, 15 Oct 2016 12:35:06 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 02/10] gdhcp: Return correct errno value
Message-ID: <[email protected]>

close() may overwrite errno
---
 gdhcp/common.c | 32 +++++++++++++++++++++-----------
 gdhcp/ipv4ll.c |  6 ++++--
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/gdhcp/common.c b/gdhcp/common.c
index 7c89e3e..146fc05 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -501,8 +501,9 @@ int dhcpv6_send_packet(int index, struct dhcpv6_packet 
*dhcp_pkt, int len)
        src.sin6_port = htons(DHCPV6_CLIENT_PORT);
 
        if (bind(fd, (struct sockaddr *) &src, sizeof(src)) <0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        memset(&dst, 0, sizeof(dst));
@@ -593,8 +594,9 @@ int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
        dest.sll_halen = 6;
        memcpy(dest.sll_addr, dest_arp, 6);
        if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        packet.ip.protocol = IPPROTO_UDP;
@@ -621,10 +623,13 @@ int dhcp_send_raw_packet(struct dhcp_packet *dhcp_pkt,
         */
        n = sendto(fd, &packet, IP_UPD_DHCP_SIZE, 0,
                        (struct sockaddr *) &dest, sizeof(dest));
-       close(fd);
+       if (n < 0) {
+               int err = errno;
+               close(fd);
+               return -err;
+       }
 
-       if (n < 0)
-               return -errno;
+       close(fd);
 
        return n;
 }
@@ -656,8 +661,9 @@ int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
        client.sin_port = htons(source_port);
        client.sin_addr.s_addr = htonl(source_ip);
        if (bind(fd, (struct sockaddr *) &client, sizeof(client)) < 0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        memset(&client, 0, sizeof(client));
@@ -665,17 +671,20 @@ int dhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
        client.sin_port = htons(dest_port);
        client.sin_addr.s_addr = htonl(dest_ip);
        if (connect(fd, (struct sockaddr *) &client, sizeof(client)) < 0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        n = write(fd, dhcp_pkt, DHCP_SIZE);
+       if (n < 0) {
+               int err = errno;
+               close(fd);
+               return -err;
+       }
 
        close(fd);
 
-       if (n < 0)
-               return -errno;
-
        return n;
 }
 
@@ -698,8 +707,9 @@ int dhcp_l3_socket(int port, const char *interface, int 
family)
 
        if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
                                interface, strlen(interface) + 1) < 0) {
+               int err = errno;
                close(fd);
-               return -1;
+               return -err;
        }
 
        if (family == AF_INET) {
diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
index c43971f..59adee6 100644
--- a/gdhcp/ipv4ll.c
+++ b/gdhcp/ipv4ll.c
@@ -85,8 +85,9 @@ int ipv4ll_send_arp_packet(uint8_t* source_eth, uint32_t 
source_ip,
        dest.sll_halen = ETH_ALEN;
        memset(dest.sll_addr, 0xFF, ETH_ALEN);
        if (bind(fd, (struct sockaddr *)&dest, sizeof(dest)) < 0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        ip_source = htonl(source_ip);
@@ -127,8 +128,9 @@ int ipv4ll_arp_socket(int ifindex)
        sock.sll_ifindex = ifindex;
 
        if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) != 0) {
+               int err = errno;
                close(fd);
-               return -errno;
+               return -err;
        }
 
        return fd;
-- 
2.7.4



------------------------------

Message: 10
Date: Sat, 15 Oct 2016 12:35:14 +0200
From: Peter Meerwald-Stadler <[email protected]>
To: Patrik Flykt <[email protected]>
Cc: [email protected]
Subject: [PATCH 10/10] shared: Drop unused shared/debugfs.c|.h
Message-ID: <[email protected]>

---
 src/shared/debugfs.c | 66 ----------------------------------------------------
 src/shared/debugfs.h | 24 -------------------
 2 files changed, 90 deletions(-)
 delete mode 100644 src/shared/debugfs.c
 delete mode 100644 src/shared/debugfs.h

diff --git a/src/shared/debugfs.c b/src/shared/debugfs.c
deleted file mode 100644
index f522c51..0000000
--- a/src/shared/debugfs.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
- *
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <limits.h>
-
-#include "src/shared/debugfs.h"
-
-#define STRINGIFY(x) STRINGIFY_ARG(x)
-#define STRINGIFY_ARG(x) #x
-
-const char *debugfs_get_path(void)
-{
-       static char path[PATH_MAX + 1];
-       static bool found = false;
-       char type[100];
-       FILE *fp;
-
-       if (found)
-               return path;
-
-       fp = fopen("/proc/mounts", "r");
-       if (!fp)
-               return NULL;
-
-       while (fscanf(fp, "%*s %" STRINGIFY(PATH_MAX) "s %99s %*s %*d %*d\n",
-                                                       path, type) == 2) {
-               if (!strcmp(type, "debugfs")) {
-                       found = true;
-                       break;
-               }
-       }
-
-       fclose(fp);
-
-       if (!found)
-               return NULL;
-
-       return path;
-}
diff --git a/src/shared/debugfs.h b/src/shared/debugfs.h
deleted file mode 100644
index 7f41ca7..0000000
--- a/src/shared/debugfs.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
- *
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-const char *debugfs_get_path(void);
-- 
2.7.4



------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 12, Issue 19
***************************************

Reply via email to