]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virGetSubIDs: do not limit file size
authorJán Tomko <jtomko@redhat.com>
Tue, 12 May 2026 11:10:43 +0000 (13:10 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 14 May 2026 21:32:35 +0000 (23:32 +0200)
On systems with many users, this file can be larger than BUFSIZ.
Since the file should only be editable by root and virFileReadAll
reallocates the buffer in increments as needed as opposed to
allocating for 'maxlen' upfront, set the maximum to INT_MAX.

https://gitlab.com/libvirt/libvirt/-/work_items/874

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virutil.c

index 187b8202dd81162fdd9123d68d4e5ee3f7bc3c7e..3e107cdae6fe9a69cee84b339a46677dbfce08db 100644 (file)
@@ -1223,7 +1223,9 @@ virGetSubIDs(virSubID **retval, const char *file)
 
     *retval = NULL;
 
-    if (virFileReadAll(file, BUFSIZ, &buf) < 0)
+    /* We trust the source of the file so we set the limit absurdly high.
+     * For smaller files, the helper function will not allocate as much space */
+    if (virFileReadAll(file, INT_MAX, &buf) < 0)
         return -1;
 
     lines = g_strsplit(buf, "\n", 0);