Bug 225389

Summary: [SOUP] Wrong cookie timestamp in case of long expire time
Product: WebKit Reporter: enometh
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: aperez, berto, bugs-noreply, cgarcia, ews-watchlist, gustavo
Priority: P2    
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch aperez: review+

Description enometh 2021-05-05 02:50:24 PDT
Assume I have a cookie file cookie.txt

#HttpOnly_localhost	FALSE	/	FALSE	2682374400	prov	123	None

Which is specifies date 2055-01-01:00:00:00

When I try to access this cookie through:

  GFile *cookie_path =
    g_file_new_build_filename (dirpath, "cookies.txt", NULL);
  webkit_cookie_manager_set_persistent_storage
    (cm, g_file_peek_path (cookie_path), WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
...

gboolean
inspect_cookies(WebKitCookieManager *cm) {
  webkit_cookie_manager_get_cookies
    (cm, "http://localhost/", NULL,
     inspect_localhost_cookies_cb,
     NULL);
  return FALSE;
}



void
inspect_localhost_cookies_cb(GObject *source_object, GAsyncResult *res,
			     gpointer user_data)
{
  GError *error;
  WebKitCookieManager *cookie_manager = WEBKIT_COOKIE_MANAGER(source_object);
  error = NULL;
  GList *gl =
    webkit_cookie_manager_get_cookies_finish (cookie_manager, res, &error);
  if (error) {
    g_warning("inspect cookies cb: failed: %s", error->message ?: "");
    return;
  }

  while (gl) {
    g_assert(gl->data);
    SoupCookie *soup_cookie = gl->data;
    g_message("COOKIE ==> %s", soup_cookie_to_set_cookie_header(soup_cookie));
    gl = gl->next;
  }
}


I get a message which shows
** Message: 15:11:42.077: COOKIE ==> prov=123; expires=Fri, 01-Jan-2055 00:00:-8 GMT; path=/; domain=localhost; HttpOnly

This indicates that the seconds field now stores a negative integer.

In practice this triggers a critical in glib


#0  g_logv
    (log_domain=0x7fffed49614e "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=<optimized out>) at ../glib-2.68.0/glib/gmessages.c:1413
#1  0x00007fffed44c782 in g_log
    (log_domain=log_domain@entry=0x7fffed49614e "GLib", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7fffed498336 "%s: assertion '%s' failed") at ../glib-2.68.0/glib/gmessages.c:1451
#2  0x00007fffed44cf39 in g_return_if_fail_warning
    (log_domain=log_domain@entry=0x7fffed49614e "GLib", pretty_function=pretty_function@entry=0x7fffed4a6450 <__func__.14> "g_date_time_to_unix", expression=expression@entry=0x7fffed49702a "datetime != NULL")
    at ../glib-2.68.0/glib/gmessages.c:2883
#3  0x00007fffed42c81a in g_date_time_to_unix (datetime=0x0)
    at ../glib-2.68.0/glib/gdatetime.c:2566
#4  g_date_time_to_unix (datetime=datetime@entry=0x0)
    at ../glib-2.68.0/glib/gdatetime.c:2564
#5  0x00007ffff0d3be89 in soup_date_to_time_t (date=<optimized out>)
    at ../libsoup-2.70.0/libsoup/soup-date.c:718
#6  0x00007ffff5119e24 in WebCore::Cookie::Cookie(_SoupCookie*) ()
    at /7/gtk/webkitgtk/build.amd64/lib/libwebkit2gtk-4.0.so.37


I'm noticing this since 2.32.0. Do others see this or should i suspect another gcc bug
Comment 1 Carlos Garcia Campos 2021-05-05 04:54:59 PDT
I can reproduce with libsoup2, but it's also failing in libsoup3 in a different way. It's a WebKit bug in any case. I'll submit a patch.
Comment 2 Carlos Garcia Campos 2021-05-05 05:44:36 PDT
Created attachment 427761 [details]
Patch
Comment 3 Carlos Garcia Campos 2021-05-05 06:25:02 PDT
Committed r277014 (237330@main): <https://commits.webkit.org/237330@main>