Check if any cgroups have been selected and string subtree_control has a
length greater than 0 before reducing its length by 1, preventing to
write outside of the bounds of the array in case no cgroups are
selected.
Fixes: ID: TOB-OWRT-6
Fixes: 16159bb ("jail: parse OCI cgroups resources")
Reported-by: Trail of Bits
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
if (rdma)
strcat(subtree_control, "+rdma ");
- /* remove trailing space */
- ent = strchr(subtree_control, '\0') - 1;
- *ent = '\0';
+ /* remove trailing space (length is > 0) */
+ ent = strchr(subtree_control, '\0');
+ if (ent > subtree_control) {
+ ent -= 1;
+ *ent = '\0';
+ }
ent = malloc(maxlen);
if (!ent)