diff options
author | Ion Agorria | 2024-01-05 09:22:10 +0200 |
---|---|---|
committer | Mattijs Korpershoek | 2024-01-09 14:58:33 +0100 |
commit | e58bafc35fe37491bb3546299593dcc054145adb (patch) | |
tree | a50d65fe54980ff838d40d1a205433da49908d98 | |
parent | 90087dd076d42c196de3506b6fa4d052f0869670 (diff) |
lib: membuff: fix readline not returning line in case of overflow
If line overflows readline it will not be returned, fix this behavior,
make it optional and documented properly.
Signed-off-by: Ion Agorria <ion@agorria.com>
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Link: https://lore.kernel.org/r/20240105072212.6615-6-clamor95@gmail.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
-rw-r--r-- | boot/bootmeth_extlinux.c | 2 | ||||
-rw-r--r-- | common/console.c | 2 | ||||
-rw-r--r-- | include/membuff.h | 5 | ||||
-rw-r--r-- | lib/membuff.c | 4 |
4 files changed, 7 insertions, 6 deletions
diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c index aa2a4591ebd..ae0ad1d53e3 100644 --- a/boot/bootmeth_extlinux.c +++ b/boot/bootmeth_extlinux.c @@ -82,7 +82,7 @@ static int extlinux_fill_info(struct bootflow *bflow) log_debug("parsing bflow file size %x\n", bflow->size); membuff_init(&mb, bflow->buf, bflow->size); membuff_putraw(&mb, bflow->size, true, &data); - while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' '), len) { + while (len = membuff_readline(&mb, line, sizeof(line) - 1, ' ', true), len) { char *tok, *p = line; tok = strsep(&p, " "); diff --git a/common/console.c b/common/console.c index e6d7ebe935f..cad65891fc9 100644 --- a/common/console.c +++ b/common/console.c @@ -848,7 +848,7 @@ int console_record_readline(char *str, int maxlen) return -ENOSPC; return membuff_readline((struct membuff *)&gd->console_out, str, - maxlen, '\0'); + maxlen, '\0', false); } int console_record_avail(void) diff --git a/include/membuff.h b/include/membuff.h index 21051b0c54e..4eba626ce1c 100644 --- a/include/membuff.h +++ b/include/membuff.h @@ -192,10 +192,11 @@ int membuff_free(struct membuff *mb); * @mb: membuff to adjust * @str: Place to put the line * @maxlen: Maximum line length (excluding terminator) + * @must_fit: If true then str is empty if line doesn't fit * Return: number of bytes read (including terminator) if a line has been - * read, 0 if nothing was there + * read, 0 if nothing was there or line didn't fit when must_fit is set */ -int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch); +int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit); /** * membuff_extend_by() - expand a membuff diff --git a/lib/membuff.c b/lib/membuff.c index 3c6c0ae125c..b242a38ff1c 100644 --- a/lib/membuff.c +++ b/lib/membuff.c @@ -287,7 +287,7 @@ int membuff_free(struct membuff *mb) (mb->end - mb->start) - 1 - membuff_avail(mb); } -int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch) +int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch, bool must_fit) { int len; /* number of bytes read (!= string length) */ char *s, *end; @@ -309,7 +309,7 @@ int membuff_readline(struct membuff *mb, char *str, int maxlen, int minch) } /* couldn't get the whole string */ - if (!ok) { + if (!ok && must_fit) { if (maxlen) *orig = '\0'; return 0; |