|
|
e5da31 |
From 4fd0162b758d97855beed09d81c77cb1a1626bd8 Mon Sep 17 00:00:00 2001
|
|
|
e5da31 |
From: Philip Withnall <pwithnall@endlessos.org>
|
|
|
e5da31 |
Date: Thu, 4 Feb 2021 14:07:39 +0000
|
|
|
e5da31 |
Subject: [PATCH 10/12] gtlspassword: Forbid very long TLS passwords
|
|
|
e5da31 |
MIME-Version: 1.0
|
|
|
e5da31 |
Content-Type: text/plain; charset=UTF-8
|
|
|
e5da31 |
Content-Transfer-Encoding: 8bit
|
|
|
e5da31 |
|
|
|
e5da31 |
The public API `g_tls_password_set_value_full()` (and the vfunc it
|
|
|
e5da31 |
invokes) can only accept a `gssize` length. Ensure that nul-terminated
|
|
|
e5da31 |
strings passed to `g_tls_password_set_value()` can’t exceed that length.
|
|
|
e5da31 |
Use `g_memdup2()` to avoid an overflow if they’re longer than
|
|
|
e5da31 |
`G_MAXUINT` similarly.
|
|
|
e5da31 |
|
|
|
e5da31 |
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
|
|
e5da31 |
Helps: #2319
|
|
|
e5da31 |
---
|
|
|
e5da31 |
gio/gtlspassword.c | 10 ++++++++--
|
|
|
e5da31 |
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
e5da31 |
|
|
|
e5da31 |
diff --git a/gio/gtlspassword.c b/gio/gtlspassword.c
|
|
|
e5da31 |
index 1e437a7b6..dbcec41a8 100644
|
|
|
e5da31 |
--- a/gio/gtlspassword.c
|
|
|
e5da31 |
+++ b/gio/gtlspassword.c
|
|
|
e5da31 |
@@ -23,6 +23,7 @@
|
|
|
e5da31 |
#include "glibintl.h"
|
|
|
e5da31 |
|
|
|
e5da31 |
#include "gioenumtypes.h"
|
|
|
e5da31 |
+#include "gstrfuncsprivate.h"
|
|
|
e5da31 |
#include "gtlspassword.h"
|
|
|
e5da31 |
|
|
|
e5da31 |
#include <string.h>
|
|
|
e5da31 |
@@ -287,9 +288,14 @@ g_tls_password_set_value (GTlsPassword *password,
|
|
|
e5da31 |
g_return_if_fail (G_IS_TLS_PASSWORD (password));
|
|
|
e5da31 |
|
|
|
e5da31 |
if (length < 0)
|
|
|
e5da31 |
- length = strlen ((gchar *)value);
|
|
|
e5da31 |
+ {
|
|
|
e5da31 |
+ /* FIXME: g_tls_password_set_value_full() doesn’t support unsigned gsize */
|
|
|
e5da31 |
+ gsize length_unsigned = strlen ((gchar *) value);
|
|
|
e5da31 |
+ g_return_if_fail (length_unsigned > G_MAXSSIZE);
|
|
|
e5da31 |
+ length = (gssize) length_unsigned;
|
|
|
e5da31 |
+ }
|
|
|
e5da31 |
|
|
|
e5da31 |
- g_tls_password_set_value_full (password, g_memdup (value, length), length, g_free);
|
|
|
e5da31 |
+ g_tls_password_set_value_full (password, g_memdup2 (value, (gsize) length), length, g_free);
|
|
|
e5da31 |
}
|
|
|
e5da31 |
|
|
|
e5da31 |
/**
|
|
|
e5da31 |
--
|
|
|
e5da31 |
2.31.1
|
|
|
e5da31 |
|