Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jwessel
Copy link

@jwessel jwessel commented Jun 15, 2018

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

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>
@Jimmy-Xu
Copy link

Can one of the admins verify this patch?

@gnawux
Copy link
Member

gnawux commented Jun 15, 2018

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?

@@ -22,6 +22,8 @@
#include "syscall.h"
#include "netlink.h"

#define MAX_PBUF 512
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just use PATH_MAX defined in <limits.h>, as being done in container_check_volume.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants