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 {
593593/// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
594594/// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
595595pub fn posixGetUserInfo(name: []const u8) !UserInfo {
596 var reader = try io.Reader.open("/etc/passwd", null);
597 defer reader.close();
596 const file = try std.fs.openFileAbsolute("/etc/passwd", .{});
597 defer file.close();
598
599 const reader = file.reader();
598600
599601 const State = enum {
600602 Start,
......@@ -650,8 +652,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
650652 '0'...'9' => byte - '0',
651653 else => return error.CorruptPasswordFile,
652654 };
653 if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile;
654 if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile;
655 if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;
656 if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;
655657 },
656658 },
657659 .ReadGroupId => switch (byte) {
......@@ -666,8 +668,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
666668 '0'...'9' => byte - '0',
667669 else => return error.CorruptPasswordFile,
668670 };
669 if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile;
670 if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile;
671 if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;
672 if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;
671673 },
672674 },
673675 }