[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] libbb: Fix xmalloc_fgets() newline handling
From:       Mark Thompson <mark.thompson () starleaf ! com>
Date:       2018-08-31 12:03:54
Message-ID: ee0a1229-ba31-2ae6-c143-097f4e6db8ab () starleaf ! com
[Download RAW message or body]

Since 2da9724b56169f00bd7fb6b9a11c9409a7620981, xmalloc_fgets() will always
return the entirety of a text file rather than stopping at '\n' as one would
expect from fgets().  This is visible in for example 'head -n -1', which
outputs nothing rather than all but the last line of the input.

Signed-off-by: Mark Thompson <mark.thompson@starleaf.com>
---
Found from tracking down why 'ifdown foo' would always protest that 'foo' was \
unconfigured, despite it being in the ifstate file (but not as the first line).  The \
'head -n -1' example is a much easier way to show the problem, and there are probably \
a few other places with unexpected behaviour because of it.


 libbb/get_line_from_file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
index f3d6c62..ad04e3a 100644
--- a/libbb/get_line_from_file.c
+++ b/libbb/get_line_from_file.c
@@ -47,7 +47,8 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end)
 /* Get line, including trailing \n if any */
 char* FAST_FUNC xmalloc_fgets(FILE *file)
 {
-	return bb_get_chunk_from_file(file, NULL);
+	size_t i;
+	return bb_get_chunk_from_file(file, &i);
 }
 /* Get line.  Remove trailing \n */
 char* FAST_FUNC xmalloc_fgetline(FILE *file)
-- 
2.7.4
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic