summaryrefslogtreecommitdiff
path: root/apps/gui
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui')
-rw-r--r--apps/gui/wps_parser.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 67b8a6f9ca..ee16de330a 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -770,12 +770,11 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
770 unsigned int len = 1; 770 unsigned int len = 1;
771 const char *string_start = wps_bufptr - 1; 771 const char *string_start = wps_bufptr - 1;
772 772
773 /* continue until we hit something that ends the string 773 /* find the length of the string */
774 or we run out of memory */
775 while (wps_bufptr && *wps_bufptr != '#' && 774 while (wps_bufptr && *wps_bufptr != '#' &&
776 *wps_bufptr != '%' && *wps_bufptr != ';' && 775 *wps_bufptr != '%' && *wps_bufptr != ';' &&
777 *wps_bufptr != '<' && *wps_bufptr != '>' && 776 *wps_bufptr != '<' && *wps_bufptr != '>' &&
778 *wps_bufptr != '|' && *wps_bufptr != '\n') 777 *wps_bufptr != '|' && *wps_bufptr != '\n')
779 { 778 {
780 wps_bufptr++; 779 wps_bufptr++;
781 len++; 780 len++;
@@ -788,7 +787,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
788 for (i = 0, str = data->strings, found = false; 787 for (i = 0, str = data->strings, found = false;
789 i < data->num_strings && 788 i < data->num_strings &&
790 !(found = (strlen(*str) == len && 789 !(found = (strlen(*str) == len &&
791 strncmp(string_start, *str, len) == 0)); 790 strncmp(string_start, *str, len) == 0));
792 i++, str++); 791 i++, str++);
793 /* If a matching string is found, found is true and i is 792 /* If a matching string is found, found is true and i is
794 the index of the string. If not, found is false */ 793 the index of the string. If not, found is false */
@@ -796,23 +795,24 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
796 /* If it's NOT a duplicate, do nothing if we already have 795 /* If it's NOT a duplicate, do nothing if we already have
797 too many unique strings */ 796 too many unique strings */
798 if (found || 797 if (found ||
799 (stringbuf_used < STRING_BUFFER_SIZE - 1 && 798 (stringbuf_used < STRING_BUFFER_SIZE - 1 &&
800 data->num_strings < WPS_MAX_STRINGS)) 799 data->num_strings < WPS_MAX_STRINGS))
801 { 800 {
802 if (!found) 801 if (!found)
803 { 802 {
804 /* new string */ 803 /* new string */
805 /* truncate? */ 804
805 /* truncate? */
806 if (stringbuf_used + len > STRING_BUFFER_SIZE - 1) 806 if (stringbuf_used + len > STRING_BUFFER_SIZE - 1)
807 len = STRING_BUFFER_SIZE - stringbuf_used - 1; 807 len = STRING_BUFFER_SIZE - stringbuf_used - 1;
808 808
809 strncpy(stringbuf, string_start, len); 809 strncpy(stringbuf, string_start, len);
810 810 *(stringbuf + len) = '\0';
811
811 data->strings[data->num_strings] = stringbuf; 812 data->strings[data->num_strings] = stringbuf;
812 stringbuf += len + 1; 813 stringbuf += len + 1;
813 stringbuf_used += len + 1; 814 stringbuf_used += len + 1;
814 data->tokens[data->num_tokens].value.i = 815 data->tokens[data->num_tokens].value.i = data->num_strings;
815 data->num_strings;
816 data->num_strings++; 816 data->num_strings++;
817 } 817 }
818 else 818 else
@@ -828,6 +828,9 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
828 } 828 }
829 } 829 }
830 830
831 if (level >= 0) /* there are unclosed conditionals */
832 fail = PARSE_FAIL_UNCLOSED_COND;
833
831#ifdef DEBUG 834#ifdef DEBUG
832 print_debug_info(data, fail, line); 835 print_debug_info(data, fail, line);
833#endif 836#endif