[libvirt PATCH 2/4] virfile: Use VIR_MAX_FILE_LEN instead of INT_MAX to limit file size

Tim Wiederhake twiederh at redhat.com
Wed Jul 21 12:46:41 UTC 2021


The use of INT_MAX as maximum file length is problematic for reasons
discussed in the next commit.

Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 tests/networkxml2firewalltest.c | 2 +-
 tests/testutils.c               | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c
index 91336a0c55..114e17fbbd 100644
--- a/tests/networkxml2firewalltest.c
+++ b/tests/networkxml2firewalltest.c
@@ -176,7 +176,7 @@ mymain(void)
 
     basefile = g_strdup_printf("%s/networkxml2firewalldata/base.args", abs_srcdir);
 
-    if (virFileReadAll(basefile, INT_MAX, &baseargs) < 0)
+    if (virFileReadAll(basefile, VIR_MAX_FILE_LEN, &baseargs) < 0)
         return EXIT_FAILURE;
 
     DO_TEST("nat-default");
diff --git a/tests/testutils.c b/tests/testutils.c
index 7d87e30a5c..c71e099bf1 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -313,7 +313,7 @@ virTestLoadFileJSON(const char *p, ...)
     if (!(path = virTestLoadFileGetPath(p, ap)))
         goto cleanup;
 
-    if (virFileReadAll(path, INT_MAX, &jsonstr) < 0)
+    if (virFileReadAll(path, VIR_MAX_FILE_LEN, &jsonstr) < 0)
         goto cleanup;
 
     if (!(ret = virJSONValueFromString(jsonstr)))
@@ -562,7 +562,8 @@ virTestCompareToFileFull(const char *actual,
         if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
             return -1;
     } else {
-        if (virFileReadAll(filename, INT_MAX, &filecontent) < 0 && !virTestGetRegenerate())
+        if (virFileReadAll(filename, VIR_MAX_FILE_LEN, &filecontent) < 0 &&
+            !virTestGetRegenerate())
             return -1;
     }
 
-- 
2.31.1




More information about the libvir-list mailing list