Throw an error when running out of DevId numbers

I find it hard to imagine that this will happen on a real filesystem,
but it can be triggered by a malicious export file. Better protect
against that than invoke undefined behavior.
This commit is contained in:
Yorhel 2024-08-08 15:38:54 +02:00
parent 252f7fc253
commit 18f322c532

View file

@ -346,6 +346,7 @@ pub const devices = struct {
defer lock.unlock(); defer lock.unlock();
const d = lookup.getOrPut(dev) catch unreachable; const d = lookup.getOrPut(dev) catch unreachable;
if (!d.found_existing) { if (!d.found_existing) {
if (list.items.len >= std.math.maxInt(DevId)) ui.die("Maximum number of device identifiers exceeded.\n", .{});
d.value_ptr.* = @as(DevId, @intCast(list.items.len)); d.value_ptr.* = @as(DevId, @intCast(list.items.len));
list.append(dev) catch unreachable; list.append(dev) catch unreachable;
} }