[gcr] Fix bugs and unused code highlighted by the clang static analyzer
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcr] Fix bugs and unused code highlighted by the clang static analyzer
- Date: Mon, 21 Nov 2011 11:14:25 +0000 (UTC)
commit bed72254b9dda55e6a6412b4313ae9452eea0fc3
Author: Stef Walter <stefw collabora co uk>
Date: Mon Nov 21 12:14:02 2011 +0100
Fix bugs and unused code highlighted by the clang static analyzer
.gitignore | 1 +
egg/egg-armor.c | 4 +-
egg/egg-asn1x.c | 3 +-
egg/egg-symkey.c | 1 -
gck/gck-enumerator.c | 1 -
gcr/gcr-certificate-renderer.c | 5 +-
gcr/gcr-gnupg-key.c | 91 +---------------------------------------
gcr/gcr-gnupg-records.c | 1 -
gcr/gcr-gnupg-renderer.c | 2 +-
gcr/gcr-parser.c | 3 -
10 files changed, 9 insertions(+), 103 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ee49192..4e4d3c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,6 +18,7 @@ frob-*
*.lo
*.mo
*.o
+*.plist
*.pot
*.stamp
*.tar.gz
diff --git a/egg/egg-armor.c b/egg/egg-armor.c
index b82730b..473e42e 100644
--- a/egg/egg-armor.c
+++ b/egg/egg-armor.c
@@ -162,14 +162,14 @@ armor_find_end (const gchar *data,
/* Next comes the type string */
stype = g_quark_to_string (type);
n_type = strlen (stype);
- if (strncmp ((gchar*)data, stype, n_type) != 0)
+ if (n_type > n_data || strncmp ((gchar*)data, stype, n_type) != 0)
return NULL;
n_data -= n_type;
data += n_type;
/* Next comes the suffix */
- if (strncmp ((gchar*)data, ARMOR_SUFF, ARMOR_SUFF_L) != 0)
+ if (ARMOR_SUFF_L > n_data && strncmp ((gchar*)data, ARMOR_SUFF, ARMOR_SUFF_L) != 0)
return NULL;
/*
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 1f2eda2..a6ed2ee 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -2401,7 +2401,6 @@ anode_write_oid (const gchar *oid, guchar *data, gsize *n_data)
gboolean had;
gint i, k, at;
- p = oid;
at = 0;
num1 = 0;
@@ -3686,7 +3685,7 @@ anode_validate_sequence_or_set_of (GNode *node,
tag = 0;
count = 0;
- tlv = ptlv = NULL;
+ ptlv = NULL;
type = anode_def_type (node);
diff --git a/egg/egg-symkey.c b/egg/egg-symkey.c
index 71c1573..50f147b 100644
--- a/egg/egg-symkey.c
+++ b/egg/egg-symkey.c
@@ -370,7 +370,6 @@ generate_pkcs12 (int hash_algo, int type, const gchar *utf8_password,
}
} else {
memset (p, 0, 64);
- p += 64;
}
/* Hash and bash */
diff --git a/gck/gck-enumerator.c b/gck/gck-enumerator.c
index 933c344..59d1b7b 100644
--- a/gck/gck-enumerator.c
+++ b/gck/gck-enumerator.c
@@ -531,7 +531,6 @@ state_attributes (GckEnumeratorState *args,
g_free (string);
}
result->attrs = attrs;
- rv = CKR_OK;
} else {
g_message ("couldn't retrieve attributes when enumerating: %s",
diff --git a/gcr/gcr-certificate-renderer.c b/gcr/gcr-certificate-renderer.c
index a350d3e..ebceda3 100644
--- a/gcr/gcr-certificate-renderer.c
+++ b/gcr/gcr-certificate-renderer.c
@@ -736,10 +736,11 @@ gcr_certificate_renderer_render (GcrRenderer *renderer, GcrViewer *viewer)
value = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "tbsCertificate",
"subjectPublicKeyInfo", NULL));
- raw = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (bytes),
- egg_bytes_get_size (bytes),
+ raw = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (value),
+ egg_bytes_get_size (value),
G_CHECKSUM_SHA1, &n_raw);
_gcr_display_view_append_hex (view, renderer, _("Key SHA1 Fingerprint"), raw, n_raw);
+ egg_bytes_unref (value);
g_free (raw);
value = egg_asn1x_get_bits_as_raw (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo",
diff --git a/gcr/gcr-gnupg-key.c b/gcr/gcr-gnupg-key.c
index 908261a..b6dc271 100644
--- a/gcr/gcr-gnupg-key.c
+++ b/gcr/gcr-gnupg-key.c
@@ -50,95 +50,6 @@ struct _GcrGnupgKeyPrivate {
G_DEFINE_TYPE (GcrGnupgKey, _gcr_gnupg_key, G_TYPE_OBJECT);
-/* -----------------------------------------------------------------------------
- * INTERNAL
- */
-
-/* Copied from GPGME */
-static void
-parse_user_id (const gchar *uid, gchar **name, gchar **email, gchar **comment)
-{
- gchar *src, *tail, *x;
- int in_name = 0;
- int in_email = 0;
- int in_comment = 0;
-
- *name = NULL;
- *email = NULL;
- *comment = NULL;
-
- x = tail = src = g_strdup (uid);
-
- while (*src) {
- if (in_email) {
- /* Not legal but anyway. */
- if (*src == '<')
- in_email++;
- else if (*src == '>') {
- if (!--in_email && !*email) {
- *email = tail;
- *src = 0;
- tail = src + 1;
- }
- }
- } else if (in_comment) {
- if (*src == '(')
- in_comment++;
- else if (*src == ')') {
- if (!--in_comment && !*comment) {
- *comment = tail;
- *src = 0;
- tail = src + 1;
- }
- }
- } else if (*src == '<') {
- if (in_name) {
- if (!*name) {
- *name = tail;
- *src = 0;
- tail = src + 1;
- }
- in_name = 0;
- } else
- tail = src + 1;
-
- in_email = 1;
- } else if (*src == '(') {
- if (in_name) {
- if (!*name) {
- *name = tail;
- *src = 0;
- tail = src + 1;
- }
- in_name = 0;
- }
- in_comment = 1;
- } else if (!in_name && *src != ' ' && *src != '\t') {
- in_name = 1;
- }
- src++;
- }
-
- if (in_name) {
- if (!*name) {
- *name = tail;
- *src = 0;
- tail = src + 1;
- }
- }
-
- /* Let unused parts point to an EOS. */
- *name = g_strdup (*name ? *name : "");
- *email = g_strdup (*email ? *email : "");
- *comment = g_strdup (*comment ? *comment : "");
-
- g_strstrip (*name);
- g_strstrip (*email);
- g_strstrip (*comment);
-
- g_free (x);
-}
-
static gchar *
calculate_name (GcrGnupgKey *self)
{
@@ -160,7 +71,7 @@ calculate_markup (GcrGnupgKey *self)
if (uid == NULL)
return NULL;
- parse_user_id (uid, &name, &email, &comment);
+ _gcr_gnupg_records_parse_user_id (uid, &name, &email, &comment);
if (comment != NULL && comment[0] != '\0')
markup = g_markup_printf_escaped ("%s\n<small>%s \'%s\'</small>", name, email, comment);
else
diff --git a/gcr/gcr-gnupg-records.c b/gcr/gcr-gnupg-records.c
index e634b1f..2e3be1a 100644
--- a/gcr/gcr-gnupg-records.c
+++ b/gcr/gcr-gnupg-records.c
@@ -101,7 +101,6 @@ _gcr_gnupg_records_parse_user_id (const gchar *user_id,
if (!name) {
name = tail;
*src = 0;
- tail = src + 1;
}
}
diff --git a/gcr/gcr-gnupg-renderer.c b/gcr/gcr-gnupg-renderer.c
index 663e32c..f3d6da9 100644
--- a/gcr/gcr-gnupg-renderer.c
+++ b/gcr/gcr-gnupg-renderer.c
@@ -66,7 +66,7 @@ static gchar *
calculate_label (GcrGnupgRenderer *self)
{
gchar *userid;
- gchar *label;
+ gchar *label = NULL;
if (self->pv->attrs) {
if (gck_attributes_find_string (self->pv->attrs, CKA_LABEL, &label))
diff --git a/gcr/gcr-parser.c b/gcr/gcr-parser.c
index 0ef9216..e7455d3 100644
--- a/gcr/gcr-parser.c
+++ b/gcr/gcr-parser.c
@@ -871,8 +871,6 @@ handle_pkcs7_signed_data (GcrParser *self,
if (!asn)
goto done;
- ret = GCR_ERROR_FAILURE;
-
for (i = 0; TRUE; ++i) {
node = egg_asn1x_node (asn, "certificates", i + 1, NULL);
@@ -1624,7 +1622,6 @@ handle_encrypted_pem (GcrParser *self,
return GCR_ERROR_FAILURE;
}
- res = GCR_ERROR_FAILURE;
for (;;) {
res = enum_next_password (self, &pstate, &password);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]