mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] Fix off-by-one buffer overflow in getdelim
@ 2015-10-24 20:43 Felix Janda
  2015-10-24 21:36 ` Rich Felker
  2018-09-16 18:25 ` Rich Felker
  0 siblings, 2 replies; 10+ messages in thread
From: Felix Janda @ 2015-10-24 20:43 UTC (permalink / raw)
  To: musl

when deciding whether to resize the buffer, the terminating null byte
was not taken into account
---
 src/stdio/getdelim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c
index a88c393..3077490 100644
--- a/src/stdio/getdelim.c
+++ b/src/stdio/getdelim.c
@@ -27,7 +27,7 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
 	for (;;) {
 		z = memchr(f->rpos, delim, f->rend - f->rpos);
 		k = z ? z - f->rpos + 1 : f->rend - f->rpos;
-		if (i+k >= *n) {
+		if (i+k+1 >= *n) {
 			if (k >= SIZE_MAX/2-i) goto oom;
 			*n = i+k+2;
 			if (*n < SIZE_MAX/4) *n *= 2;
-- 
2.4.9


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-09-17  2:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-24 20:43 [PATCH] Fix off-by-one buffer overflow in getdelim Felix Janda
2015-10-24 21:36 ` Rich Felker
2015-10-24 22:25   ` Felix Janda
2015-10-24 23:35     ` Rich Felker
2015-10-25  0:32       ` Rich Felker
2015-10-25  6:18         ` Felix Janda
2018-09-16 18:25 ` Rich Felker
2018-09-16 18:34   ` Rich Felker
2018-09-16 23:32     ` Rich Felker
2018-09-17  2:01       ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).