summaryrefslogtreecommitdiff
path: root/apps/gui/wps_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/wps_parser.c')
-rw-r--r--apps/gui/wps_parser.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index 442fd35ba0..67b8a6f9ca 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -766,21 +766,16 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
766 766
767 /* String */ 767 /* String */
768 default: 768 default:
769 if (data->num_strings < WPS_MAX_STRINGS
770 && stringbuf_used < STRING_BUFFER_SIZE - 1)
771 { 769 {
772 data->tokens[data->num_tokens].type = WPS_TOKEN_STRING;
773
774 unsigned int len = 1; 770 unsigned int len = 1;
775 const char *string_start = wps_bufptr - 1; 771 const char *string_start = wps_bufptr - 1;
776 772
777 /* continue until we hit something that ends the string 773 /* continue until we hit something that ends the string
778 or we run out of memory */ 774 or we run out of memory */
779 while(wps_bufptr && *wps_bufptr != '#' && 775 while (wps_bufptr && *wps_bufptr != '#' &&
780 *wps_bufptr != '%' && *wps_bufptr != ';' && 776 *wps_bufptr != '%' && *wps_bufptr != ';' &&
781 *wps_bufptr != '<' && *wps_bufptr != '>' && 777 *wps_bufptr != '<' && *wps_bufptr != '>' &&
782 *wps_bufptr != '|' && *wps_bufptr != '\n' && 778 *wps_bufptr != '|' && *wps_bufptr != '\n')
783 stringbuf_used < STRING_BUFFER_SIZE - 1)
784 { 779 {
785 wps_bufptr++; 780 wps_bufptr++;
786 len++; 781 len++;
@@ -791,29 +786,43 @@ static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
791 int i; 786 int i;
792 bool found; 787 bool found;
793 for (i = 0, str = data->strings, found = false; 788 for (i = 0, str = data->strings, found = false;
794 i < data->num_strings 789 i < data->num_strings &&
795 && !(found = (strlen(*str) == len && strncmp(string_start, *str, len) == 0)); 790 !(found = (strlen(*str) == len &&
796 i++, str++) ; 791 strncmp(string_start, *str, len) == 0));
797 /* If a matching string is found, found is true and i is the 792 i++, str++);
798 index of the string. If not, found is false */ 793 /* If a matching string is found, found is true and i is
799 794 the index of the string. If not, found is false */
800 if (!found) 795
796 /* If it's NOT a duplicate, do nothing if we already have
797 too many unique strings */
798 if (found ||
799 (stringbuf_used < STRING_BUFFER_SIZE - 1 &&
800 data->num_strings < WPS_MAX_STRINGS))
801 { 801 {
802 /* new string */ 802 if (!found)
803 strncpy(stringbuf, string_start, len); 803 {
804 data->strings[data->num_strings] = stringbuf; 804 /* new string */
805 stringbuf += len + 1; 805 /* truncate? */
806 stringbuf_used += len + 1; 806 if (stringbuf_used + len > STRING_BUFFER_SIZE - 1)
807 data->tokens[data->num_tokens].value.i = data->num_strings; 807 len = STRING_BUFFER_SIZE - stringbuf_used - 1;
808 data->num_strings++; 808
809 strncpy(stringbuf, string_start, len);
810
811 data->strings[data->num_strings] = stringbuf;
812 stringbuf += len + 1;
813 stringbuf_used += len + 1;
814 data->tokens[data->num_tokens].value.i =
815 data->num_strings;
816 data->num_strings++;
817 }
818 else
819 {
820 /* another ocurrence of an existing string */
821 data->tokens[data->num_tokens].value.i = i;
822 }
823 data->tokens[data->num_tokens].type = WPS_TOKEN_STRING;
824 data->num_tokens++;
809 } 825 }
810 else
811 {
812 /* another ocurrence of an existing string */
813 data->tokens[data->num_tokens].value.i = i;
814 }
815
816 data->num_tokens++;
817 } 826 }
818 break; 827 break;
819 } 828 }