[glib: 10/12] gtlspassword: Forbid very long TLS passwords
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 10/12] gtlspassword: Forbid very long TLS passwords
- Date: Thu, 4 Feb 2021 17:12:38 +0000 (UTC)
commit a8b204ff9df49df5ad14005abc0ed39b1d09c408
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Feb 4 14:07:39 2021 +0000
gtlspassword: Forbid very long TLS passwords
The public API `g_tls_password_set_value_full()` (and the vfunc it
invokes) can only accept a `gssize` length. Ensure that nul-terminated
strings passed to `g_tls_password_set_value()` can’t exceed that length.
Use `g_memdup2()` to avoid an overflow if they’re longer than
`G_MAXUINT` similarly.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
Helps: #2319
gio/gtlspassword.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/gio/gtlspassword.c b/gio/gtlspassword.c
index 1e437a7b6..f5e02a1a8 100644
--- a/gio/gtlspassword.c
+++ b/gio/gtlspassword.c
@@ -287,9 +287,14 @@ g_tls_password_set_value (GTlsPassword *password,
g_return_if_fail (G_IS_TLS_PASSWORD (password));
if (length < 0)
- length = strlen ((gchar *)value);
+ {
+ /* 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);
+ length = (gssize) length_unsigned;
+ }
- g_tls_password_set_value_full (password, g_memdup (value, length), length, g_free);
+ g_tls_password_set_value_full (password, g_memdup2 (value, (gsize) length), length, g_free);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]