From: Lennart Poettering Date: Fri, 21 May 2021 14:31:52 +0000 (+0200) Subject: fileio: read_virtual_file(): exit once the max_size limit is reached X-Git-Tag: v249-rc1~177^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=136f12a26ae0b6930094574f55e9399b120e54c0;p=thirdparty%2Fsystemd.git fileio: read_virtual_file(): exit once the max_size limit is reached Alternative to: #19682 --- diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 7bb1e8a8c6e..cb8f5b0b184 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -450,6 +450,13 @@ int read_virtual_file(const char *filename, size_t max_size, char **ret_contents if (n <= size) break; + /* If a maximum size is specified and we already read as much, no need to try again */ + if (max_size != SIZE_MAX && n >= max_size) { + n = max_size; + truncated = true; + break; + } + /* Hmm... either we read too few bytes from /proc or less likely the content * of the file might have been changed (and is now bigger) while we were * processing, let's try again either with a bigger guessed size or the new