This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
container.c: Fix compiler errors that gcc 8.1.0 reports #356
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 jason.wessel@windriver.com