On Wed, Jul 21, 2021 at 14:46:41 +0200, Tim Wiederhake wrote:
The use of INT_MAX as maximum file length is problematic for reasons
discussed in the next commit.
Signed-off-by: Tim Wiederhake <twiederh(a)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");
In this case it's okay as is ...
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;
}
... but these two are common helper functions so having an limit of 10M
is in the realms of possibility to be hit.
The comments for both of those functions should mention that there's an
arbitrary limit in place.