Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lib/pkg_editor/src/pkg_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,11 +1389,8 @@ static acl_pack_kind add_directory(const char *out_file, FILE *of,
}

// Partially initialize the full path name.
strncpy(full_name, dir_name, FULL_NAME_LENGTH);

if (full_name[FULL_NAME_LENGTH - 1] != '\0') {
full_name[FULL_NAME_LENGTH - 1] = '\0';
}
strncpy(full_name, dir_name, FULL_NAME_LENGTH - 1);
full_name[FULL_NAME_LENGTH - 1] = '\0';

full_name[name_length - 1] = '/';

Expand Down Expand Up @@ -1577,10 +1574,8 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
ZInfo z_info;
int ret;

strncpy(full_name, out_dir, FULL_NAME_LEN);
if (full_name[FULL_NAME_LEN - 1] != '\0') {
full_name[FULL_NAME_LEN - 1] = '\0';
}
strncpy(full_name, out_dir, FULL_NAME_LEN - 1);
full_name[FULL_NAME_LEN - 1] = '\0';

// Initialize zlib.
z_info.strm.zalloc = Z_NULL;
Expand Down