Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/rpcbind check strdup results too



details:   https://anonhg.NetBSD.org/src/rev/608f7b2152f5
branches:  trunk
changeset: 838120:608f7b2152f5
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Jan 03 19:26:50 2019 +0000

description:
check strdup results too
include the function name in out of memory messages

diffstat:

 usr.sbin/rpcbind/rpcb_svc_com.c |  26 ++++++++++++++------------
 usr.sbin/rpcbind/rpcbind.c      |  39 +++++++++++++++++++++++++--------------
 2 files changed, 39 insertions(+), 26 deletions(-)

diffs (191 lines):

diff -r 962dc71e7856 -r 608f7b2152f5 usr.sbin/rpcbind/rpcb_svc_com.c
--- a/usr.sbin/rpcbind/rpcb_svc_com.c   Thu Jan 03 19:04:21 2019 +0000
+++ b/usr.sbin/rpcbind/rpcb_svc_com.c   Thu Jan 03 19:26:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpcb_svc_com.c,v 1.21 2019/01/03 19:04:21 christos Exp $       */
+/*     $NetBSD: rpcb_svc_com.c,v 1.22 2019/01/03 19:26:50 christos Exp $       */
 /*     $FreeBSD: head/usr.sbin/rpcbind/rpcb_svc_com.c 301770 2016-06-09 22:25:00Z pfg $ */
 
 /*-
@@ -306,8 +306,12 @@
                reg.r_prog = rbl->rpcb_map.r_prog;
                reg.r_vers = rbl->rpcb_map.r_vers;
                reg.r_netid = strdup(rbl->rpcb_map.r_netid);
-               (void)map_unset(&reg, rpcbind_superuser);
-               free(reg.r_netid);
+               if (reg.r_netid == NULL)
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
+               else {
+                       (void)map_unset(&reg, rpcbind_superuser);
+                       free(reg.r_netid);
+               }
        }
 }
 
@@ -508,16 +512,16 @@
                        nconf->nc_device, errno);
                return (-1);
        }
-       xprt = svc_tli_create(fd, 0, (struct t_bind *) 0, 0, 0);
+       xprt = svc_tli_create(fd, 0, NULL, 0, 0);
        if (xprt == NULL) {
                if (debugging)
                        fprintf(stderr,
-                               "create_rmtcall_fd: svc_tli_create failed\n");
+                               "%s: svc_tli_create failed\n", __func__);
                return (-1);
        }
-       rmt = malloc(sizeof(struct rmtcallfd_list));
+       rmt = malloc(sizeof(*rmt));
        if (rmt == NULL) {
-               syslog(LOG_ERR, "create_rmtcall_fd: no memory!");
+               syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                return (-1);
        }
        rmt->xprt = xprt;
@@ -813,9 +817,7 @@
                if (outbuf_alloc == NULL) {
                        if (reply_type == RPCBPROC_INDIRECT)
                                svcerr_systemerr(transp);
-                       if (debugging)
-                               fprintf(stderr,
-                               "rpcbproc_callit_com:  No memory!\n");
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                        goto error;
                }
                xdrmem_create(&outxdr, outbuf_alloc, sendsz, XDR_ENCODE);
@@ -1462,7 +1464,7 @@
         */
        pml = malloc(sizeof(*pml));
        if (pml == NULL) {
-               (void) syslog(LOG_ERR, "rpcbind: no memory!\n");
+               syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                return (1);
        }
        pml->pml_map = pmap;
@@ -1474,7 +1476,7 @@
 
                /* Attach to the end of the list */
                for (fnd = list_pml; fnd->pml_next; fnd = fnd->pml_next)
-                       ;
+                       continue;
                fnd->pml_next = pml;
        }
        return (0);
diff -r 962dc71e7856 -r 608f7b2152f5 usr.sbin/rpcbind/rpcbind.c
--- a/usr.sbin/rpcbind/rpcbind.c        Thu Jan 03 19:04:21 2019 +0000
+++ b/usr.sbin/rpcbind/rpcbind.c        Thu Jan 03 19:26:50 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rpcbind.c,v 1.26 2019/01/03 19:04:21 christos Exp $    */
+/*     $NetBSD: rpcbind.c,v 1.27 2019/01/03 19:26:50 christos Exp $    */
 
 /*-
  * Copyright (c) 2009, Sun Microsystems, Inc.
@@ -482,9 +482,8 @@
                        taddr.addr.len = taddr.addr.maxlen = addrlen;
                        taddr.addr.buf = malloc(addrlen);
                        if (taddr.addr.buf == NULL) {
-                               syslog(LOG_ERR,
-                                   "cannot allocate memory for %s address",
-                                   nconf->nc_netid);
+                               syslog(LOG_ERR, "%s: Cannot allocate memory",
+                                   __func__);
                                if (res != NULL)
                                        freeaddrinfo(res);
                                return 1;
@@ -540,8 +539,7 @@
                taddr.addr.len = taddr.addr.maxlen = addrlen;
                taddr.addr.buf = malloc(addrlen);
                if (taddr.addr.buf == NULL) {
-                       syslog(LOG_ERR, "cannot allocate memory for %s address",
-                           nconf->nc_netid);
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                        if (res != NULL)
                            freeaddrinfo(res);
                        return 1;
@@ -567,7 +565,7 @@
 
                my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr,
                    RPC_MAXDATASIZE, RPC_MAXDATASIZE);
-               if (my_xprt == (SVCXPRT *)NULL) {
+               if (my_xprt == NULL) {
                        syslog(LOG_ERR, "%s: could not create service",
                            nconf->nc_netid);
                        goto error;
@@ -592,7 +590,7 @@
                }
                pml = malloc(sizeof(*pml));
                if (pml == NULL) {
-                       syslog(LOG_ERR, "Cannot allocate memory");
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                        goto error;
                }
 
@@ -609,7 +607,8 @@
                        tcptrans = strdup(nconf->nc_netid);
                        if (tcptrans == NULL) {
                                free(pml);
-                               syslog(LOG_ERR, "Cannot allocate memory");
+                               syslog(LOG_ERR, "%s: Cannot allocate memory",
+                                   __func__);
                                goto error;
                        }
                        pml->pml_map.pm_prot = IPPROTO_TCP;
@@ -627,7 +626,8 @@
                        udptrans = strdup(nconf->nc_netid);
                        if (udptrans == NULL) {
                                free(pml);
-                               syslog(LOG_ERR, "Cannot allocate memory");
+                               syslog(LOG_ERR, "%s: Cannot allocate memory",
+                                   __func__);
                                goto error;
                        }
                        pml->pml_map.pm_prot = IPPROTO_UDP;
@@ -646,7 +646,7 @@
                /* Add version 3 information */
                pml = malloc(sizeof(*pml));
                if (pml == NULL) {
-                       syslog(LOG_ERR, "Cannot allocate memory");
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                        goto error;
                }
                pml->pml_map = list_pml->pml_map;
@@ -657,7 +657,7 @@
                /* Add version 4 information */
                pml = malloc(sizeof(*pml));
                if (pml == NULL) {
-                       syslog(LOG_ERR, "Cannot allocate memory");
+                       syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                        goto error;
                }
                pml->pml_map = list_pml->pml_map;
@@ -812,9 +812,9 @@
 {
        rpcblist_ptr rbl;
 
-       rbl = malloc(sizeof(*rbl));
+       rbl = calloc(1, sizeof(*rbl));
        if (rbl == NULL) {
-               syslog(LOG_ERR, "Out of memory");
+               syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
                return;
        }
 
@@ -823,6 +823,17 @@
        rbl->rpcb_map.r_netid = strdup(nconf->nc_netid);
        rbl->rpcb_map.r_addr = taddr2uaddr(nconf, addr);
        rbl->rpcb_map.r_owner = strdup(rpcbind_superuser);
+       if (rbl->rpcb_map.r_netid == NULL ||
+           rbl->rpcb_map.r_addr == NULL ||
+           rbl->rpcb_map.r_owner == NULL)
+       {
+           free(rbl->rpcb_map.r_netid);
+           free(rbl->rpcb_map.r_addr);
+           free(rbl->rpcb_map.r_owner);
+           free(rbl);
+           syslog(LOG_ERR, "%s: Cannot allocate memory", __func__);
+           return;
+       }
        rbl->rpcb_next = list_rbl;      /* Attach to global list */
        list_rbl = rbl;
 }



Home | Main Index | Thread Index | Old Index