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

pkg_editor: unconditionally null-terminate output of strncpy() #215

Merged
merged 1 commit into from
Nov 25, 2022

Conversation

pcolberg
Copy link
Contributor

Resolves Coverity error "Buffer not null terminated (BUFFER_SIZE)".

The previous code was correct but non-idiomatic.

Signed-off-by: Peter Colberg peter.colberg@intel.com

@haoxian2 in case you see this pattern elsewhere.

Resolves Coverity error "Buffer not null terminated (BUFFER_SIZE)".

The previous code was correct but non-idiomatic.

Signed-off-by: Peter Colberg <peter.colberg@intel.com>
@pcolberg pcolberg added this to the 2023.1 milestone Nov 25, 2022
@pcolberg pcolberg self-assigned this Nov 25, 2022
@pcolberg
Copy link
Contributor Author

Resolved Coverity errors:

lib/pkg_editor/src/pkg_editor.c:1580:3:
  Type: Buffer not null terminated (BUFFER_SIZE)

lib/pkg_editor/src/pkg_editor.c:1580:3:
  1. buffer_size_warning: Calling "strncpy" with a maximum size argument of 12288 bytes on destination array "full_nam
e" of size 12288 bytes might leave the destination string unterminated.
lib/pkg_editor/src/pkg_editor.c:1581:3:
  2. path: Condition "full_name[12287 /* 3 * 4096 - 1 */] != 0", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1589:3:
  3. path: Condition "buffer != NULL", taking true branch.
lib/pkg_editor/src/pkg_editor.c:1590:5:
  4. path: Condition "input == NULL", taking true branch.
lib/pkg_editor/src/pkg_editor.c:1593:3:
  5. path: Falling through to end of if statement.
lib/pkg_editor/src/pkg_editor.c:1599:3:
  6. path: Condition "ret != 0", taking true branch.

lib/pkg_editor/src/pkg_editor.c:1392:5:
  Type: Buffer not null terminated (BUFFER_SIZE)

lib/pkg_editor/src/pkg_editor.c:1323:3:
  1. path: Condition "!append_data(&info, 20UL /* sizeof (info) */, z_info, of, 0)", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1330:3:
  2. path: Condition "!append_data(dir_name, name_length, z_info, of, 0)", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1385:5:
  3. path: Condition "8192UL /* 2 * 4096 */ < name_length", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1392:5:
  4. buffer_size_warning: Calling "strncpy" with a maximum size argument of 8192 bytes on destination array "full_name
" of size 8192 bytes might leave the destination string unterminated.
lib/pkg_editor/src/pkg_editor.c:1394:5:
  5. path: Condition "full_name[8191 /* 2 * 4096 - 1 */] != 0", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1401:5:
  6. path: Condition "dir == NULL", taking false branch.
lib/pkg_editor/src/pkg_editor.c:1407:5:
  7. path: Condition "entry", taking false branch.

@pcolberg pcolberg marked this pull request as ready for review November 25, 2022 01:13
@pcolberg pcolberg requested a review from zibaiwan November 25, 2022 01:13
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 08e9cd0 into intel:main Nov 25, 2022
@pcolberg pcolberg deleted the buffer_size branch November 25, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants