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 warnings in unit test BSP #204

Merged
merged 2 commits into from
Nov 18, 2022
Merged

Fix warnings in unit test BSP #204

merged 2 commits into from
Nov 18, 2022

Conversation

pcolberg
Copy link
Contributor

@pcolberg pcolberg commented Nov 17, 2022

commit caa98ebd373d48e5ec063d604347248d9df82ba6
Author: Peter Colberg <peter.colberg@intel.com>
Date:   Thu Nov 17 18:40:39 2022

    fake_bsp: fix out-of-bounds read of OFFSET_CONFIGURATION_ROM
    
    The check failed to account for the trailing null byte, and
    memcpy() read beyond the end of the copied string literal.
    
    Signed-off-by: Peter Colberg <peter.colberg@intel.com>
commit 7f737cdc93826a36087417004b99c34e7296e9f8
Author: Peter Colberg <peter.colberg@intel.com>
Date:   Thu Nov 17 18:04:25 2022

    fake_bsp: fix stringop-overread warnings with string literals
    
    GCC 11 correctly points out that there is no point in limiting strnlen()
    to a size that is greater than the length of the string literal argument.
    
    test/fake_bsp/fakegoodbsp.cpp:47:26: warning: 'size_t strnlen(const char*, size_t)' specified bound 1204 exceeds source size 16 [-Wstringop-overread]
       47 |     size_t Xlen = strnlen(X, MAX_NAME_SIZE) + 1;                               \
          |                   ~~~~~~~^~~~~~~~~~~~~~~~~~
    
    strnlen() is commonly used with an input buffer that is possibly not
    null-terminated, i.e., contains a truncated string. strnlen() is also
    useful to set an upper bound on the length to consume, e.g., to avoid
    a denial of service. Neither of these use cases apply here.
    
    MAX_NAME_SIZE was previously introduced in acl.h to address Klocwork
    issues relating to missing null termination of strings. The chosen
    1204 is a typo of 1024, but even then, it should be 1023 such that a
    buffer with the trailing null byte occupies 1023 + 1 = 1024 bytes.
    
    Signed-off-by: Peter Colberg <peter.colberg@intel.com>

GCC 11 correctly points out that there is no point in limiting strnlen()
to a size that is greater than the length of the string literal argument.

test/fake_bsp/fakegoodbsp.cpp:47:26: warning: 'size_t strnlen(const char*, size_t)' specified bound 1204 exceeds source size 16 [-Wstringop-overread]
   47 |     size_t Xlen = strnlen(X, MAX_NAME_SIZE) + 1;                               \
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~

strnlen() is commonly used with an input buffer that is possibly not
null-terminated, i.e., contains a truncated string. strnlen() is also
useful to set an upper bound on the length to consume, e.g., to avoid
a denial of service. Neither of these use cases apply here.

MAX_NAME_SIZE was previously introduced in acl.h to address Klocwork
issues relating to missing null termination of strings. The chosen
1204 is a typo of 1024, but even then, it should be 1023 such that a
buffer with the trailing null byte occupies 1023 + 1 = 1024 bytes.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
The check failed to account for the trailing null byte, and
memcpy() read beyond the end of the copied string literal.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
@pcolberg pcolberg added the bug Something isn't working label Nov 17, 2022
@pcolberg pcolberg added this to the 2023.1 milestone Nov 17, 2022
@pcolberg pcolberg self-assigned this Nov 17, 2022
@pcolberg pcolberg linked an issue Nov 17, 2022 that may be closed by this pull request
2 tasks
@pcolberg pcolberg marked this pull request as ready for review November 18, 2022 00:09
@pcolberg pcolberg requested a review from zibaiwan November 18, 2022 00:41
Copy link
Contributor

@zibaiwan zibaiwan left a comment

Choose a reason for hiding this comment

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

Thanks @pcolberg !

@pcolberg pcolberg merged commit aa2bbfe into intel:main Nov 18, 2022
@pcolberg pcolberg deleted the fake_bsp branch November 18, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix warnings in unit test BSP
2 participants