From 40cc8e0df2282e8fc8d20735ee351add1ae23644 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 18 Aug 2000 05:56:19 +0000 Subject: getfileline() - line with length of zero -> filebuf[strlen(filebuf)-1] is NOT ok. (This used to be commit 24e0c8ef70dc59bfaaa113c3d44befbccbcba15f) --- source3/lib/util_file.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 194fb7ae49..50bd85e6e3 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -217,21 +217,24 @@ int getfileline(void *vp, char *linebuf, int linebuf_size) */ linebuf_len = strlen(linebuf); - if (linebuf[linebuf_len - 1] != '\n') + if (linebuf_len > 0) { - c = '\0'; - while (!ferror(fp) && !feof(fp)) + if (linebuf[linebuf_len - 1] != '\n') { - c = fgetc(fp); - if (c == '\n') + c = '\0'; + while (!ferror(fp) && !feof(fp)) { - break; + c = fgetc(fp); + if (c == '\n') + { + break; + } } } - } - else - { - linebuf[linebuf_len - 1] = '\0'; + else + { + linebuf[linebuf_len - 1] = '\0'; + } } #ifdef DEBUG_PASSWORD -- cgit