mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std: fix bitrot in process.posixGetUserInfo()
This commit is contained in:
parent
0833c8d06b
commit
4170f3f77f
@ -593,8 +593,10 @@ pub fn getUserInfo(name: []const u8) !UserInfo {
|
|||||||
/// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
|
/// TODO this reads /etc/passwd. But sometimes the user/id mapping is in something else
|
||||||
/// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
|
/// like NIS, AD, etc. See `man nss` or look at an strace for `id myuser`.
|
||||||
pub fn posixGetUserInfo(name: []const u8) !UserInfo {
|
pub fn posixGetUserInfo(name: []const u8) !UserInfo {
|
||||||
var reader = try io.Reader.open("/etc/passwd", null);
|
const file = try std.fs.openFileAbsolute("/etc/passwd", .{});
|
||||||
defer reader.close();
|
defer file.close();
|
||||||
|
|
||||||
|
const reader = file.reader();
|
||||||
|
|
||||||
const State = enum {
|
const State = enum {
|
||||||
Start,
|
Start,
|
||||||
@ -650,8 +652,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
|
|||||||
'0'...'9' => byte - '0',
|
'0'...'9' => byte - '0',
|
||||||
else => return error.CorruptPasswordFile,
|
else => return error.CorruptPasswordFile,
|
||||||
};
|
};
|
||||||
if (@mulWithOverflow(u32, uid, 10, *uid)) return error.CorruptPasswordFile;
|
if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;
|
||||||
if (@addWithOverflow(u32, uid, digit, *uid)) return error.CorruptPasswordFile;
|
if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.ReadGroupId => switch (byte) {
|
.ReadGroupId => switch (byte) {
|
||||||
@ -666,8 +668,8 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
|
|||||||
'0'...'9' => byte - '0',
|
'0'...'9' => byte - '0',
|
||||||
else => return error.CorruptPasswordFile,
|
else => return error.CorruptPasswordFile,
|
||||||
};
|
};
|
||||||
if (@mulWithOverflow(u32, gid, 10, *gid)) return error.CorruptPasswordFile;
|
if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;
|
||||||
if (@addWithOverflow(u32, gid, digit, *gid)) return error.CorruptPasswordFile;
|
if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user