Skip to content

Commit 1a4c87e

Browse files
committed
Validate acl_to_text() input before forwarding to libacl
The acl_to_text() wrapper previously forwarded nullptr ACL handles directly into libacl. Under ASan/UBSan builds this triggered undefined behavior inside libacl internals before the library returned an error condition. Add explicit parameter validation in the wrapper and return EINVAL for invalid ACL inputs before invoking libacl. The related test was updated to validate the wrapper contract directly by passing nullptr instead of relying on acl_get_file("") to indirectly produce an invalid ACL handle. This change improves defensive behavior for invalid input handling and avoids sanitizer failures caused by passing invalid pointers into third-party C library internals.
1 parent a23098a commit 1a4c87e

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

score/os/acl_impl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,18 @@ score::cpp::expected<char*, score::os::Error> AclInstance::acl_to_text(const Acl
400400
ssize_t* const len_p) const noexcept
401401
/* KW_SUPPRESS_END:MISRA.VAR.HIDDEN:Wrapper function is identifiable through namespace usage */
402402
{
403+
if ((acl == nullptr) || (len_p == nullptr))
404+
{
405+
errno = EINVAL;
406+
return score::cpp::make_unexpected(score::os::Error::createFromErrno());
407+
}
408+
403409
auto* const acl_text = ::acl_to_text(acl, len_p);
404410
if (acl_text == nullptr)
405411
{
406412
return score::cpp::make_unexpected(score::os::Error::createFromErrno());
407413
}
414+
408415
return acl_text;
409416
}
410417

score/os/test/acl_test.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,14 @@ TEST_F(AclTestFixture, AclToTextToReturnErrorIfPassInvalidAcl)
242242
RecordProperty("Verifies", "SCR-46010294");
243243
RecordProperty("ASIL", "QM");
244244
RecordProperty("Description", "ACL shall return error if pass invalid ACL");
245-
RecordProperty("TestType", "requirements-based"); // requirements test
246-
RecordProperty("DerivationTechnique", "requirements-analysis"); // requirements
245+
RecordProperty("TestType", "requirements-based");
246+
RecordProperty("DerivationTechnique", "requirements-analysis");
247247

248-
auto* result = ::acl_get_file("", ACL_TYPE_ACCESS);
249248
ssize_t len{0};
250-
auto res = unit_.acl_to_text(result, &len);
251-
ASSERT_FALSE(res.has_value());
252249

253-
::acl_free(result);
250+
auto res = unit_.acl_to_text(nullptr, &len);
251+
252+
ASSERT_FALSE(res.has_value());
254253
}
255254

256255
// Test to set fd return error if invalid parameters are passed

0 commit comments

Comments
 (0)