[gnome-keyring/dbus-api] Parse, but don't use non-utf8 secrets in keyrings.
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-keyring/dbus-api] Parse, but don't use non-utf8 secrets in keyrings.
- Date: Tue, 21 Jul 2009 00:35:41 +0000 (UTC)
commit 0c691b4570e726835af4b742aa41137fa5b74562
Author: Stef Walter <stef memberwebs com>
Date: Mon Jul 13 17:13:40 2009 +0000
Parse, but don't use non-utf8 secrets in keyrings.
This is a change for future backwards compatibility.
daemon/keyrings/gkr-keyring-binary.c | 13 +++++++++++--
egg/egg-buffer.c | 4 ++--
library/gnome-keyring-proto.c | 19 +++++++++++++++++++
library/gnome-keyring-proto.h | 5 +++++
4 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/daemon/keyrings/gkr-keyring-binary.c b/daemon/keyrings/gkr-keyring-binary.c
index 8fe3401..7d12e8a 100644
--- a/daemon/keyrings/gkr-keyring-binary.c
+++ b/daemon/keyrings/gkr-keyring-binary.c
@@ -434,6 +434,7 @@ gkr_keyring_binary_parse (GkrKeyring *keyring, EggBuffer *buffer)
guint32 lock_timeout;
time_t mtime, ctime;
char *display_name;
+ gsize n_secret;
int i, j;
guint32 tmp;
guint32 num_items;
@@ -547,10 +548,18 @@ gkr_keyring_binary_parse (GkrKeyring *keyring, EggBuffer *buffer)
&items[i].display_name)) {
goto bail;
}
- if (!gkr_proto_get_utf8_secret (buffer, offset, &offset,
- &items[i].secret)) {
+ if (!gkr_proto_get_raw_secret (buffer, offset, &offset,
+ (guchar**)(&items[i].secret), &n_secret)) {
goto bail;
}
+ /* We don't support binary secrets yet, skip */
+ if (!g_utf8_validate ((gchar*)items[i].secret, n_secret, NULL)) {
+ g_message ("discarding item with unsupported non-textual secret: %s",
+ items[i].display_name);
+ free (items[i].display_name);
+ free (items[i].secret);
+ continue;
+ }
if (!gkr_proto_get_time (buffer, offset, &offset,
&items[i].ctime)) {
goto bail;
diff --git a/egg/egg-buffer.c b/egg/egg-buffer.c
index cf90e69..16eb12f 100644
--- a/egg/egg-buffer.c
+++ b/egg/egg-buffer.c
@@ -405,8 +405,8 @@ egg_buffer_add_byte_array_empty (EggBuffer *buffer, size_t vlen)
int
egg_buffer_get_byte_array (EggBuffer *buffer, size_t offset,
- size_t *next_offset, const unsigned char **val,
- size_t *vlen)
+ size_t *next_offset, const unsigned char **val,
+ size_t *vlen)
{
uint32_t len;
if (!egg_buffer_get_uint32 (buffer, offset, &offset, &len))
diff --git a/library/gnome-keyring-proto.c b/library/gnome-keyring-proto.c
index fd68d9c..c39671b 100644
--- a/library/gnome-keyring-proto.c
+++ b/library/gnome-keyring-proto.c
@@ -112,6 +112,25 @@ gkr_proto_get_bytes (EggBuffer *buffer, gsize offset, gsize *next_offset,
}
gboolean
+gkr_proto_get_raw_secret (EggBuffer *buffer, gsize offset, gsize *next_offset,
+ guchar **secret, gsize *n_secret)
+{
+ const guchar* ptr;
+ if (!egg_buffer_get_byte_array (buffer, offset, next_offset, &ptr, n_secret))
+ return FALSE;
+
+ if (ptr == NULL || *n_secret == 0) {
+ *secret = NULL;
+ *n_secret = 0;
+ return TRUE;
+ }
+
+ *secret = egg_secure_alloc (*n_secret);
+ memcpy (*secret, ptr, *n_secret);
+ return TRUE;
+}
+
+gboolean
gkr_proto_get_utf8_string (EggBuffer *buffer, gsize offset, gsize *next_offset,
char **str_ret)
{
diff --git a/library/gnome-keyring-proto.h b/library/gnome-keyring-proto.h
index c0283e1..aea9fd6 100644
--- a/library/gnome-keyring-proto.h
+++ b/library/gnome-keyring-proto.h
@@ -71,6 +71,11 @@ gboolean gkr_proto_get_utf8_secret (EggBuffer
gsize offset,
gsize *next_offset,
char **str_ret);
+gboolean gkr_proto_get_raw_secret (EggBuffer *buffer,
+ gsize offset,
+ gsize *next_offset,
+ guchar **secret,
+ gsize *n_secret);
gboolean gkr_proto_add_attribute_list (EggBuffer *buffer,
GnomeKeyringAttributeList *attributes);
gboolean gkr_proto_add_acl (EggBuffer *buffer,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]