add tests for upper limits

This commit is contained in:
2022-02-22 15:04:59 +02:00
committed by Motiejus Jakštys
parent 26fbfc5f08
commit 78dc63669d
2 changed files with 34 additions and 20 deletions

View File

@@ -32,15 +32,15 @@ pub const PackedUser = packed struct {
}
pub fn realHomeLen(self: *const PackedUser) usize {
return self.home_len + 1;
return @as(u32, self.home_len) + 1;
}
pub fn realNameLen(self: *const PackedUser) usize {
return self.name_len + 1;
return @as(u32, self.name_len) + 1;
}
pub fn realShellLen(self: *const PackedUser) usize {
return self.shell_len_or_idx + 1;
return @as(u32, self.shell_len_or_idx) + 1;
}
pub fn realGecosLen(self: *const PackedUser) usize {
@@ -180,7 +180,7 @@ pub const UserReader = struct {
if (u.name_is_a_suffix) {
const name_start = u.realHomeLen() - u.realNameLen();
name = entry.blob[name_start..u.realHomeLen()];
pos = u.home_len + 1;
pos = u.realHomeLen();
} else {
const name_start = u.realHomeLen();
name = entry.blob[name_start .. name_start + u.realNameLen()];
@@ -269,12 +269,12 @@ test "construct PackedUser blob" {
.home = "/home/service1",
.shell = "/usr/bin/nologin",
}, User{
.uid = 1002,
.gid = 1002,
.name = "user-account",
.gecos = "",
.home = "/a",
.shell = "/bin/zsh",
.uid = 0,
.gid = 4294967295,
.name = "n" ** 32,
.gecos = "g" ** 255,
.home = "h" ** 64,
.shell = "s" ** 64,
} };
for (users) |user| {
try writer.appendUser(user);