diff options
| author | Jason Wessel <jason.wessel@windriver.com> | 2018-06-15 08:19:23 -0700 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2018-06-19 12:29:33 -0400 |
| commit | 646259f4d50bdfc0bd3d6ebd9c20bd8bd7251310 (patch) | |
| tree | 04b0f2270000b954d77068e56b4086db96a30f17 | |
| parent | 8af86bc72dc7313d8a81e0e8897efbd044575b15 (diff) | |
| download | meta-virtualization-646259f4d50bdfc0bd3d6ebd9c20bd8bd7251310.tar.gz | |
hyperstart: Fix compiler errors from gcc 8.1.0 uprev
The patch to hypterstart was also submitted to the upstream project.
It fixes these errors/warnings:
container.c: In function 'hyper_setup_container_rootfs':
container.c:630:24: error: '/' directive writing 1 byte into a region of size between 0 and 511 [-Werror=format-overflow=]
sprintf(rootfs, "%s/%s/", root, container->rootfs);
^
container.c:630:2: note: 'sprintf' output 3 or more bytes (assuming 514) into a destination of size 512
sprintf(rootfs, "%s/%s/", root, container->rootfs);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
container.c:262:18: error: '%s' directive writing up to 511 bytes into a region of size 510 [-Werror=format-overflow=]
sprintf(dst, "./%s", src);
^~ ~~~
container.c:262:2: note: 'sprintf' output between 3 and 514 bytes into a destination of size 512
sprintf(dst, "./%s", src);
^~~~~~~~~~~~~~~~~~~~~~~~~
container.c:218:24: error: '/_data' directive writing 6 bytes into a region of size between 1 and 512 [-Werror=format-overflow=]
sprintf(volume, "%s/_data", path);
^~~~~~
container.c:218:5: note: 'sprintf' output between 7 and 518 bytes into a destination of size 512
sprintf(volume, "%s/_data", path);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
container.c:149:24: error: '/_data' directive writing 6 bytes into a region of size between 0 and 511 [-Werror=format-overflow=]
sprintf(volume, "/%s/_data", path);
^~~~~~
container.c:149:4: note: 'sprintf' output between 8 and 519 bytes into a destination of size 512
sprintf(volume, "/%s/_data", path);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
container.c:131:24: error: '/' directive writing 1 byte into a region of size between 0 and 511 [-Werror=format-overflow=]
sprintf(volume, "/%s/", path);
^
container.c:131:4: note: 'sprintf' output between 3 and 514 bytes into a destination of size 512
sprintf(volume, "/%s/", path);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
container.c:176:24: error: '/_data/' directive writing 7 bytes into a region of size between 0 and 511 [-Werror=format-overflow=]
sprintf(volume, "/%s/_data/%s", path, filevolume);
^~~~~~~
container.c:176:4: note: 'sprintf' output 9 or more bytes (assuming 520) into a destination of size 512
sprintf(volume, "/%s/_data/%s", path, filevolume);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
| -rw-r--r-- | recipes-extended/hyperstart/hyperstart/0001-container.c-Fix-compiler-errors-that-gcc-8.1.0-repor.patch | 230 | ||||
| -rw-r--r-- | recipes-extended/hyperstart/hyperstart_git.bb | 1 |
2 files changed, 231 insertions, 0 deletions
diff --git a/recipes-extended/hyperstart/hyperstart/0001-container.c-Fix-compiler-errors-that-gcc-8.1.0-repor.patch b/recipes-extended/hyperstart/hyperstart/0001-container.c-Fix-compiler-errors-that-gcc-8.1.0-repor.patch new file mode 100644 index 00000000..4a01de5b --- /dev/null +++ b/recipes-extended/hyperstart/hyperstart/0001-container.c-Fix-compiler-errors-that-gcc-8.1.0-repor.patch | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | From 11f5089300c1c368d896c95890827dc85a67f132 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Jason Wessel <jason.wessel@windriver.com> | ||
| 3 | Date: Fri, 15 Jun 2018 08:04:35 -0700 | ||
| 4 | Subject: [PATCH] container.c: Fix compiler errors that gcc 8.1.0 reports | ||
| 5 | |||
| 6 | gcc 8.1.0 reports the following compiler errors/warnings. They can be | ||
| 7 | fixed by using snprintf and checking the result for truncation. This | ||
| 8 | patch also uses a named constant instead of inserting the value 512 in | ||
| 9 | many locations. | ||
| 10 | |||
| 11 | container.c: In function 'hyper_setup_container_rootfs': | ||
| 12 | container.c:630:24: error: '/' directive writing 1 byte into a region of size between 0 and 511 [-Werror=format-overflow=] | ||
| 13 | sprintf(rootfs, "%s/%s/", root, container->rootfs); | ||
| 14 | ^ | ||
| 15 | container.c:630:2: note: 'sprintf' output 3 or more bytes (assuming 514) into a destination of size 512 | ||
| 16 | sprintf(rootfs, "%s/%s/", root, container->rootfs); | ||
| 17 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 18 | container.c:262:18: error: '%s' directive writing up to 511 bytes into a region of size 510 [-Werror=format-overflow=] | ||
| 19 | sprintf(dst, "./%s", src); | ||
| 20 | ^~ ~~~ | ||
| 21 | container.c:262:2: note: 'sprintf' output between 3 and 514 bytes into a destination of size 512 | ||
| 22 | sprintf(dst, "./%s", src); | ||
| 23 | ^~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 24 | container.c:218:24: error: '/_data' directive writing 6 bytes into a region of size between 1 and 512 [-Werror=format-overflow=] | ||
| 25 | sprintf(volume, "%s/_data", path); | ||
| 26 | ^~~~~~ | ||
| 27 | container.c:218:5: note: 'sprintf' output between 7 and 518 bytes into a destination of size 512 | ||
| 28 | sprintf(volume, "%s/_data", path); | ||
| 29 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 30 | container.c:149:24: error: '/_data' directive writing 6 bytes into a region of size between 0 and 511 [-Werror=format-overflow=] | ||
| 31 | sprintf(volume, "/%s/_data", path); | ||
| 32 | ^~~~~~ | ||
| 33 | container.c:149:4: note: 'sprintf' output between 8 and 519 bytes into a destination of size 512 | ||
| 34 | sprintf(volume, "/%s/_data", path); | ||
| 35 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 36 | container.c:131:24: error: '/' directive writing 1 byte into a region of size between 0 and 511 [-Werror=format-overflow=] | ||
| 37 | sprintf(volume, "/%s/", path); | ||
| 38 | ^ | ||
| 39 | container.c:131:4: note: 'sprintf' output between 3 and 514 bytes into a destination of size 512 | ||
| 40 | sprintf(volume, "/%s/", path); | ||
| 41 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 42 | container.c:176:24: error: '/_data/' directive writing 7 bytes into a region of size between 0 and 511 [-Werror=format-overflow=] | ||
| 43 | sprintf(volume, "/%s/_data/%s", path, filevolume); | ||
| 44 | ^~~~~~~ | ||
| 45 | container.c:176:4: note: 'sprintf' output 9 or more bytes (assuming 520) into a destination of size 512 | ||
| 46 | sprintf(volume, "/%s/_data/%s", path, filevolume); | ||
| 47 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| 48 | |||
| 49 | Signed-off-by: Jason Wessel <jason.wessel@windriver.com> | ||
| 50 | --- | ||
| 51 | src/container.c | 47 ++++++++++++++++++++++++++++------------------- | ||
| 52 | 1 file changed, 28 insertions(+), 19 deletions(-) | ||
| 53 | |||
| 54 | diff --git a/src/container.c b/src/container.c | ||
| 55 | index 0938d82..b1c52d4 100644 | ||
| 56 | --- a/src/container.c | ||
| 57 | +++ b/src/container.c | ||
| 58 | @@ -22,6 +22,8 @@ | ||
| 59 | #include "syscall.h" | ||
| 60 | #include "netlink.h" | ||
| 61 | |||
| 62 | +#define MAX_PBUF 512 | ||
| 63 | + | ||
| 64 | static int container_populate_volume(char *src, char *dest) | ||
| 65 | { | ||
| 66 | struct stat st; | ||
| 67 | @@ -99,12 +101,12 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 68 | struct hyper_container *container) | ||
| 69 | { | ||
| 70 | int i; | ||
| 71 | - char dev[512], path[512]; | ||
| 72 | + char dev[MAX_PBUF], path[MAX_PBUF]; | ||
| 73 | struct volume *vol; | ||
| 74 | |||
| 75 | for (i = 0; i < container->vols_num; i++) { | ||
| 76 | - char volume[512]; | ||
| 77 | - char mountpoint[512]; | ||
| 78 | + char volume[MAX_PBUF]; | ||
| 79 | + char mountpoint[MAX_PBUF]; | ||
| 80 | char *options = NULL; | ||
| 81 | const char *filevolume = NULL; | ||
| 82 | vol = &container->vols[i]; | ||
| 83 | @@ -128,7 +130,8 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 84 | if (hyper_mount_nfs(vol->device, path) < 0) | ||
| 85 | return -1; | ||
| 86 | /* nfs export has implicitly included _data part of the volume */ | ||
| 87 | - sprintf(volume, "/%s/", path); | ||
| 88 | + if (snprintf(volume, MAX_PBUF, "/%s/", path) >= MAX_PBUF) | ||
| 89 | + return -1; | ||
| 90 | } else { | ||
| 91 | fprintf(stdout, "mount %s to %s, tmp path %s\n", | ||
| 92 | dev, vol->mountpoint, path); | ||
| 93 | @@ -137,7 +140,7 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 94 | options = "nouuid"; | ||
| 95 | |||
| 96 | if (access(dev, R_OK) < 0) { | ||
| 97 | - char device[512]; | ||
| 98 | + char device[MAX_PBUF]; | ||
| 99 | sprintf(device, "/block/%s", vol->device); | ||
| 100 | hyper_netlink_wait_dev(pod->ueventfd, device); | ||
| 101 | } | ||
| 102 | @@ -146,7 +149,8 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 103 | perror("mount volume device failed"); | ||
| 104 | return -1; | ||
| 105 | } | ||
| 106 | - sprintf(volume, "/%s/_data", path); | ||
| 107 | + if (snprintf(volume, MAX_PBUF, "/%s/_data", path) >= MAX_PBUF) | ||
| 108 | + return -1; | ||
| 109 | } | ||
| 110 | |||
| 111 | if (container_check_file_volume(volume, &filevolume) < 0) | ||
| 112 | @@ -173,7 +177,8 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 113 | perror("create volume file failed"); | ||
| 114 | return -1; | ||
| 115 | } | ||
| 116 | - sprintf(volume, "/%s/_data/%s", path, filevolume); | ||
| 117 | + if (snprintf(volume, MAX_PBUF, "/%s/_data/%s", path, filevolume) >= MAX_PBUF) | ||
| 118 | + return -1; | ||
| 119 | /* 0777 so that any user can read/write the new file volume */ | ||
| 120 | if (chmod(volume, 0777) < 0) { | ||
| 121 | fprintf(stderr, "fail to chmod directory %s\n", volume); | ||
| 122 | @@ -197,9 +202,9 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 123 | |||
| 124 | for (i = 0; i < container->maps_num; i++) { | ||
| 125 | struct stat st; | ||
| 126 | - char *src, path[512], volume[512]; | ||
| 127 | + char *src, path[MAX_PBUF], volume[MAX_PBUF]; | ||
| 128 | struct fsmap *map = &container->maps[i]; | ||
| 129 | - char mountpoint[512]; | ||
| 130 | + char mountpoint[MAX_PBUF]; | ||
| 131 | |||
| 132 | sprintf(path, "%s/%s", SHARED_DIR, map->source); | ||
| 133 | sprintf(mountpoint, "./%s", map->path); | ||
| 134 | @@ -215,7 +220,8 @@ static int container_setup_volume(struct hyper_pod *pod, | ||
| 135 | } | ||
| 136 | if (map->docker) { | ||
| 137 | /* converted from volume */ | ||
| 138 | - sprintf(volume, "%s/_data", path); | ||
| 139 | + if (snprintf(volume, MAX_PBUF, "%s/_data", path) >= MAX_PBUF) | ||
| 140 | + return -1; | ||
| 141 | src = volume; | ||
| 142 | if (container->initialize && | ||
| 143 | (container_populate_volume(mountpoint, volume) < 0)) { | ||
| 144 | @@ -251,7 +257,7 @@ static int container_setup_modules(struct hyper_container *container) | ||
| 145 | { | ||
| 146 | struct stat st; | ||
| 147 | struct utsname uts; | ||
| 148 | - char src[512], dst[512]; | ||
| 149 | + char src[MAX_PBUF], dst[MAX_PBUF]; | ||
| 150 | |||
| 151 | if (uname(&uts) < 0) { | ||
| 152 | perror("fail to call uname"); | ||
| 153 | @@ -259,7 +265,8 @@ static int container_setup_modules(struct hyper_container *container) | ||
| 154 | } | ||
| 155 | |||
| 156 | sprintf(src, "/lib/modules/%s", uts.release); | ||
| 157 | - sprintf(dst, "./%s", src); | ||
| 158 | + if (snprintf(dst, MAX_PBUF, "./%s", src) >= MAX_PBUF) | ||
| 159 | + return -1; | ||
| 160 | |||
| 161 | if (stat(dst, &st) == 0) { | ||
| 162 | struct dirent **list; | ||
| 163 | @@ -291,7 +298,7 @@ static int container_setup_modules(struct hyper_container *container) | ||
| 164 | |||
| 165 | static int container_setup_mount(struct hyper_container *container) | ||
| 166 | { | ||
| 167 | - char src[512]; | ||
| 168 | + char src[MAX_PBUF]; | ||
| 169 | |||
| 170 | // current dir is container rootfs, the operations on "./PATH" are the operations on container's "/PATH" | ||
| 171 | if (!container->readonly) { | ||
| 172 | @@ -546,7 +553,7 @@ static int hyper_setup_container_rootfs(void *data) | ||
| 173 | { | ||
| 174 | struct hyper_container_arg *arg = data; | ||
| 175 | struct hyper_container *container = arg->c; | ||
| 176 | - char root[512], rootfs[512]; | ||
| 177 | + char root[MAX_PBUF], rootfs[MAX_PBUF]; | ||
| 178 | int setup_dns; | ||
| 179 | |||
| 180 | /* wait for ns-opened ready message */ | ||
| 181 | @@ -609,7 +616,7 @@ static int hyper_setup_container_rootfs(void *data) | ||
| 182 | goto fail; | ||
| 183 | } | ||
| 184 | } else { | ||
| 185 | - char path[512]; | ||
| 186 | + char path[MAX_PBUF]; | ||
| 187 | |||
| 188 | sprintf(path, "%s/%s/", SHARED_DIR, container->image); | ||
| 189 | fprintf(stdout, "src directory %s\n", path); | ||
| 190 | @@ -627,7 +634,9 @@ static int hyper_setup_container_rootfs(void *data) | ||
| 191 | fprintf(stdout, "root directory for container is %s/%s, init task %s\n", | ||
| 192 | root, container->rootfs, container->exec.argv[0]); | ||
| 193 | |||
| 194 | - sprintf(rootfs, "%s/%s/", root, container->rootfs); | ||
| 195 | + if (snprintf(rootfs, MAX_PBUF, "%s/%s/", root, container->rootfs) >= MAX_PBUF) | ||
| 196 | + goto fail; | ||
| 197 | + | ||
| 198 | if (mount(rootfs, rootfs, NULL, MS_BIND|MS_REC, NULL) < 0) { | ||
| 199 | perror("failed to bind rootfs"); | ||
| 200 | goto fail; | ||
| 201 | @@ -710,7 +719,7 @@ fail: | ||
| 202 | |||
| 203 | static int hyper_setup_pty(struct hyper_container *c) | ||
| 204 | { | ||
| 205 | - char root[512]; | ||
| 206 | + char root[MAX_PBUF]; | ||
| 207 | |||
| 208 | sprintf(root, "/tmp/hyper/%s/devpts/", c->id); | ||
| 209 | |||
| 210 | @@ -730,7 +739,7 @@ static int hyper_setup_pty(struct hyper_container *c) | ||
| 211 | |||
| 212 | static void hyper_cleanup_pty(struct hyper_container *c) | ||
| 213 | { | ||
| 214 | - char path[512]; | ||
| 215 | + char path[MAX_PBUF]; | ||
| 216 | |||
| 217 | sprintf(path, "/tmp/hyper/%s/devpts/", c->id); | ||
| 218 | if (umount(path) < 0) | ||
| 219 | @@ -739,7 +748,7 @@ static void hyper_cleanup_pty(struct hyper_container *c) | ||
| 220 | |||
| 221 | int container_prepare_rootfs_dev(struct hyper_container *container, struct hyper_pod *pod) | ||
| 222 | { | ||
| 223 | - char dev[512]; | ||
| 224 | + char dev[MAX_PBUF]; | ||
| 225 | |||
| 226 | if (container->fstype == NULL) | ||
| 227 | return 0; | ||
| 228 | -- | ||
| 229 | 2.17.1 | ||
| 230 | |||
diff --git a/recipes-extended/hyperstart/hyperstart_git.bb b/recipes-extended/hyperstart/hyperstart_git.bb index 02974772..99c21952 100644 --- a/recipes-extended/hyperstart/hyperstart_git.bb +++ b/recipes-extended/hyperstart/hyperstart_git.bb | |||
| @@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=fa818a259cbed7ce8bc2a22d35a464fc" | |||
| 7 | inherit autotools-brokensep | 7 | inherit autotools-brokensep |
| 8 | 8 | ||
| 9 | SRC_URI = "git://github.com/hyperhq/hyperstart.git" | 9 | SRC_URI = "git://github.com/hyperhq/hyperstart.git" |
| 10 | SRC_URI += "file://0001-container.c-Fix-compiler-errors-that-gcc-8.1.0-repor.patch" | ||
| 10 | 11 | ||
| 11 | SRCREV = "ad48a3230836f59ada163659cde151a37522068b" | 12 | SRCREV = "ad48a3230836f59ada163659cde151a37522068b" |
| 12 | PV = "v0.2+git${SRCREV}" | 13 | PV = "v0.2+git${SRCREV}" |
