]> git.ozlabs.org Git - ppp.git/commitdiff
Various fixes for errors found by coverity static analysis (#109)
authorJaroslav Škarvada <jskarvad@redhat.com>
Sun, 5 May 2019 22:46:02 +0000 (00:46 +0200)
committerPaul Mackerras <paulus@samba.org>
Sun, 5 May 2019 22:46:02 +0000 (08:46 +1000)
Fixes #108

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
17 files changed:
chat/chat.c
pppd/auth.c
pppd/multilink.c
pppd/plugins/pppol2tp/openl2tp.c
pppd/plugins/radius/avpair.c
pppd/plugins/radius/config.c
pppd/plugins/radius/radius.c
pppd/plugins/radius/radiusclient.h
pppd/plugins/radius/radrealms.c
pppd/plugins/rp-pppoe/Makefile.linux
pppd/plugins/rp-pppoe/if.c
pppd/plugins/rp-pppoe/plugin.c
pppd/plugins/rp-pppoe/pppoe-discovery.c
pppd/plugins/rp-pppoe/pppoe.h
pppd/plugins/winbind.c
pppd/sys-linux.c
pppstats/pppstats.c

index 710dba9a41c9c0edeb7d916ce1a7171ea80855d5..bf107335c8458fa296a75f171c967b6669fb4a17 100644 (file)
@@ -512,6 +512,7 @@ void msgf __V((const char *fmt, ...))
        syslog(LOG_INFO, "%s", line);
     if (to_stderr)
        fprintf(stderr, "%s\n", line);
        syslog(LOG_INFO, "%s", line);
     if (to_stderr)
        fprintf(stderr, "%s\n", line);
+    va_end(args);
 }
 
 /*
 }
 
 /*
@@ -537,6 +538,7 @@ void fatal __V((int code, const char *fmt, ...))
        syslog(LOG_ERR, "%s", line);
     if (to_stderr)
        fprintf(stderr, "%s\n", line);
        syslog(LOG_ERR, "%s", line);
     if (to_stderr)
        fprintf(stderr, "%s\n", line);
+    va_end(args);
     terminate(code);
 }
 
     terminate(code);
 }
 
index 7457eda227bf19c2d09b79dd4e0b031da6bc1bf9..590a265eda7b3cb646493d8fbc812a5a3ed25162 100644 (file)
@@ -430,6 +430,7 @@ setupapfile(argv)
     euid = geteuid();
     if (seteuid(getuid()) == -1) {
        option_error("unable to reset uid before opening %s: %m", fname);
     euid = geteuid();
     if (seteuid(getuid()) == -1) {
        option_error("unable to reset uid before opening %s: %m", fname);
+        free(fname);
        return 0;
     }
     ufile = fopen(fname, "r");
        return 0;
     }
     ufile = fopen(fname, "r");
@@ -437,6 +438,7 @@ setupapfile(argv)
        fatal("unable to regain privileges: %m");
     if (ufile == NULL) {
        option_error("unable to open user login data file %s", fname);
        fatal("unable to regain privileges: %m");
     if (ufile == NULL) {
        option_error("unable to open user login data file %s", fname);
+        free(fname);
        return 0;
     }
     check_access(ufile, fname);
        return 0;
     }
     check_access(ufile, fname);
@@ -447,6 +449,7 @@ setupapfile(argv)
        || fgets(p, MAXSECRETLEN - 1, ufile) == NULL) {
        fclose(ufile);
        option_error("unable to read user login data file %s", fname);
        || fgets(p, MAXSECRETLEN - 1, ufile) == NULL) {
        fclose(ufile);
        option_error("unable to read user login data file %s", fname);
+        free(fname);
        return 0;
     }
     fclose(ufile);
        return 0;
     }
     fclose(ufile);
@@ -468,6 +471,7 @@ setupapfile(argv)
        explicit_passwd = 1;
     }
 
        explicit_passwd = 1;
     }
 
+    free(fname);
     return (1);
 }
 
     return (1);
 }
 
index 135cab0b42ad419d1c4297240cf464ca6b83b14f..c49c4465ced8f1b65d3be54c35b71c000c0ac33b 100644 (file)
@@ -445,9 +445,13 @@ get_default_epdisc(ep)
        if (p != 0 && get_if_hwaddr(ep->value, p) >= 0) {
                ep->class = EPD_MAC;
                ep->length = 6;
        if (p != 0 && get_if_hwaddr(ep->value, p) >= 0) {
                ep->class = EPD_MAC;
                ep->length = 6;
+               free(p);
                return 1;
        }
 
                return 1;
        }
 
+       if (p)
+               free(p);
+
        /* see if our hostname corresponds to a reasonable IP address */
        hp = gethostbyname(hostname);
        if (hp != NULL) {
        /* see if our hostname corresponds to a reasonable IP address */
        hp = gethostbyname(hostname);
        if (hp != NULL) {
index 9643b965792b0e8188e2de76cda18e30971d16f7..85ff0b56cdc5b839382a2f970034419c6bcb7756 100644 (file)
@@ -246,6 +246,9 @@ out:
                (*old_pppol2tp_ip_updown_hook)(tunnel_id, session_id, up);
        }
 
                (*old_pppol2tp_ip_updown_hook)(tunnel_id, session_id, up);
        }
 
+       if (user_name != NULL)
+               free(user_name);
+
        return;
 }
 
        return;
 }
 
index 716d23f2efb7df7c9c059b1f592339c189730976..b22a0a2423dc3302c593508ffd5dd2565350792d 100644 (file)
@@ -121,7 +121,7 @@ VALUE_PAIR *rc_avpair_new (int attrid, void *pval, int len, int vendorcode)
                if ((vp = (VALUE_PAIR *) malloc (sizeof (VALUE_PAIR)))
                                                        != (VALUE_PAIR *) NULL)
                {
                if ((vp = (VALUE_PAIR *) malloc (sizeof (VALUE_PAIR)))
                                                        != (VALUE_PAIR *) NULL)
                {
-                       strncpy (vp->name, pda->name, sizeof (vp->name));
+                       strlcpy (vp->name, pda->name, NAME_LENGTH);
                        vp->attribute = attrid;
                        vp->vendorcode = vendorcode;
                        vp->next = (VALUE_PAIR *) NULL;
                        vp->attribute = attrid;
                        vp->vendorcode = vendorcode;
                        vp->next = (VALUE_PAIR *) NULL;
index a29e5e8da90918ffd446b4fda92ca847a4d50667..6e36d898a27a58bdae7e29f8e616797ff1eb0ab2 100644 (file)
@@ -153,6 +153,7 @@ static int set_option_auo(char *filename, int line, OPTION *option, char *p)
                        *iptr = AUTH_RADIUS_FST;
        else {
                error("%s: auth_order: unknown keyword: %s", filename, p);
                        *iptr = AUTH_RADIUS_FST;
        else {
                error("%s: auth_order: unknown keyword: %s", filename, p);
+               free(iptr);
                return (-1);
        }
 
                return (-1);
        }
 
@@ -165,6 +166,7 @@ static int set_option_auo(char *filename, int line, OPTION *option, char *p)
                        *iptr = (*iptr) | AUTH_RADIUS_SND;
                else {
                        error("%s: auth_order: unknown or unexpected keyword: %s", filename, p);
                        *iptr = (*iptr) | AUTH_RADIUS_SND;
                else {
                        error("%s: auth_order: unknown or unexpected keyword: %s", filename, p);
+                       free(iptr);
                        return (-1);
                }
        }
                        return (-1);
                }
        }
@@ -272,7 +274,7 @@ char *rc_conf_str(char *optname)
 
        if (option == NULL)
                fatal("rc_conf_str: unkown config option requested: %s", optname);
 
        if (option == NULL)
                fatal("rc_conf_str: unkown config option requested: %s", optname);
-               return (char *)option->val;
+       return (char *)option->val;
 }
 
 int rc_conf_int(char *optname)
 }
 
 int rc_conf_int(char *optname)
index fbf872006005b59ca5472f73b1a5c1b69007bef4..5f75aaedc54b6afb63b31fa4b07566e551bb5c38 100644 (file)
@@ -898,7 +898,7 @@ radius_acct_start(void)
 
     rstate.start_time = time(NULL);
 
 
     rstate.start_time = time(NULL);
 
-    strncpy(rstate.session_id, rc_mksid(), sizeof(rstate.session_id));
+    strlcpy(rstate.session_id, rc_mksid(), MAXSESSIONID);
 
     rc_avpair_add(&send, PW_ACCT_SESSION_ID,
                   rstate.session_id, 0, VENDOR_NONE);
 
     rc_avpair_add(&send, PW_ACCT_SESSION_ID,
                   rstate.session_id, 0, VENDOR_NONE);
index 51b959a808e9e584e1a4f23be006b05202dbd2fb..cff0c268ad304001595bd17a61d333b13dc0b91a 100644 (file)
@@ -440,6 +440,7 @@ UINT4 rc_get_ipaddr __P((char *));
 int rc_good_ipaddr __P((char *));
 const char *rc_ip_hostname __P((UINT4));
 UINT4 rc_own_ipaddress __P((void));
 int rc_good_ipaddr __P((char *));
 const char *rc_ip_hostname __P((UINT4));
 UINT4 rc_own_ipaddress __P((void));
+UINT4 rc_own_bind_ipaddress __P((void));
 
 
 /*     sendserver.c            */
 
 
 /*     sendserver.c            */
index 7a30370121bdbca99fab7ac7b7479b74933d3d6b..cd006fd0894cae2cae87ec303daf1256839cbe87 100644 (file)
@@ -68,10 +68,12 @@ lookup_realm(char const *user,
     
     if ((fd = fopen(radrealms_config, "r")) == NULL) {
        option_error("cannot open %s", radrealms_config);
     
     if ((fd = fopen(radrealms_config, "r")) == NULL) {
        option_error("cannot open %s", radrealms_config);
+       free(auths);
+       free(accts);
        return;
        return;
-    } 
+    }
     info("Reading %s", radrealms_config);
     info("Reading %s", radrealms_config);
-    
+
     while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
        line++;
 
     while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
        line++;
 
@@ -87,6 +89,8 @@ lookup_realm(char const *user,
            fclose(fd);
            option_error("%s: invalid line %d: %s", radrealms_config,
                         line, buffer);
            fclose(fd);
            option_error("%s: invalid line %d: %s", radrealms_config,
                         line, buffer);
+           free(auths);
+           free(accts);
            return;
        }
        info("Parsing '%s' entry:", p);
            return;
        }
        info("Parsing '%s' entry:", p);
@@ -101,6 +105,8 @@ lookup_realm(char const *user,
            fclose(fd);
            option_error("%s: realm name missing on line %d: %s",
                         radrealms_config, line, buffer);
            fclose(fd);
            option_error("%s: realm name missing on line %d: %s",
                         radrealms_config, line, buffer);
+           free(auths);
+           free(accts);
            return;
        }
 
            return;
        }
 
@@ -111,6 +117,8 @@ lookup_realm(char const *user,
                fclose(fd);
                option_error("%s: server address missing on line %d: %s",
                             radrealms_config, line, buffer);
                fclose(fd);
                option_error("%s: server address missing on line %d: %s",
                             radrealms_config, line, buffer);
+               free(auths);
+               free(accts);
                return;
            }
            s->name[s->max] = strdup(p);
                return;
            }
            s->name[s->max] = strdup(p);
@@ -119,6 +127,8 @@ lookup_realm(char const *user,
                fclose(fd);
                option_error("%s: server port missing on line %d:  %s",
                             radrealms_config, line, buffer);
                fclose(fd);
                option_error("%s: server port missing on line %d:  %s",
                             radrealms_config, line, buffer);
+               free(auths);
+               free(accts);
                return;
            }
            s->port[s->max] = atoi(p);
                return;
            }
            s->port[s->max] = atoi(p);
index 9803aeb4ebbae07bb7d8a527f942b753eb5b404e..749ccc2c931cc8406189fe90ae7d53219db4ed99 100644 (file)
@@ -33,10 +33,10 @@ pppoe-discovery: pppoe-discovery.o debug.o
        $(CC) $(LDFLAGS) -o pppoe-discovery pppoe-discovery.o debug.o
 
 pppoe-discovery.o: pppoe-discovery.c
        $(CC) $(LDFLAGS) -o pppoe-discovery pppoe-discovery.o debug.o
 
 pppoe-discovery.o: pppoe-discovery.c
-       $(CC) $(CFLAGS) -c -o pppoe-discovery.o pppoe-discovery.c
+       $(CC) $(CFLAGS) -I../../.. -c -o pppoe-discovery.o pppoe-discovery.c
 
 debug.o: debug.c
 
 debug.o: debug.c
-       $(CC) $(CFLAGS) -c -o debug.o debug.c
+       $(CC) $(CFLAGS) -I../../.. -c -o debug.o debug.c
 
 rp-pppoe.so: plugin.o discovery.o if.o common.o
        $(CC) $(LDFLAGS) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
 
 rp-pppoe.so: plugin.o discovery.o if.o common.o
        $(CC) $(LDFLAGS) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
index 91e9a57dd4024b48cb4ab4276994194763f38be3..07b20b1717ab5e9637a0394e5f83154733a272d7 100644 (file)
@@ -133,7 +133,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
 
     /* Fill in hardware address */
     if (hwaddr) {
 
     /* Fill in hardware address */
     if (hwaddr) {
-       strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+       strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
        if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
            error("Can't get hardware address for %s: %m", ifname);
            close(fd);
        if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) {
            error("Can't get hardware address for %s: %m", ifname);
            close(fd);
@@ -152,7 +152,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     }
 
     /* Sanity check on MTU */
     }
 
     /* Sanity check on MTU */
-    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
     if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
        error("Can't get MTU for %s: %m", ifname);
     } else if (ifr.ifr_mtu < ETH_DATA_LEN) {
     if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) {
        error("Can't get MTU for %s: %m", ifname);
     } else if (ifr.ifr_mtu < ETH_DATA_LEN) {
@@ -166,7 +166,7 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     sa.sll_family = AF_PACKET;
     sa.sll_protocol = htons(type);
 
     sa.sll_family = AF_PACKET;
     sa.sll_protocol = htons(type);
 
-    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
        error("Could not get interface index for %s: %m", ifname);
        close(fd);
     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
        error("Could not get interface index for %s: %m", ifname);
        close(fd);
index c89be94250bc660203beb0a163776fddbb5d074b..48fcea832917561bccb9c7fa1deae2d14eb43fe4 100644 (file)
@@ -153,7 +153,7 @@ PPPOEConnectDevice(void)
        error("Can't get MTU for %s: %m", conn->ifName);
        goto errout;
     }
        error("Can't get MTU for %s: %m", conn->ifName);
        goto errout;
     }
-    strncpy(ifr.ifr_name, conn->ifName, sizeof(ifr.ifr_name));
+    strlcpy(ifr.ifr_name, conn->ifName, sizeof(ifr.ifr_name));
     if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
        error("Can't get MTU for %s: %m", conn->ifName);
        close(s);
     if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
        error("Can't get MTU for %s: %m", conn->ifName);
        close(s);
@@ -327,7 +327,7 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
 
     /* Try getting interface index */
     if (r) {
 
     /* Try getting interface index */
     if (r) {
-       strncpy(ifr.ifr_name, cmd, sizeof(ifr.ifr_name));
+       strlcpy(ifr.ifr_name, cmd, sizeof(ifr.ifr_name));
        if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
            r = 0;
        } else {
        if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
            r = 0;
        } else {
@@ -346,7 +346,7 @@ PPPoEDevnameHook(char *cmd, char **argv, int doit)
     /* Close socket */
     close(fd);
     if (r && doit) {
     /* Close socket */
     close(fd);
     if (r && doit) {
-       strncpy(devnam, cmd, sizeof(devnam));
+       strlcpy(devnam, cmd, sizeof(devnam));
        if (the_channel != &pppoe_channel) {
 
            the_channel = &pppoe_channel;
        if (the_channel != &pppoe_channel) {
 
            the_channel = &pppoe_channel;
index bce71fce04f459b02053cba4c4d95b10a0206f4b..5afb037a1c74c74448851f6c75a1218810a912db 100644 (file)
@@ -181,7 +181,8 @@ openInterface(char const *ifname, UINT16_t type, unsigned char *hwaddr)
     sa.sll_family = AF_PACKET;
     sa.sll_protocol = htons(type);
 
     sa.sll_family = AF_PACKET;
     sa.sll_protocol = htons(type);
 
-    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+    strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+    ifr.ifr_name[IFNAMSIZ - 1] = 0;
     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
        fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
     }
     if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
        fatalSys("ioctl(SIOCFIGINDEX): Could not get interface index");
     }
index 813dcf368cf3369ff48a94db10b5e5b028716175..8c4b8f783a83b692218b11c0c156570a22fb5c1f 100644 (file)
@@ -22,6 +22,8 @@
 #include <stdio.h>             /* For FILE */
 #include <sys/types.h>         /* For pid_t */
 
 #include <stdio.h>             /* For FILE */
 #include <sys/types.h>         /* For pid_t */
 
+#include "pppd/pppd.h"         /* For error */
+
 /* How do we access raw Ethernet devices? */
 #undef USE_LINUX_PACKET
 #undef USE_BPF
 /* How do we access raw Ethernet devices? */
 #undef USE_LINUX_PACKET
 #undef USE_BPF
index bb05acd87dce10a5d2a4adee6feaac68da576fd0..4638f46530469fa29812c5b45c56c06263d27745 100644 (file)
@@ -432,6 +432,7 @@ unsigned int run_ntlm_auth(const char *username,
 
         /* parent */
         if (close(child_out[0]) == -1) {
 
         /* parent */
         if (close(child_out[0]) == -1) {
+                close(child_in[1]);
                 notice("error closing pipe?!? for child OUT[0]");
                 return NOT_AUTHENTICATED;
         }
                 notice("error closing pipe?!? for child OUT[0]");
                 return NOT_AUTHENTICATED;
         }
index 46e1ed419f4b494fb3d6f4781fdc0120ca808fab..761aafc88f92530b27264d4bfa87215b66ff194c 100644 (file)
@@ -2167,7 +2167,6 @@ int ppp_available(void)
                }
            }
 
                }
            }
 
-           close (s);
            if (!ok) {
                slprintf(route_buffer, sizeof(route_buffer),
                         "Sorry - PPP driver version %d.%d.%d is out of date\n",
            if (!ok) {
                slprintf(route_buffer, sizeof(route_buffer),
                         "Sorry - PPP driver version %d.%d.%d is out of date\n",
@@ -2177,6 +2176,7 @@ int ppp_available(void)
            }
        }
     }
            }
        }
     }
+    close(s);
     return ok;
 }
 
     return ok;
 }
 
@@ -2653,7 +2653,10 @@ get_pty(master_fdp, slave_fdp, slave_name, uid)
                warn("Couldn't unlock pty slave %s: %m", pty_name);
 #endif
            if ((sfd = open(pty_name, O_RDWR | O_NOCTTY)) < 0)
                warn("Couldn't unlock pty slave %s: %m", pty_name);
 #endif
            if ((sfd = open(pty_name, O_RDWR | O_NOCTTY)) < 0)
+           {
                warn("Couldn't open pty slave %s: %m", pty_name);
                warn("Couldn't open pty slave %s: %m", pty_name);
+               close(mfd);
+           }
        }
     }
 #endif /* TIOCGPTN */
        }
     }
 #endif /* TIOCGPTN */
index 46cb9c24942b5e6869fef31f463b514daefb99ba..843f7eaa6247e37b64bfe049b67df2f04edf839d 100644 (file)
@@ -149,7 +149,8 @@ get_ppp_stats(curp)
 #define ifr_name ifr__name
 #endif
 
 #define ifr_name ifr__name
 #endif
 
-    strncpy(req.ifr_name, interface, sizeof(req.ifr_name));
+    strncpy(req.ifr_name, interface, IFNAMSIZ);
+    req.ifr_name[IFNAMSIZ - 1] = 0;
     if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
        fprintf(stderr, "%s: ", progname);
        if (errno == ENOTTY)
     if (ioctl(s, SIOCGPPPSTATS, &req) < 0) {
        fprintf(stderr, "%s: ", progname);
        if (errno == ENOTTY)
@@ -175,7 +176,8 @@ get_ppp_cstats(csp)
 #define ifr_name ifr__name
 #endif
 
 #define ifr_name ifr__name
 #endif
 
-    strncpy(creq.ifr_name, interface, sizeof(creq.ifr_name));
+    strncpy(creq.ifr_name, interface, IFNAMSIZ);
+    creq.ifr_name[IFNAMSIZ - 1] = 0;
     if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) {
        fprintf(stderr, "%s: ", progname);
        if (errno == ENOTTY) {
     if (ioctl(s, SIOCGPPPCSTATS, &creq) < 0) {
        fprintf(stderr, "%s: ", progname);
        if (errno == ENOTTY) {
@@ -521,7 +523,8 @@ main(argc, argv)
 #undef  ifr_name
 #define ifr_name ifr_ifrn.ifrn_name
 #endif
 #undef  ifr_name
 #define ifr_name ifr_ifrn.ifrn_name
 #endif
-       strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
+       strncpy(ifr.ifr_name, interface, IFNAMSIZ);
+       ifr.ifr_name[IFNAMSIZ - 1] = 0;
        if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
            fprintf(stderr, "%s: nonexistent interface '%s' specified\n",
                    progname, interface);
        if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
            fprintf(stderr, "%s: nonexistent interface '%s' specified\n",
                    progname, interface);