[libvirt PATCH] util: virGetSubIDs: do not limit file size

Ján Tomko via Devel posted 1 patch 1 day, 1 hour ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/bf949404afca38b8b750854d5a7450966a57879c.1778746524.git.jtomko@redhat.com
There is a newer version of this series
src/util/virutil.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[libvirt PATCH] util: virGetSubIDs: do not limit file size
Posted by Ján Tomko via Devel 1 day, 1 hour ago
From: Ján Tomko <jtomko@redhat.com>

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>
---
 src/util/virutil.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index 187b8202dd..3e107cdae6 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -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);
-- 
2.54.0

Re: [libvirt PATCH] util: virGetSubIDs: do not limit file size
Posted by Peter Krempa via Devel 23 hours ago
On Thu, May 14, 2026 at 10:15:24 +0200, Ján Tomko via Devel wrote:
> From: Ján Tomko <jtomko@redhat.com>
> 
> 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>
> ---
>  src/util/virutil.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virutil.c b/src/util/virutil.c
> index 187b8202dd..3e107cdae6 100644
> --- a/src/util/virutil.c
> +++ b/src/util/virutil.c
> @@ -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);

Reviewed-by: Peter Krempa <pkrempa@redhat.com>