Skip to content

Commit

Permalink
icalvalue.c: truncate long GEO values rather than erroring
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison authored and brong committed Feb 28, 2024
1 parent 28cfd65 commit a2a5ce4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/libical/icalvalue.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int simple_str_to_doublestr(const char *from, char *result, int result_le
#if !defined(HAVE_GETNUMBERFORMAT)
struct lconv *loc_data = localeconv();
#endif
int i = 0;
int i = 0, len;
double dtest;

/*sanity checks */
Expand All @@ -392,17 +392,18 @@ static int simple_str_to_doublestr(const char *from, char *result, int result_le
++cur;
}
end = cur;
if (end - start + 1 > result_len) {
/*huh hoh, number is too big. getting out */
return 1;
len = end - start;
if (len + 1 >= result_len) {
/* huh hoh, number is too big. truncate it */
len = result_len - 1;
}

/* copy the float number string into tmp_buf, and take
/* copy the float number string into result, and take
* care to have the (optional) decimal separator be the one
* of the current locale.
*/
#if !defined(HAVE_GETNUMBERFORMAT)
for (i = 0; i < end - start; ++i) {
for (i = 0; i < len; ++i) {
if (start[i] == '.' && loc_data && loc_data->decimal_point && loc_data->decimal_point[0]
&& loc_data->decimal_point[0] != '.') {
/*replace '.' by the digit separator of the current locale */
Expand Down
5 changes: 4 additions & 1 deletion src/test/regression.c
Original file line number Diff line number Diff line change
Expand Up @@ -4421,14 +4421,17 @@ void test_geo_props(void)
ok("expected fail icalcomponent_get_first_property()", (p == NULL));
icalcomponent_free(c);

/* truncation situations */
c = icalparser_parse_string("BEGIN:VEVENT\n" "GEO:16.815151515151515151;+0\n" "END:VEVENT\n");
ok("icalparser_parse_string()", (c != NULL));
if (!c) {
exit(EXIT_FAILURE);
}
if (VERBOSE)
printf("%s", icalcomponent_as_ical_string(c));
p = icalcomponent_get_first_property(c, ICAL_GEO_PROPERTY);
ok("expected fail icalcomponent_get_first_property()", (p == NULL));
str_is("icalproperty_get_value_as_string() works",
icalproperty_get_value_as_string(p), "16.815151515151;+0");
icalcomponent_free(c);

icalerror_set_errors_are_fatal(estate);
Expand Down

0 comments on commit a2a5ce4

Please sign in to comment.