Skip to content

Resolve address sanitizer issues in pkg_editor_test #191

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

Merged
merged 3 commits into from
Oct 31, 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
25 changes: 14 additions & 11 deletions lib/pkg_editor/test/pkg_editor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct acl_pkg_file *create_file() {
pkg = acl_pkg_open_file(SAMPLE_FILE, ACL_PKG_CREATE | ACL_PKG_READ_WRITE);
CHECK(pkg);

char name[] = "13.0.0";
const static char name[] = "13.0.0";
CHECK(acl_pkg_add_data_section(pkg, ACL_PKG_SECTION_ACL_VERSION, name,
sizeof(name)));
return pkg;
Expand Down Expand Up @@ -153,6 +153,7 @@ TEST(sample_file, write_ops_on_readonly) {
sizeof(data)));
CHECK_EQUAL(0, acl_pkg_update_section_from_file(pkg, ACL_PKG_SECTION_HASH,
SAMPLE_FILE));
close_file(pkg);
printf("end writeops\n");
}

Expand All @@ -170,12 +171,12 @@ TEST(sample_file, write_ops_on_writable) {
acl_pkg_add_data_section(pkg, ACL_PKG_SECTION_HASH, &data, sizeof(data)));
// Check that we get the right data back.
size_t data_size;
size_t data_result = 99;
CHECK(acl_pkg_section_exists(pkg, ACL_PKG_SECTION_HASH, &data_size));
CHECK_EQUAL(sizeof(data), data_size);
CHECK(acl_pkg_read_section(pkg, ACL_PKG_SECTION_HASH, (char *)&data_result,
data_size + 1));
CHECK_EQUAL(data, data_result);
char data_result[sizeof(data) + 1] = {0};
CHECK(acl_pkg_read_section(pkg, ACL_PKG_SECTION_HASH, data_result,
sizeof(data_result)));
CHECK_EQUAL(0, memcmp(&data, data_result, sizeof(data)));
char *data_result_ptr = 0;
CHECK(acl_pkg_read_section_transient(pkg, ACL_PKG_SECTION_HASH,
&data_result_ptr));
Expand All @@ -187,10 +188,10 @@ TEST(sample_file, write_ops_on_writable) {
// Check that we get the right data back.
CHECK(acl_pkg_section_exists(pkg, ACL_PKG_SECTION_HASH, &data_size));
CHECK_EQUAL(sizeof(data), data_size);
data_result = 99;
CHECK(acl_pkg_read_section(pkg, ACL_PKG_SECTION_HASH, (char *)&data_result,
data_size + 1));
CHECK_EQUAL(data2, data_result);
char data2_result[sizeof(data) + 1] = {0};
CHECK(acl_pkg_read_section(pkg, ACL_PKG_SECTION_HASH, data2_result,
sizeof(data2_result)));
CHECK_EQUAL(0, memcmp(&data2, data2_result, sizeof(data2)));
data_result_ptr = 0;
CHECK(acl_pkg_read_section_transient(pkg, ACL_PKG_SECTION_HASH,
&data_result_ptr));
Expand All @@ -203,6 +204,8 @@ TEST(sample_file, write_ops_on_writable) {
// check result -- it must contain these two section names
CHECK(strstr(buf, ACL_PKG_SECTION_HASH));
CHECK(strstr(buf, ACL_PKG_SECTION_ACL_VERSION));

close_file(pkg);
printf("end writeops_write\n");
}

Expand Down Expand Up @@ -230,9 +233,9 @@ TEST(sample_file, read_readonly) {
CHECK(pkg);
CHECK(acl_pkg_section_exists(pkg, ACL_PKG_SECTION_HASH, &data_size));
CHECK_EQUAL(sizeof(hw), data_size);
char data_result[sizeof(hw)];
char data_result[sizeof(hw) + 1] = {0};
CHECK(acl_pkg_read_section(pkg, ACL_PKG_SECTION_HASH, data_result,
data_size + 1));
sizeof(data_result)));
CHECK_EQUAL(0, strcmp(data_result, hw));
char *data_result_ptr = 0;
CHECK(acl_pkg_read_section_transient(pkg, ACL_PKG_SECTION_HASH,
Expand Down