Coverity reports that daemon_set_new_user() may receive a large
unsigned value from get_sysconf_buffer_size(), due to sysconf()
returning -1 and being cast to size_t.

Although this would likely lead to an allocation failure and abort,
it's better to handle the error in place.

Signed-off-by: Eelco Chaudron <echau...@redhat.com>
---
 lib/daemon-unix.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
index 4fdc6e3c4..78a013645 100644
--- a/lib/daemon-unix.c
+++ b/lib/daemon-unix.c
@@ -915,8 +915,9 @@ daemon_become_new_user(bool access_datapath, bool 
access_hardware_ports)
 static size_t
 get_sysconf_buffer_size(void)
 {
-    size_t bufsize, pwd_bs = 0, grp_bs = 0;
     const size_t default_bufsize = 1024;
+    long pwd_bs = 0, grp_bs = 0;
+    size_t bufsize;
 
     errno = 0;
     if ((pwd_bs = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1) {
@@ -924,14 +925,19 @@ get_sysconf_buffer_size(void)
             VLOG_FATAL("%s: Read initial passwordd struct size "
                        "failed (%s), aborting. ", pidfile,
                        ovs_strerror(errno));
+        } else {
+            pwd_bs = default_bufsize;
         }
     }
 
+    errno = 0;
     if ((grp_bs = sysconf(_SC_GETGR_R_SIZE_MAX)) == -1) {
         if (errno) {
             VLOG_FATAL("%s: Read initial group struct size "
                        "failed (%s), aborting. ", pidfile,
                        ovs_strerror(errno));
+        } else {
+            grp_bs = default_bufsize;
         }
     }
 
-- 
2.49.0

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to