New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning and build failure in archive_write_set_format_ar #1020

Closed
phcerdan opened this Issue May 21, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@phcerdan
Contributor

phcerdan commented May 21, 2018

  • Version of libarchive (master at 6c739e0 )
  • built from source
  • compiler: gcc 8.1.0
  • system: linux, archlinux.

I am getting the following warnings, these turned into errors when using libarchive (and compiling it) as an external library in other project.

I guess due to libarchive turning these warnings into errors in CMakeLists.txt

[220/666] Building C object libarchive/CMakeFiles/archive.dir/archive_write_set_format_ar.c.o
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c: In function ‘archive_write_ar_header’:
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:183:2: warning: ‘strncpy’ output truncated before terminating nul copying 2 bytes from a string of the same length [-Wstringop-truncation]
  strncpy(&buff[AR_fmag_offset], "`\n", 2);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:192:3: warning: ‘strncpy’ output truncated before terminating nul copying 9 bytes from a string of the same length [-Wstringop-truncation]
   strncpy(buff + AR_name_offset, "__.SYMDEF", 9);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:292:4: warning: ‘strncpy’ output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
    strncpy(buff + AR_name_offset, "#1/", 3);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:288:4: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
    strncpy(&buff[AR_name_offset], filename, strlen(filename));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:287:7: note: length computed here
   if (strlen(filename) <= 16 && strchr(filename, ' ') == NULL) {
       ^~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:251:4: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
    strncpy(se, filename, strlen(filename));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:228:4: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
    strncpy(&buff[AR_name_offset],
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        filename, strlen(filename));
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/libarchive/archive_write_set_format_ar.c:227:7: note: length computed here
   if (strlen(filename) <= 15) {
       ^~~~~~~~~~~~~~~~
[267/666] Building C object libarchive/test/CMakeFiles/libarchive_test.dir/__/__/test_utils/test_main.c.o
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c: In function ‘main’:
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:26: warning: ‘%s’ directive writing up to 255 bytes into a region of size between 250 and 254 [-Wformat-overflow=]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                          ^~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:19: note: directive argument in the range [0, 999]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                   ^~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:3: note: ‘sprintf’ output 7 or more bytes (assuming 266) into a destination of size 256
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~~~~~
[551/666] Building C object cat/test/CMakeFiles/bsdcat_test.dir/__/__/test_utils/test_main.c.o
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c: In function ‘main’:
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:26: warning: ‘%s’ directive writing up to 255 bytes into a region of size between 250 and 254 [-Wformat-overflow=]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                          ^~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:19: note: directive argument in the range [0, 999]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                   ^~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:3: note: ‘sprintf’ output 7 or more bytes (assuming 266) into a destination of size 256
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~~~~~
[588/666] Building C object tar/test/CMakeFiles/bsdtar_test.dir/__/__/test_utils/test_main.c.o
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c: In function ‘main’:
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:26: warning: ‘%s’ directive writing up to 255 bytes into a region of size between 250 and 254 [-Wformat-overflow=]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                          ^~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:19: note: directive argument in the range [0, 999]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                   ^~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:3: note: ‘sprintf’ output 7 or more bytes (assuming 266) into a destination of size 256
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~~~~~
[653/666] Building C object cpio/test/CMakeFiles/bsdcpio_test.dir/test_option_t.c.o
/path/Software/Slicer/libarchive/libarchive/cpio/test/test_option_t.c: In function ‘test_option_t’:
/path/Software/Slicer/libarchive/libarchive/cpio/test/test_option_t.c:95:38: warning: ‘ file’ directive output may be truncated writing 5 bytes into a region of size between 0 and 19 [-Wformat-truncation=]
  snprintf(date, sizeof(date)-1, "%12s file", date2);
                                      ^~~~~
/path/Software/Slicer/libarchive/libarchive/cpio/test/test_option_t.c:95:2: note: ‘snprintf’ output between 18 and 37 bytes into a destination of size 31
  snprintf(date, sizeof(date)-1, "%12s file", date2);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[660/666] Building C object cpio/test/CMakeFiles/bsdcpio_test.dir/__/__/test_utils/test_main.c.o
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c: In function ‘main’:
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:26: warning: ‘%s’ directive writing up to 255 bytes into a region of size between 250 and 254 [-Wformat-overflow=]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                          ^~
       tmpdir_timestamp, i);
       ~~~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:19: note: directive argument in the range [0, 999]
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
                   ^~~~~~~~~~~~~~~
/path/Software/Slicer/libarchive/libarchive/test_utils/test_main.c:3737:3: note: ‘sprintf’ output 7 or more bytes (assuming 266) into a destination of size 256
   sprintf(tmpdir, "%s/%s.%s-%03d", tmp, progname,
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       tmpdir_timestamp, i);

@phcerdan phcerdan changed the title from Warning, so build failure in to Warning and build failure in archive_write_set_format_ar May 21, 2018

@kientzle

This comment has been minimized.

Contributor

kientzle commented Jun 1, 2018

It looks like the strncpy calls here should be simple memcpy instead. Can you send a PR with that change?

The bounds checking in the test harness is less interesting, of course. Can you just avoid building the test programs?

@phcerdan

This comment has been minimized.

Contributor

phcerdan commented Jun 1, 2018

@kientzle Sure, thanks, I'll send a PR this weekend with memcpy. We have an option to build tests of external libraries, just to be in the safe side :)

phcerdan added a commit to phcerdan/libarchive that referenced this issue Jun 3, 2018

@phcerdan

This comment has been minimized.

Contributor

phcerdan commented Jun 5, 2018

@kientzle have a look at PR #1024 for the proposed fix with memcpy. Thanks!

@kientzle

This comment has been minimized.

Contributor

kientzle commented Jun 10, 2018

I've merged #1024. Please re-test.

For the test harness issues, we probably should be using snprintf() instead of sprintf() here. Could you try that as well?

gperciva added a commit to Tarsnap/libarchive that referenced this issue Aug 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment