mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Return srclen in proc.idMapFileOperations.Write.
PiperOrigin-RevId: 241037926 Change-Id: I4b0381ac1c7575e8b861291b068d3da22bc03850
This commit is contained in:
@@ -169,5 +169,8 @@ func (imfo *idMapFileOperations) Write(ctx context.Context, file *fs.File, src u
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int64(len(b)), nil
|
||||
|
||||
// On success, Linux's kernel/user_namespace.c:map_write() always returns
|
||||
// count, even if fewer bytes were used.
|
||||
return int64(srclen), nil
|
||||
}
|
||||
|
||||
@@ -129,6 +129,23 @@ TEST_P(ProcSelfUidGidMapTest, IdentityMapOwnID) {
|
||||
IsPosixErrorOkAndHolds(0));
|
||||
}
|
||||
|
||||
TEST_P(ProcSelfUidGidMapTest, TrailingNewlineAndNULIgnored) {
|
||||
// This is identical to IdentityMapOwnID, except that a trailing newline, NUL,
|
||||
// and an invalid (incomplete) map entry are appended to the valid entry. The
|
||||
// newline should be accepted, and everything after the NUL should be ignored.
|
||||
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(CanCreateUserNamespace()));
|
||||
uint32_t id = CurrentID();
|
||||
std::string line = absl::StrCat(id, " ", id, " 1\n\0 4 3");
|
||||
EXPECT_THAT(
|
||||
InNewUserNamespaceWithMapFD([&](int fd) {
|
||||
DenySelfSetgroups();
|
||||
// The write should return the full size of the write, even though
|
||||
// characters after the NUL were ignored.
|
||||
TEST_PCHECK(write(fd, line.c_str(), line.size()) == line.size());
|
||||
}),
|
||||
IsPosixErrorOkAndHolds(0));
|
||||
}
|
||||
|
||||
TEST_P(ProcSelfUidGidMapTest, NonIdentityMapOwnID) {
|
||||
SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(CanCreateUserNamespace()));
|
||||
SKIP_IF(ASSERT_NO_ERRNO_AND_VALUE(HaveSetIDCapability()));
|
||||
|
||||
Reference in New Issue
Block a user