[OTR-dev] [PATCH 9/9] Check malloc()'s return value.
Andreas Schlick
ninox+otr at posteo.net
Wed Oct 22 14:39:27 EDT 2014
---
src/message.c | 3 +++
src/privkey.c | 4 ++++
src/proto.c | 7 +++++++
3 files changed, 14 insertions(+)
diff --git a/src/message.c b/src/message.c
index 333ee0c..791e41b 100644
--- a/src/message.c
+++ b/src/message.c
@@ -759,6 +759,9 @@ static void init_respond_smp(OtrlUserState us, const OtrlMessageAppOps *ops,
combined_buf_len = 41 + context->sessionid_len + secretlen;
combined_buf = malloc(combined_buf_len);
+ if (!combined_buf) {
+ return;
+ }
combined_buf[0] = 0x01;
if (initiating) {
memmove(combined_buf + 1, our_fp, 20);
diff --git a/src/privkey.c b/src/privkey.c
index 9bba7d0..16bce1f 100644
--- a/src/privkey.c
+++ b/src/privkey.c
@@ -488,6 +488,10 @@ gcry_error_t otrl_privkey_generate_start(OtrlUserState us,
/* Allocate the working structure */
ppc = malloc(sizeof(*ppc));
+ if (!ppc) {
+ return gcry_error(GPG_ERR_ENOMEM);
+ }
+
ppc->accountname = strdup(accountname);
ppc->protocol = strdup(protocol);
ppc->privkey = NULL;
diff --git a/src/proto.c b/src/proto.c
index f560a82..b2f6a9d 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -253,6 +253,9 @@ char *otrl_proto_default_query_msg(const char *ourname, OtrlPolicy policy)
v2_supported = (policy & OTRL_POLICY_ALLOW_V2);
v3_supported = (policy & OTRL_POLICY_ALLOW_V3);
version_tag = malloc(8);
+ if (!version_tag) {
+ return NULL;
+ }
bufp = version_tag;
if (v1_supported) {
*bufp = '?';
@@ -460,6 +463,10 @@ gcry_error_t otrl_proto_instance(const char *otrmsg,
/* Decode and extract instance tag */
bufp = malloc(OTRL_B64_MAX_DECODED_SIZE(12));
+ if (!bufp) {
+ return gcry_error(GPG_ERR_ENOMEM);
+ }
+
bufp_head = bufp;
lenp = otrl_base64_decode(bufp, otrtag+9, 12);
read_int(*instance_from);
--
2.1.2
More information about the OTR-dev
mailing list