From 6122bed3af3f9a46b471ba2920e728df4686dc79 Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 6 Mar 2024 21:00:33 -0800 Subject: [PATCH] fix: bounds check result in getMaxCPU Upstream-Bug: https://github.com/NixOS/nix/issues/9725 Upstream-PR: https://github.com/NixOS/nix/pull/10172 Change-Id: I2b8e8b15ee28951be98e5cbe3ccea5b9c8de5994 --- src/libutil/util.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 6fcce5d67..691b03bb0 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -796,6 +796,11 @@ unsigned int getMaxCPU() auto cpuMax = readFile(cpuFile); auto cpuMaxParts = tokenizeString>(cpuMax, " \n"); + + if (cpuMaxParts.size() != 2) { + return 0; + } + auto quota = cpuMaxParts[0]; auto period = cpuMaxParts[1]; if (quota != "max")