Commit 00b181fa authored by Sebastian Dröge's avatar Sebastian Dröge 🍵
Browse files

Merge branch 'wip/issue2323-2-66' into 'glib-2-66'

[2.66] Fix regressions in 2.66.6 where negative gssize indicates strlen()

See merge request !1933
parents d5ec4f36 3d155035
Pipeline #254510 passed with stages
in 9 minutes and 15 seconds
......@@ -291,7 +291,7 @@ g_tls_password_set_value (GTlsPassword *password,
{
/* FIXME: g_tls_password_set_value_full() doesn’t support unsigned gsize */
gsize length_unsigned = strlen ((gchar *) value);
g_return_if_fail (length_unsigned > G_MAXSSIZE);
g_return_if_fail (length_unsigned <= G_MAXSSIZE);
length = (gssize) length_unsigned;
}
......
......@@ -174,6 +174,38 @@ test_interaction_ask_password_finish_failure (GTlsInteraction *interaction,
}
/* Return a copy of @str that is allocated in a silly way, to exercise
* custom free-functions. The returned pointer points to a copy of @str
* in a buffer of the form "BEFORE \0 str \0 AFTER". */
static guchar *
special_dup (const char *str)
{
GString *buf = g_string_new ("BEFORE");
guchar *ret;
g_string_append_c (buf, '\0');
g_string_append (buf, str);
g_string_append_c (buf, '\0');
g_string_append (buf, "AFTER");
ret = (guchar *) g_string_free (buf, FALSE);
return ret + strlen ("BEFORE") + 1;
}
/* Free a copy of @str that was made with special_dup(), after asserting
* that it has not been corrupted. */
static void
special_free (gpointer p)
{
gchar *s = p;
gchar *buf = s - strlen ("BEFORE") - 1;
g_assert_cmpstr (buf, ==, "BEFORE");
g_assert_cmpstr (s + strlen (s) + 1, ==, "AFTER");
g_free (buf);
}
static GTlsInteractionResult
test_interaction_ask_password_sync_success (GTlsInteraction *interaction,
GTlsPassword *password,
......@@ -181,6 +213,8 @@ test_interaction_ask_password_sync_success (GTlsInteraction *interaction,
GError **error)
{
TestInteraction *self;
const guchar *value;
gsize len;
g_assert (TEST_IS_INTERACTION (interaction));
self = TEST_INTERACTION (interaction);
......@@ -192,6 +226,27 @@ test_interaction_ask_password_sync_success (GTlsInteraction *interaction,
g_assert (error != NULL);
g_assert (*error == NULL);
/* Exercise different ways to set the value */
g_tls_password_set_value (password, (const guchar *) "foo", 4);
len = 0;
value = g_tls_password_get_value (password, &len);
g_assert_cmpmem (value, len, "foo", 4);
g_tls_password_set_value (password, (const guchar *) "bar", -1);
len = 0;
value = g_tls_password_get_value (password, &len);
g_assert_cmpmem (value, len, "bar", 3);
g_tls_password_set_value_full (password, special_dup ("baa"), 4, special_free);
len = 0;
value = g_tls_password_get_value (password, &len);
g_assert_cmpmem (value, len, "baa", 4);
g_tls_password_set_value_full (password, special_dup ("baz"), -1, special_free);
len = 0;
value = g_tls_password_get_value (password, &len);
g_assert_cmpmem (value, len, "baz", 3);
/* Don't do this in real life. Include a null terminator for testing */
g_tls_password_set_value (password, (const guchar *)"the password", 13);
return G_TLS_INTERACTION_HANDLED;
......
......@@ -900,13 +900,13 @@ g_io_channel_set_line_term (GIOChannel *channel,
{
/* FIXME: We’re constrained by line_term_len being a guint here */
gsize length_size = strlen (line_term);
g_return_if_fail (length_size > G_MAXUINT);
g_return_if_fail (length_size <= G_MAXUINT);
length_unsigned = (guint) length_size;
}
g_free (channel->line_term);
channel->line_term = line_term ? g_memdup2 (line_term, length_unsigned) : NULL;
channel->line_term_len = length;
channel->line_term_len = length_unsigned;
}
/**
......
......@@ -49,8 +49,10 @@ test_read_line_embedded_nuls (void)
channel = g_io_channel_new_file (filename, "r", &local_error);
g_assert_no_error (local_error);
/* Only break on newline characters, not nuls. */
g_io_channel_set_line_term (channel, "\n", 1);
/* Only break on newline characters, not nuls.
* Use length -1 here to exercise glib#2323; the case where length > 0
* is covered in glib/tests/protocol.c. */
g_io_channel_set_line_term (channel, "\n", -1);
g_io_channel_set_encoding (channel, NULL, &local_error);
g_assert_no_error (local_error);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment