threads / patch / 46890

patchtest-stringlist: avoid buffer underrun when sorting nothing

Subject: [PATCH] test-stringlist: avoid buffer underrun when sorting nothing

## tl;dr

2 messages between Oct 3, 2017 and Oct 3, 2017. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Oct 3, 2017, 14:36 UTC · lore

Check if the strbuf containing data to sort is empty before attempting to trim a trailing newline character.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 t/helper/test-string-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/helper/test-string-list.c +1 −1
diff --git a/t/helper/test-string-list.c b/t/helper/test-string-list.c
index c502fa16d3..829ec3d7d2 100644
--- a/t/helper/test-string-list.c
+++ b/t/helper/test-string-list.c
@@ -108,7 +108,7 @@ int cmd_main(int argc, const char **argv)
 		 * Split by newline, but don't create a string_list item
 		 * for the empty string after the last separator.
 		 */
-		if (sb.buf[sb.len - 1] == '\n')
+		if (sb.len && sb.buf[sb.len - 1] == '\n')
 			strbuf_setlen(&sb, sb.len - 1);
 		string_list_split_in_place(&list, sb.buf, '\n', -1);
 
-- 
2.14.2
Jonathan Nieder· Oct 3, 2017, 22:59 UTC · re: René Scharfe · lore

Re: [PATCH] test-stringlist: avoid buffer underrun when sorting nothing

René Scharfe wrote:
Show 7 quoted lines
> Check if the strbuf containing data to sort is empty before attempting
> to trim a trailing newline character.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  t/helper/test-string-list.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
Thanks for fixing it.
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

← back to recent threads