From 104a987024658098c05c9f6dedecfd42d7e06aef Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Tue, 11 Mar 2014 00:05:11 +0100 Subject: [PATCH] shared/hfp: Don't update offset if string parsing failed --- src/shared/hfp.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/shared/hfp.c b/src/shared/hfp.c index 325693106..36c8c3e2f 100644 --- a/src/shared/hfp.c +++ b/src/shared/hfp.c @@ -299,20 +299,22 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf, { int i = 0; const char *data = result->data; + unsigned int offset; skip_whitespace(result); if (data[result->offset] != '"') return false; - result->offset++; + offset = result->offset; + offset++; - while (data[result->offset] != '\0' && data[result->offset] != '"') { + while (data[offset] != '\0' && data[offset] != '"') { if (i == len) return false; - buf[i++] = data[result->offset]; - result->offset++; + buf[i++] = data[offset]; + offset++; } if (i == len) @@ -320,11 +322,13 @@ bool hfp_gw_result_get_string(struct hfp_gw_result *result, char *buf, buf[i] = '\0'; - if (data[result->offset] == '"') - result->offset++; + if (data[offset] == '"') + offset++; else return false; + result->offset = offset; + skip_whitespace(result); next_field(result); @@ -335,6 +339,7 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf, uint8_t len) { const char *data = result->data; + unsigned int offset; int i = 0; char c; @@ -344,13 +349,15 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf, if (c == '"' || c == ')' || c == '(') return false; - while (data[result->offset] != '\0' && data[result->offset] != ',' - && data[result->offset] != ')') { + offset = result->offset; + + while (data[offset] != '\0' && data[offset] != ',' && + data[offset] != ')') { if (i == len) return false; - buf[i++] = data[result->offset]; - result->offset++; + buf[i++] = data[offset]; + offset++; } if (i == len) @@ -358,6 +365,8 @@ bool hfp_gw_result_get_unquoted_string(struct hfp_gw_result *result, char *buf, buf[i] = '\0'; + result->offset = offset; + next_field(result); return true; -- 2.47.3