hyperstart icon indicating copy to clipboard operation
hyperstart copied to clipboard

container.c: Fix compiler errors that gcc 8.1.0 reports

Open jwessel opened this issue 6 years ago • 2 comments

gcc 8.1.0 reports the following compiler errors/warnings. They can be fixed by using snprintf and checking the result for truncation. This patch also uses a named constant instead of inserting the value 512 in many locations.

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 [email protected]

jwessel avatar Jun 15 '18 15:06 jwessel

Can one of the admins verify this patch?

Jimmy-Xu avatar Jun 15 '18 15:06 Jimmy-Xu

I think the case in the warning won't happened, however, the patch is

LGTM

and good to the compiler as well.

What's your opinion, @laijs?

gnawux avatar Jun 15 '18 16:06 gnawux