aboutsummaryrefslogtreecommitdiff
path: root/libbb/parse_config.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-01-31 08:22:10 +0000
committerRon Yorston <rmy@pobox.com>2023-01-31 08:22:10 +0000
commitf3aae6b7c256b1d9faff96f957f32886643bbaa8 (patch)
tree18d08897a507cb7866f309ec996268cb4cf0b2dd /libbb/parse_config.c
parentb9a1b02dee2b82e4e4a580c446a1e022aa96166d (diff)
downloadbusybox-w32-f3aae6b7c256b1d9faff96f957f32886643bbaa8.tar.gz
busybox-w32-f3aae6b7c256b1d9faff96f957f32886643bbaa8.tar.bz2
busybox-w32-f3aae6b7c256b1d9faff96f957f32886643bbaa8.zip
libbb: fix CRLF handling
Ensure a trailing CR is only removed if it precedes a LF. The two cases at issue are intended to read complete lines and remove the line terminator. In the normal case a trailing LF will be present so removing the CR unconditionally worked. However, if the last line of a file was missing its LF or if a NUL was detected (in the case of xmalloc_fgetline()) the CR might have been removed without justification.
Diffstat (limited to 'libbb/parse_config.c')
-rw-r--r--libbb/parse_config.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index f7a2b81b9..800a2935e 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -113,11 +113,16 @@ static int get_line_with_continuation(parser_t *parser)
113 line = parser->line; 113 line = parser->line;
114 for (;;) { 114 for (;;) {
115 parser->lineno++; 115 parser->lineno++;
116#if ENABLE_PLATFORM_MINGW32
116 if (line[len - 1] == '\n') 117 if (line[len - 1] == '\n')
117 len--; 118 len--;
118#if ENABLE_PLATFORM_MINGW32 119#else
119 if (line[len - 1] == '\r') 120 if (line[len - 1] == '\n') {
120 len--; 121 len--;
122 if (len != 0 && line[len - 1] == '\r') {
123 len--;
124 }
125 }
121#endif 126#endif
122 if (len == 0 || line[len - 1] != '\\') 127 if (len == 0 || line[len - 1] != '\\')
123 break; 128 break;