summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2019-09-24 08:19:18 +0000
committerDaiki Ueno <ueno@gnu.org>2019-09-24 08:19:18 +0000
commitf609501e986809a5d1a7f0450e9d82144e04da17 (patch)
tree5dab00288f4e58057a5e18382974369f17f15dbf
parentbb7336cf262acaefe2c462ce052ecf14739d15de (diff)
parentbf04c45535dc9fae80d3beead16fcd760989b44e (diff)
downloadgnome-keyring-f609501e986809a5d1a7f0450e9d82144e04da17.tar.gz
Merge branch 'wip/dueno/ubsan' into 'master'
build: Fix UB spotted by UBSan See merge request GNOME/gnome-keyring!24
-rw-r--r--egg/egg-asn1x.c14
-rw-r--r--egg/egg-buffer.c2
-rw-r--r--pkcs11/gkm/gkm-attributes.c14
3 files changed, 16 insertions, 14 deletions
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index b2bc7614..7983b52a 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -763,7 +763,7 @@ atlv_parse_length (const guchar *at,
const guchar *end,
gint *off)
{
- gint ans, last;
+ gint ans;
gint k, punt;
gint n_data;
@@ -789,19 +789,15 @@ atlv_parse_length (const guchar *at,
if (k) {
ans = 0;
while (punt <= k && punt < n_data) {
- last = ans;
- ans = ans * 256;
-
/* we wrapped around, no bignum support... */
- if (ans < last)
+ if (ans > G_MAXINT / 256)
return -2;
-
- last = ans;
- ans += at[punt++];
+ ans = ans * 256;
/* we wrapped around, no bignum support... */
- if (ans < last)
+ if (ans > G_MAXINT - at[punt])
return -2;
+ ans += at[punt++];
}
/* indefinite length method */
diff --git a/egg/egg-buffer.c b/egg/egg-buffer.c
index fd0aca27..f20588ff 100644
--- a/egg/egg-buffer.c
+++ b/egg/egg-buffer.c
@@ -321,7 +321,7 @@ egg_buffer_encode_uint32 (unsigned char* buf, uint32_t val)
uint32_t
egg_buffer_decode_uint32 (unsigned char* ptr)
{
- uint32_t val = ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
+ uint32_t val = (uint32_t) ptr[0] << 24 | ptr[1] << 16 | ptr[2] << 8 | ptr[3];
return val;
}
diff --git a/pkcs11/gkm/gkm-attributes.c b/pkcs11/gkm/gkm-attributes.c
index fb185bc0..dfdd08f3 100644
--- a/pkcs11/gkm/gkm-attributes.c
+++ b/pkcs11/gkm/gkm-attributes.c
@@ -518,8 +518,11 @@ gkm_attributes_find_boolean (CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, CK_ATTRIB
if (attr->ulValueLen != sizeof (CK_BBOOL))
return FALSE;
- if (value != NULL)
- *value = *((CK_BBOOL*)attr->pValue) == CK_TRUE ? TRUE : FALSE;
+ if (value != NULL) {
+ CK_BBOOL bbool;
+ memcpy (&bbool, attr->pValue, sizeof (CK_BBOOL));
+ *value = bbool == CK_TRUE ? TRUE : FALSE;
+ }
return TRUE;
}
@@ -538,8 +541,11 @@ gkm_attributes_find_ulong (CK_ATTRIBUTE_PTR attrs, CK_ULONG n_attrs, CK_ATTRIBUT
if (attr->ulValueLen != sizeof (CK_ULONG))
return FALSE;
- if (value != NULL)
- *value = *((CK_ULONG*)attr->pValue);
+ if (value != NULL) {
+ CK_ULONG ulong;
+ memcpy (&ulong, attr->pValue, sizeof (CK_ULONG));
+ *value = ulong;
+ }
return TRUE;
}