summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2005-11-28 16:30:16 +0000
committerjhb <jhb@FreeBSD.org>2005-11-28 16:30:16 +0000
commit7091045951f78ddef36351f39e38b8d2b1b7895b (patch)
tree018eda33e27ac8d4eba87ae0559d4c54116168ec /lib
parentde3a26c2e0ed69da33a6535ab3378ade4bb96ed3 (diff)
downloadFreeBSD-src-7091045951f78ddef36351f39e38b8d2b1b7895b.zip
FreeBSD-src-7091045951f78ddef36351f39e38b8d2b1b7895b.tar.gz
Restore the previous state after a FILL operation in properties_read()
rather than forcing the state to LOOK. If we are in the middle of parsing a line when we have to do a FILL we would have lost any token we were in the middle of parsing and would have treated the next character as being at the start of a new line instead. PR: kern/89181 Submitted by: Antony Mawer gnats at mawer dot org MFC after: 1 week
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/property.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/libutil/property.c b/lib/libutil/property.c
index f2c3917..a944f9d 100644
--- a/lib/libutil/property.c
+++ b/lib/libutil/property.c
@@ -75,17 +75,18 @@ properties_read(int fd)
char hold_v[PROPERTY_MAX_VALUE + 1];
char buf[BUFSIZ * 4];
int bp, n, v, max;
- enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state;
+ enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state, last_state;
int ch = 0, blevel = 0;
n = v = bp = max = 0;
head = ptr = NULL;
- state = LOOK;
+ state = last_state = LOOK;
while (state != STOP) {
if (state != COMMIT) {
- if (bp == max)
+ if (bp == max) {
+ last_state = state;
state = FILL;
- else
+ } else
ch = buf[bp++];
}
switch(state) {
@@ -96,13 +97,19 @@ properties_read(int fd)
}
if (max == 0) {
state = STOP;
- break;
} else {
- state = LOOK;
+ /*
+ * Restore the state from before the fill (which will be
+ * initialised to LOOK for the first FILL). This ensures that
+ * if we were part-way through eg., a VALUE state, when the
+ * buffer ran out, that the previous operation will be allowed
+ * to complete.
+ */
+ state = last_state;
ch = buf[0];
- bp = 1;
+ bp = 0;
}
- /* FALLTHROUGH deliberately since we already have a character and state == LOOK */
+ continue;
case LOOK:
if (isspace((unsigned char)ch))
OpenPOWER on IntegriCloud