authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2020-09-10 13:36:34+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-10 14:30:07-04:00
log4170f3f77f23bca52a2a9b24d1a249fae35c04ac
treeb65d26dde2eaab275be22dcab85655852c667ef8
parent0833c8d06ba9a467bb8449cbca2ba6f43d218c32

std: fix bitrot in process.posixGetUserInfo()


1 files changed, 8 insertions(+), 6 deletions(-)

lib/std/process.zig+8-6
...@@ -593,8 +593,10 @@ pub fn getUserInfo(name: []const u8) !UserInfo {...@@ -593,8 +593,10 @@ pub fn getUserInfo(name: []const u8) !UserInfo {
593/// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else593/// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
594/// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.594/// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
595pub fn posixGetUserInfo(name: []const u8) !UserInfo {595pub fn posixGetUserInfo(name: []const u8) !UserInfo {
596 var reader = try io.Reader.open("/etc/passwd", null);596 const file = try std.fs.openFileAbsolute("/etc/passwd", .{});
597 defer reader.close();597 defer file.close();
598
599 const reader = file.reader();
598600
599 const State = enum {601 const State = enum {
600 Start,602 Start,
...@@ -650,8 +652,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -650,8 +652,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
650 '0'...'9' => byte - '0',652 '0'...'9' => byte - '0',
651 else => return error.CorruptPasswordFile,653 else => return error.CorruptPasswordFile,
652 };654 };
653 if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile;655 if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;
654 if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile;656 if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;
655 },657 },
656 },658 },
657 .ReadGroupId => switch (byte) {659 .ReadGroupId => switch (byte) {
...@@ -666,8 +668,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {...@@ -666,8 +668,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
666 '0'...'9' => byte - '0',668 '0'...'9' => byte - '0',
667 else => return error.CorruptPasswordFile,669 else => return error.CorruptPasswordFile,
668 };670 };
669 if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile;671 if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;
670 if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile;672 if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;
671 },673 },
672 },674 },
673 }675 }