Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 1 | From 58b6d9a2efe101e5b80fd708e6f84c7ca779ce93 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Thu, 31 May 2018 20:27:43 -0700 |
| 4 | Subject: [PATCH] Fix potential string truncation in strncpy() |
| 5 | |
| 6 | GCC 8 complains about the string truncation during copy |
| 7 | |
| 8 | error: 'strncpy' specified bound 16 equals destination size |
| 9 | |
| 10 | Upstream-Status: Inappropriate [depricated component] |
| 11 | |
| 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 13 | --- |
| 14 | tests/listen-packet.c | 3 ++- |
| 15 | tests/listen.c | 3 ++- |
| 16 | tests/test2.c | 4 ++-- |
| 17 | tests/test3.c | 3 ++- |
| 18 | tests/test4.c | 3 ++- |
| 19 | tests/test5.c | 3 ++- |
| 20 | tests/test6.c | 3 ++- |
| 21 | tests/test7.c | 3 ++- |
| 22 | 8 files changed, 16 insertions(+), 9 deletions(-) |
| 23 | |
| 24 | diff --git a/tests/listen-packet.c b/tests/listen-packet.c |
| 25 | index e40af81..eae0c71 100644 |
| 26 | --- a/tests/listen-packet.c |
| 27 | +++ b/tests/listen-packet.c |
| 28 | @@ -50,7 +50,8 @@ int main(int argc, char **argv) { |
| 29 | return 1; |
| 30 | } |
| 31 | |
| 32 | - strncpy(req.ifr_name, iface, IF_NAMESIZE); |
| 33 | + strncpy(req.ifr_name, iface, IF_NAMESIZE - 1); |
| 34 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 35 | ret = ioctl(sd, SIOCGIFINDEX, &req); |
| 36 | if (ret < 0) |
| 37 | perror("ioctl: SIOCGIFINDEX"); |
| 38 | diff --git a/tests/listen.c b/tests/listen.c |
| 39 | index 75c320b..5ce1ed9 100644 |
| 40 | --- a/tests/listen.c |
| 41 | +++ b/tests/listen.c |
| 42 | @@ -47,7 +47,8 @@ int main(int argc, char **argv) { |
| 43 | return 1; |
| 44 | } |
| 45 | |
| 46 | - strncpy(req.ifr_name, iface, IFNAMSIZ); |
| 47 | + strncpy(req.ifr_name, iface, IFNAMSIZ - 1); |
| 48 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 49 | ret = ioctl(sd, SIOCGIFHWADDR, &req); |
| 50 | if (ret < 0) |
| 51 | perror("ioctl: SIOCGIFHWADDR"); |
| 52 | diff --git a/tests/test2.c b/tests/test2.c |
| 53 | index 58eb74b..5d02838 100644 |
| 54 | --- a/tests/test2.c |
| 55 | +++ b/tests/test2.c |
| 56 | @@ -45,8 +45,8 @@ int main(int argc, char **argv) { |
| 57 | perror("socket"); |
| 58 | return 1; |
| 59 | } |
| 60 | - |
| 61 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 62 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 63 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 64 | ret = ioctl(sd, SIOCGIFHWADDR, &req); |
| 65 | if (ret < 0) |
| 66 | perror("ioctl: SIOCGIFHWADDR"); |
| 67 | diff --git a/tests/test3.c b/tests/test3.c |
| 68 | index fb36627..2f50a5a 100644 |
| 69 | --- a/tests/test3.c |
| 70 | +++ b/tests/test3.c |
| 71 | @@ -46,7 +46,8 @@ int main(int argc, char **argv) { |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 76 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 77 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 78 | ret = ioctl(sd, SIOCGIFHWADDR, &req); |
| 79 | if (ret < 0) |
| 80 | perror("ioctl: SIOCGIFHWADDR"); |
| 81 | diff --git a/tests/test4.c b/tests/test4.c |
| 82 | index 33c274c..8737149 100644 |
| 83 | --- a/tests/test4.c |
| 84 | +++ b/tests/test4.c |
| 85 | @@ -46,7 +46,8 @@ int main(int argc, char **argv) { |
| 86 | return 1; |
| 87 | } |
| 88 | |
| 89 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 90 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 91 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 92 | ret = ioctl(sd, SIOCGIFHWADDR, &req); |
| 93 | if (ret < 0) |
| 94 | perror("ioctl: SIOCGIFHWADDR"); |
| 95 | diff --git a/tests/test5.c b/tests/test5.c |
| 96 | index 4439dfa..28db562 100644 |
| 97 | --- a/tests/test5.c |
| 98 | +++ b/tests/test5.c |
| 99 | @@ -45,7 +45,8 @@ int main(int argc, char **argv) { |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 104 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 105 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 106 | ret = ioctl(sd, SIOCGIFADDR, &req); |
| 107 | if (ret < 0) { |
| 108 | perror("ioctl: SIOCGIFADDR"); |
| 109 | diff --git a/tests/test6.c b/tests/test6.c |
| 110 | index e375bfb..ce7de59 100644 |
| 111 | --- a/tests/test6.c |
| 112 | +++ b/tests/test6.c |
| 113 | @@ -45,7 +45,8 @@ int main(int argc, char **argv) { |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 118 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 119 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 120 | ret = ioctl(sd, SIOCGIFADDR, &req); |
| 121 | if (ret < 0) { |
| 122 | perror("ioctl: SIOCGIFADDR"); |
| 123 | diff --git a/tests/test7.c b/tests/test7.c |
| 124 | index e9a5a55..37da22d 100644 |
| 125 | --- a/tests/test7.c |
| 126 | +++ b/tests/test7.c |
| 127 | @@ -58,7 +58,8 @@ int main(int argc, char **argv) { |
| 128 | if (ret) |
| 129 | perror("setsockopt"); |
| 130 | |
| 131 | - strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE); |
| 132 | + strncpy(req.ifr_name, argv[1] ?: "wpan0", IF_NAMESIZE - 1); |
| 133 | + req.ifr_name[IF_NAMESIZE - 1] = '\0'; |
| 134 | ret = ioctl(sd, SIOCGIFHWADDR, &req); |
| 135 | if (ret < 0) |
| 136 | perror("ioctl: SIOCGIFHWADDR"); |
| 137 | -- |
| 138 | 2.17.1 |
| 139 | |