]> git.ozlabs.org Git - ppp.git/commitdiff
pppd: Eliminate some more compiler warnings
authorPaul Mackerras <paulus@ozlabs.org>
Sun, 1 Dec 2019 10:32:37 +0000 (21:32 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Sun, 1 Dec 2019 10:32:37 +0000 (21:32 +1100)
Recent versions of gcc produce warnings on code where strncpy will
produce a result that is not NULL terminated.  This changes the
code to eliminate these warnings.  In two cases this is done by
changing strncpy to strlcpy, which could in principle cause a loss
of the information in the last byte.  This is not a concern in
these cases because:

- In sys-linux.c, the interface names in struct ifreq were possibly
  not NULL terminated.  The Linux kernel clears the last byte to make
  them NULL terminated anyway, so there is no loss of information.

- In session.c, the lastlog ll_line and ll_host fields were possibly
  not NULL terminated.  These fields are quite long and it is unlikely
  that the last byte is needed.

In the other cases strlcpy and strlcat are used to give the same
effect as the old code but without warnings.

This also changes %ld to %d in one place to eliminate a format warning.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
pppd/plugins/radius/avpair.c
pppd/plugins/radius/config.c
pppd/plugins/rp-pppoe/plugin.c
pppd/session.c
pppd/sys-linux.c

index b22a0a2423dc3302c593508ffd5dd2565350792d..ebc1895c0a6900d79e8d799e596e1169dcaad8e4 100644 (file)
@@ -737,7 +737,7 @@ int rc_avpair_tostr (VALUE_PAIR *pair, char *name, int ln, char *value, int lv)
                }
                else
                {
                }
                else
                {
-                       sprintf (buffer, "%ld", pair->lvalue);
+                       sprintf (buffer, "%d", pair->lvalue);
                        strncpy(value, buffer, (size_t) lv);
                }
                break;
                        strncpy(value, buffer, (size_t) lv);
                }
                break;
index 6e36d898a27a58bdae7e29f8e616797ff1eb0ab2..c5a4eeb04581333b61763e81905072ad53b2a3ea 100644 (file)
@@ -482,26 +482,14 @@ int rc_find_server (char *server_name, UINT4 *ip_addr, char *secret)
                if ((h = strtok (buffer, " \t\n")) == NULL) /* first hostname */
                        continue;
 
                if ((h = strtok (buffer, " \t\n")) == NULL) /* first hostname */
                        continue;
 
-               memset (hostnm, '\0', AUTH_ID_LEN);
-               len = strlen (h);
-               if (len > AUTH_ID_LEN)
-               {
-                       len = AUTH_ID_LEN;
-               }
-               strncpy (hostnm, h, (size_t) len);
-               hostnm[AUTH_ID_LEN] = '\0';
+               memset (hostnm, '\0', AUTH_ID_LEN + 1);
+               strlcpy (hostnm, h, AUTH_ID_LEN + 1);
 
                if ((s = strtok (NULL, " \t\n")) == NULL) /* and secret field */
                        continue;
 
 
                if ((s = strtok (NULL, " \t\n")) == NULL) /* and secret field */
                        continue;
 
-               memset (secret, '\0', MAX_SECRET_LENGTH);
-               len = strlen (s);
-               if (len > MAX_SECRET_LENGTH)
-               {
-                       len = MAX_SECRET_LENGTH;
-               }
-               strncpy (secret, s, (size_t) len);
-               secret[MAX_SECRET_LENGTH] = '\0';
+               memset (secret, '\0', MAX_SECRET_LENGTH + 1);
+               strlcpy (secret, s, MAX_SECRET_LENGTH + 1);
 
                if (!strchr (hostnm, '/')) /* If single name form */
                {
 
                if (!strchr (hostnm, '/')) /* If single name form */
                {
index 9e838d30d58b81208b9289ff239acfb9937f03fb..44e0c31de9f3f6af6abd629ae78954462eccc2f8 100644 (file)
@@ -302,8 +302,10 @@ PPPOEDisconnectDevice(void)
 static void
 PPPOEDeviceOptions(void)
 {
 static void
 PPPOEDeviceOptions(void)
 {
-    char buf[256];
-    snprintf(buf, 256, _PATH_ETHOPT "%s", devnam);
+    char buf[MAXPATHLEN];
+
+    strlcpy(buf, _PATH_ETHOPT, MAXPATHLEN);
+    strlcat(buf, devnam, MAXPATHLEN);
     if (!options_from_file(buf, 0, 0, 1))
        exit(EXIT_OPTION_ERROR);
 
     if (!options_from_file(buf, 0, 0, 1))
        exit(EXIT_OPTION_ERROR);
 
index 56385dd638742ba9fd7028165104e8565cff0778..473e51e1912f63074eb7c1d058a601f17fc2749e 100644 (file)
@@ -384,8 +384,8 @@ session_start(flags, user, passwd, ttyName, msg)
                 memset((void *)&ll, 0, sizeof(ll));
                (void)time(&tnow);
                 ll.ll_time = tnow;
                 memset((void *)&ll, 0, sizeof(ll));
                (void)time(&tnow);
                 ll.ll_time = tnow;
-                (void)strncpy(ll.ll_line, ttyName, sizeof(ll.ll_line));
-                (void)strncpy(ll.ll_host, ifname, sizeof(ll.ll_host));
+                strlcpy(ll.ll_line, ttyName, sizeof(ll.ll_line));
+                strlcpy(ll.ll_host, ifname, sizeof(ll.ll_host));
                 (void)write(fd, (char *)&ll, sizeof(ll));
                 (void)close(fd);
             }
                 (void)write(fd, (char *)&ll, sizeof(ll));
                 (void)close(fd);
             }
index 89263ed1c5b75231471dc83271f591381cf45cd2..a0531e9d351d094e138600e3b24945c9b27d1f60 100644 (file)
@@ -656,8 +656,8 @@ static int make_ppp_unit()
                char t[MAXIFNAMELEN];
                memset(&ifr, 0, sizeof(struct ifreq));
                slprintf(t, sizeof(t), "%s%d", PPP_DRV_NAME, ifunit);
                char t[MAXIFNAMELEN];
                memset(&ifr, 0, sizeof(struct ifreq));
                slprintf(t, sizeof(t), "%s%d", PPP_DRV_NAME, ifunit);
-               strncpy(ifr.ifr_name, t, IF_NAMESIZE);
-               strncpy(ifr.ifr_newname, req_ifname, IF_NAMESIZE);
+               strlcpy(ifr.ifr_name, t, IF_NAMESIZE);
+               strlcpy(ifr.ifr_newname, req_ifname, IF_NAMESIZE);
                x = ioctl(sock_fd, SIOCSIFNAME, &ifr);
                if (x < 0)
                    error("Couldn't rename interface %s to %s: %m", t, req_ifname);
                x = ioctl(sock_fd, SIOCSIFNAME, &ifr);
                if (x < 0)
                    error("Couldn't rename interface %s to %s: %m", t, req_ifname);