Merge branch 'mcatanzaro/#2832' into 'main'

Fix: GSocketClient cannot proxy connect unless default port is explicitly specified in proxy URL

Closes #2832

See merge request GNOME/glib!3451
This commit is contained in:
Michael Catanzaro 2023-05-30 16:50:40 +00:00
commit b7d5e4bc19
5 changed files with 31 additions and 5 deletions

View File

@ -29,6 +29,7 @@
#include "ginetaddress.h"
#include "gioerror.h"
#include "glibintl.h"
#include "glib-private.h"
#include "gnetworkaddress.h"
#include "gnetworkingprivate.h"
#include "gproxy.h"
@ -158,9 +159,13 @@ next_enumerator (GProxyAddressEnumeratorPrivate *priv)
else
{
GError *error = NULL;
int default_port;
connectable = g_network_address_parse_uri (priv->proxy_uri, 0, &error);
default_port = GLIB_PRIVATE_CALL (g_uri_get_default_scheme_port) (priv->proxy_type);
if (default_port == -1)
default_port = 0;
connectable = g_network_address_parse_uri (priv->proxy_uri, default_port, &error);
if (error)
{
g_warning ("Invalid proxy URI '%s': %s",

View File

@ -69,6 +69,8 @@ glib__private__ (void)
g_win32_pop_invalid_parameter_handler,
g_find_program_for_path,
g_uri_get_default_scheme_port,
};
return &table;

View File

@ -158,6 +158,8 @@ char *g_find_program_for_path (const char *program,
const char *path,
const char *working_dir);
int g_uri_get_default_scheme_port (const char *scheme);
#define GLIB_PRIVATE_CALL(symbol) (glib__private__()->symbol)
@ -222,6 +224,9 @@ typedef struct {
const char *path,
const char *working_dir);
/* See guri.c */
int (* g_uri_get_default_scheme_port) (const char *scheme);
/* Add other private functions here, initialize them in glib-private.c */
} GLibPrivateVTable;

View File

@ -25,6 +25,7 @@
#include "glib.h"
#include "glibintl.h"
#include "glib-private.h"
#include "guriprivate.h"
/**
@ -808,8 +809,8 @@ normalize_port (const char *scheme,
return port;
}
static int
default_scheme_port (const char *scheme)
int
g_uri_get_default_scheme_port (const char *scheme)
{
if (strcmp (scheme, "http") == 0 || strcmp (scheme, "ws") == 0)
return 80;
@ -820,6 +821,9 @@ default_scheme_port (const char *scheme)
if (strcmp (scheme, "ftp") == 0)
return 21;
if (strstr (scheme, "socks") == scheme)
return 1080;
return -1;
}
@ -1019,7 +1023,7 @@ g_uri_split_internal (const gchar *uri_string,
}
if (port && *port == -1)
*port = default_scheme_port (scheme_str);
*port = g_uri_get_default_scheme_port (scheme_str);
}
g_free (normalized_scheme);
@ -2507,7 +2511,7 @@ g_uri_get_port (GUri *uri)
g_return_val_if_fail (uri != NULL, -1);
if (uri->port == -1 && uri->flags & G_URI_FLAGS_SCHEME_NORMALIZE)
return default_scheme_port (uri->scheme);
return g_uri_get_default_scheme_port (uri->scheme);
return uri->port;
}

View File

@ -1912,6 +1912,16 @@ static const struct
"ftp", "", 21 },
{ "scheme://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"scheme", "", -1 },
{ "socks://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"socks", "", 1080 },
{ "socks4://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"socks4", "", 1080 },
{ "socks4a://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"socks4a", "", 1080 },
{ "socks5://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"socks5", "", 1080 },
{ "socks5h://foo", G_URI_FLAGS_SCHEME_NORMALIZE,
"socks5h", "", 1080 },
};
static const struct