diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 11b031bd388db5c8e2ef323272819e9bfcdad84d..18aa0b52598b19ec2319551927827c02f1eca48b 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -3313,7 +3313,7 @@ g_desktop_app_info_launch_with_kylin_process_manager (GDesktopAppInfo *info, g_variant_builder_close (&builder); gboolean has_icon_geometry = FALSE; - if (g_object_get_data (launch_context, "rectX")) { + if (g_object_get_data (launch_context, "rectWidth")) { has_icon_geometry = TRUE; gint rect_x = GPOINTER_TO_INT(g_object_get_data(launch_context, "rectX")); gint rect_y = GPOINTER_TO_INT(g_object_get_data(launch_context, "rectY")); diff --git a/glib/gdatetime.c b/glib/gdatetime.c index b5372d8346f7382a3514db748e0bd093dadcf55b..34685b5e0a8cd6e5fa6043a9e7da62978ae06c01 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -1393,12 +1393,16 @@ parse_iso8601_date (const gchar *text, gsize length, return FALSE; } +/* Value returned in tz_offset is valid if and only if the function return value + * is non-NULL. */ static GTimeZone * -parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset) +parse_iso8601_timezone (const gchar *text, gsize length, size_t *tz_offset) { - gint i, tz_length, offset_hours, offset_minutes; + size_t tz_length; + gint offset_hours, offset_minutes; gint offset_sign = 1; GTimeZone *tz; + const char *tz_start; /* UTC uses Z suffix */ if (length > 0 && text[length - 1] == 'Z') @@ -1408,42 +1412,42 @@ parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset) } /* Look for '+' or '-' of offset */ - for (i = length - 1; i >= 0; i--) - if (text[i] == '+' || text[i] == '-') + for (tz_length = 1; tz_length <= length; tz_length++) + if (text[length - tz_length] == '+' || text[length - tz_length] == '-') { - offset_sign = text[i] == '-' ? -1 : 1; + offset_sign = text[length - tz_length] == '-' ? -1 : 1; break; } - if (i < 0) + if (tz_length > length) return NULL; - tz_length = length - i; + tz_start = text + length - tz_length; /* +hh:mm or -hh:mm */ - if (tz_length == 6 && text[i+3] == ':') + if (tz_length == 6 && tz_start[3] == ':') { - if (!get_iso8601_int (text + i + 1, 2, &offset_hours) || - !get_iso8601_int (text + i + 4, 2, &offset_minutes)) + if (!get_iso8601_int (tz_start + 1, 2, &offset_hours) || + !get_iso8601_int (tz_start + 4, 2, &offset_minutes)) return NULL; } /* +hhmm or -hhmm */ else if (tz_length == 5) { - if (!get_iso8601_int (text + i + 1, 2, &offset_hours) || - !get_iso8601_int (text + i + 3, 2, &offset_minutes)) + if (!get_iso8601_int (tz_start + 1, 2, &offset_hours) || + !get_iso8601_int (tz_start + 3, 2, &offset_minutes)) return NULL; } /* +hh or -hh */ else if (tz_length == 3) { - if (!get_iso8601_int (text + i + 1, 2, &offset_hours)) + if (!get_iso8601_int (tz_start + 1, 2, &offset_hours)) return NULL; offset_minutes = 0; } else return NULL; - *tz_offset = i; - tz = g_time_zone_new_identifier (text + i); + *tz_offset = tz_start - text; + tz = g_time_zone_new_identifier (tz_start); /* Double-check that the GTimeZone matches our interpretation of the timezone. * This can fail because our interpretation is less strict than (for example) @@ -1462,11 +1466,11 @@ static gboolean parse_iso8601_time (const gchar *text, gsize length, gint *hour, gint *minute, gdouble *seconds, GTimeZone **tz) { - gssize tz_offset = -1; + size_t tz_offset = 0; /* Check for timezone suffix */ *tz = parse_iso8601_timezone (text, length, &tz_offset); - if (tz_offset >= 0) + if (*tz != NULL) length = tz_offset; /* hh:mm:ss(.sss) */ @@ -1544,7 +1548,8 @@ parse_iso8601_time (const gchar *text, gsize length, GDateTime * g_date_time_new_from_iso8601 (const gchar *text, GTimeZone *default_tz) { - gint length, date_length = -1; + size_t length, date_length = 0; + gboolean date_length_set = FALSE; gint hour = 0, minute = 0; gdouble seconds = 0.0; GTimeZone *tz = NULL; @@ -1555,11 +1560,14 @@ g_date_time_new_from_iso8601 (const gchar *text, GTimeZone *default_tz) /* Count length of string and find date / time separator ('T', 't', or ' ') */ for (length = 0; text[length] != '\0'; length++) { - if (date_length < 0 && (text[length] == 'T' || text[length] == 't' || text[length] == ' ')) - date_length = length; + if (!date_length_set && (text[length] == 'T' || text[length] == 't' || text[length] == ' ')) + { + date_length = length; + date_length_set = TRUE; + } } - if (date_length < 0) + if (!date_length_set) return NULL; if (!parse_iso8601_time (text + date_length + 1, length - (date_length + 1), diff --git a/glib/gstring.c b/glib/gstring.c index 463bfecccdc38e00e2b8fd757b45a7f9db71648f..a8386e7c125a87f783a262c2b80c2c104b76178f 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -480,8 +480,9 @@ g_string_insert_len (GString *string, return string; if (len < 0) - len = strlen (val); - len_unsigned = len; + len_unsigned = strlen (val); + else + len_unsigned = len; if (pos < 0) pos_unsigned = string->len; @@ -778,10 +779,12 @@ g_string_insert_c (GString *string, g_string_maybe_expand (string, 1); if (pos < 0) - pos = string->len; + pos_unsigned = string->len; else - g_return_val_if_fail ((gsize) pos <= string->len, string); - pos_unsigned = pos; + { + pos_unsigned = pos; + g_return_val_if_fail (pos_unsigned <= string->len, string); + } /* If not just an append, move the old stuff */ if (pos_unsigned < string->len) @@ -814,6 +817,7 @@ g_string_insert_unichar (GString *string, gssize pos, gunichar wc) { + gsize pos_unsigned; gint charlen, first, i; gchar *dest; @@ -855,15 +859,18 @@ g_string_insert_unichar (GString *string, g_string_maybe_expand (string, charlen); if (pos < 0) - pos = string->len; + pos_unsigned = string->len; else - g_return_val_if_fail ((gsize) pos <= string->len, string); + { + pos_unsigned = pos; + g_return_val_if_fail (pos_unsigned <= string->len, string); + } /* If not just an append, move the old stuff */ - if ((gsize) pos < string->len) - memmove (string->str + pos + charlen, string->str + pos, string->len - pos); + if (pos_unsigned < string->len) + memmove (string->str + pos_unsigned + charlen, string->str + pos_unsigned, string->len - pos_unsigned); - dest = string->str + pos; + dest = string->str + pos_unsigned; /* Code copied from g_unichar_to_utf() */ for (i = charlen - 1; i > 0; --i) { @@ -921,6 +928,7 @@ g_string_overwrite_len (GString *string, const gchar *val, gssize len) { + gsize len_unsigned; gsize end; g_return_val_if_fail (string != NULL, NULL); @@ -932,14 +940,16 @@ g_string_overwrite_len (GString *string, g_return_val_if_fail (pos <= string->len, string); if (len < 0) - len = strlen (val); + len_unsigned = strlen (val); + else + len_unsigned = len; - end = pos + len; + end = pos + len_unsigned; if (end > string->len) g_string_maybe_expand (string, end - string->len); - memcpy (string->str + pos, val, len); + memcpy (string->str + pos, val, len_unsigned); if (end > string->len) { diff --git a/glib/tests/gdatetime.c b/glib/tests/gdatetime.c index d46f653acb4370dc73e0310cfc7112f5f2f84123..15eb81cf1edd388604d94cd5d89c5bcbd45892e4 100644 --- a/glib/tests/gdatetime.c +++ b/glib/tests/gdatetime.c @@ -866,6 +866,23 @@ test_GDateTime_new_from_iso8601 (void) * NaN */ dt = g_date_time_new_from_iso8601 ("0005306 000001,666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666600080000-00", NULL); g_assert_null (dt); + + /* Various invalid timezone offsets which look like they could be in + * `+hh:mm`, `-hh:mm`, `+hhmm`, `-hhmm`, `+hh` or `-hh` format */ + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+01:xx", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+xx:00", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+xx:xx", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+01xx", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+xx00", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+xxxx", NULL); + g_assert_null (dt); + dt = g_date_time_new_from_iso8601 ("2025-02-18T18:14:00+xx", NULL); + g_assert_null (dt); } typedef struct {