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

fix gcc 10.1 stringop-truncation error #10346

Merged
merged 1 commit into from
May 19, 2020
Merged

Conversation

gamanakis
Copy link
Contributor

@gamanakis gamanakis commented May 18, 2020

Compiling with gcc 10.1 fails with:

zpool_main.c: In function ‘zpool_do_events_short’:
zpool_main.c:8901:9: error: ‘strncpy’ output may be truncated copying 6 bytes from a string of length 21 [-Werror=stringop-truncation]
 8901 |  (void) strncpy(str, ctime_str+4,  6);  /* 'Jun 30' */
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zpool_main.c:8902:9: error: ‘strncpy’ output may be truncated copying 4 bytes from a string of length 5 [-Werror=stringop-truncation]
 8902 |  (void) strncpy(str+7, ctime_str+20, 4);  /* '1993' */
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zpool_main.c:8903:9: error: ‘strncpy’ output may be truncated copying 8 bytes from a string of length 14 [-Werror=stringop-truncation]
 8903 |  (void) strncpy(str+12, ctime_str+11, 8); /* '21:49:08' */
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As we do not expect the destination of these strncpy calls to be NUL terminated, substitute them with memcpy per https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation

Signed-off-by: George Amanakis gamanakis@gmail.com

Motivation and Context

Description

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

  • My code follows the ZFS on Linux code style requirements.
  • I have updated the documentation accordingly.
  • I have read the contributing document.
  • I have added tests to cover my changes.
  • I have run the ZFS Test Suite with this change applied.
  • All commit messages are properly formatted and contain Signed-off-by.

As we do not expect the destination of these strncpy calls to be NUL
terminated, substitute them with memcpy.

Signed-off-by: George Amanakis <gamanakis@gmail.com>
@tonyhutter
Copy link
Contributor

I think you can simplify it further to:

/*
 * Take a date like 'Mon May 18 15:23:11 2020' and trim off the day
 * of the week (first three chars + space).
 */
memcpy(str, ctime_str + 4,  20);

@gamanakis
Copy link
Contributor Author

@tonyhutter I think that would change the format of the date though.
I find it more functional the way it has been: May 18 2020 15:23:11.xxxxx, instead of May 18 15:23:11.xxxxx 2020

@codecov-commenter
Copy link

codecov-commenter commented May 19, 2020

Codecov Report

Merging #10346 into master will increase coverage by 0.24%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10346      +/-   ##
==========================================
+ Coverage   79.24%   79.48%   +0.24%     
==========================================
  Files         390      390              
  Lines      123336   123336              
==========================================
+ Hits        97737    98036     +299     
+ Misses      25599    25300     -299     
Flag Coverage Δ
#kernel 79.94% <ø> (+0.03%) ⬆️
#user 66.02% <100.00%> (+1.85%) ⬆️
Impacted Files Coverage Δ
cmd/zpool/zpool_main.c 80.43% <100.00%> (+0.02%) ⬆️
module/lua/lmem.c 83.33% <0.00%> (-4.17%) ⬇️
module/zfs/dsl_synctask.c 92.40% <0.00%> (-2.54%) ⬇️
module/zfs/zap_micro.c 85.35% <0.00%> (-1.26%) ⬇️
module/os/linux/zfs/zfs_file_os.c 84.15% <0.00%> (-1.00%) ⬇️
module/zfs/dmu_traverse.c 96.34% <0.00%> (-0.67%) ⬇️
module/zfs/vdev_raidz.c 93.13% <0.00%> (-0.66%) ⬇️
module/zfs/vdev_queue.c 94.49% <0.00%> (-0.62%) ⬇️
module/zfs/zil.c 91.25% <0.00%> (-0.57%) ⬇️
module/zfs/bpobj.c 90.61% <0.00%> (-0.54%) ⬇️
... and 58 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b29e31d...d54e8b9. Read the comment docs.

Copy link
Contributor

@tonyhutter tonyhutter left a comment

Choose a reason for hiding this comment

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

@gamanakis ah you're right, I see what you mean. Approved

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels May 19, 2020
@behlendorf behlendorf merged commit 7cd723e into openzfs:master May 19, 2020
as-com pushed a commit to as-com/zfs that referenced this pull request Jun 20, 2020
As we do not expect the destination of these strncpy calls to be NULL
terminated, substitute them with memcpy.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Amanakis <gamanakis@gmail.com>
Closes openzfs#10346
(cherry picked from commit 7cd723e)
as-com pushed a commit to as-com/zfs that referenced this pull request Jun 20, 2020
As we do not expect the destination of these strncpy calls to be NULL
terminated, substitute them with memcpy.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Amanakis <gamanakis@gmail.com>
Closes openzfs#10346
(cherry picked from commit 7cd723e)
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Sep 15, 2020
As we do not expect the destination of these strncpy calls to be NULL
terminated, substitute them with memcpy.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Amanakis <gamanakis@gmail.com>
Closes openzfs#10346
tonyhutter pushed a commit to tonyhutter/zfs that referenced this pull request Sep 15, 2020
As we do not expect the destination of these strncpy calls to be NULL
terminated, substitute them with memcpy.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Amanakis <gamanakis@gmail.com>
Closes openzfs#10346
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
As we do not expect the destination of these strncpy calls to be NULL
terminated, substitute them with memcpy.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: George Amanakis <gamanakis@gmail.com>
Closes openzfs#10346
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants