Skip to content

Commit 08e9cd0

Browse files
committed
pkg_editor: unconditionally null-terminate output of strncpy()
Resolves Coverity error "Buffer not null terminated (BUFFER_SIZE)". The previous code was correct but non-idiomatic. Signed-off-by: Peter Colberg <[email protected]>
1 parent 17d8f6b commit 08e9cd0

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/pkg_editor/src/pkg_editor.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,11 +1389,8 @@ static acl_pack_kind add_directory(const char *out_file, FILE *of,
13891389
}
13901390

13911391
// Partially initialize the full path name.
1392-
strncpy(full_name, dir_name, FULL_NAME_LENGTH);
1393-
1394-
if (full_name[FULL_NAME_LENGTH - 1] != '\0') {
1395-
full_name[FULL_NAME_LENGTH - 1] = '\0';
1396-
}
1392+
strncpy(full_name, dir_name, FULL_NAME_LENGTH - 1);
1393+
full_name[FULL_NAME_LENGTH - 1] = '\0';
13971394

13981395
full_name[name_length - 1] = '/';
13991396

@@ -1577,10 +1574,8 @@ static int acl_pkg_unpack_buffer_or_file(const char *buffer, size_t buffer_size,
15771574
ZInfo z_info;
15781575
int ret;
15791576

1580-
strncpy(full_name, out_dir, FULL_NAME_LEN);
1581-
if (full_name[FULL_NAME_LEN - 1] != '\0') {
1582-
full_name[FULL_NAME_LEN - 1] = '\0';
1583-
}
1577+
strncpy(full_name, out_dir, FULL_NAME_LEN - 1);
1578+
full_name[FULL_NAME_LEN - 1] = '\0';
15841579

15851580
// Initialize zlib.
15861581
z_info.strm.zalloc = Z_NULL;

0 commit comments

Comments
 (0)