From 567d0ddc0692adfef5f15d0d383825a9b2ea4b49 Mon Sep 17 00:00:00 2001
From: Stefan Becker <chemobejk@gmail.com>
Date: Thu, 25 Mar 2021 16:54:18 +0200
Subject: [PATCH 1/3] utils: add sipe_utils_memdup()
Glib >= 2.68 deprecates g_memdup(). Add a simple wrapper that calls
g_memedup2() instead.
---
src/core/sipe-utils.c | 13 ++++++++++++-
src/core/sipe-utils.h | 10 +++++++++-
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/core/sipe-utils.c b/src/core/sipe-utils.c
index 12ff8d68..3a27e3c6 100644
--- a/src/core/sipe-utils.c
+++ b/src/core/sipe-utils.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2009-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2009-2021 SIPE Project <http://sipe.sourceforge.net/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -277,6 +277,17 @@ is_empty(const char *st)
return FALSE;
}
+gpointer sipe_utils_memdup(gconstpointer mem, guint byte_size)
+{
+ return
+#if GLIB_CHECK_VERSION(2,68,0)
+ g_memdup2
+#else
+ g_memdup
+#endif
+ (mem, byte_size);
+}
+
void sipe_utils_message_debug(struct sipe_transport_connection *conn,
const gchar *type,
const gchar *header,
diff --git a/src/core/sipe-utils.h b/src/core/sipe-utils.h
index 0d408bf6..33dd1184 100644
--- a/src/core/sipe-utils.h
+++ b/src/core/sipe-utils.h
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2009-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2009-2021 SIPE Project <http://sipe.sourceforge.net/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -235,6 +235,14 @@ sipe_is_bad_alias(const char *uri,
gboolean
is_empty(const char *st);
+/**
+ * Wrapper to hide differences between g_memdup()/g_memdup2()
+ *
+ * @param mem pointer to memory to duplicate
+ * @param byte_size length of memory to duplicate
+ */
+gpointer sipe_utils_memdup(gconstpointer mem, guint byte_size);
+
/**
* Message debugging
*
--
2.30.2
From 583a734e63833f03d11798b7b0d59a17d08ae60f Mon Sep 17 00:00:00 2001
From: Stefan Becker <chemobejk@gmail.com>
Date: Thu, 25 Mar 2021 16:56:05 +0200
Subject: [PATCH 2/3] core: replace g_memdup() with sipe_utils_memdup()
---
src/core/sip-sec-gssapi.c | 8 ++++----
src/core/sip-sec-ntlm.c | 14 +++++++-------
src/core/sip-sec-tls-dsk.c | 11 ++++++-----
src/core/sipe-media.c | 6 +++---
src/core/sipe-tls-tester.c | 16 ++++++++++++++--
src/core/sipe-tls.c | 11 +++++++----
6 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/src/core/sip-sec-gssapi.c b/src/core/sip-sec-gssapi.c
index 873080f8..fedc6b9d 100644
--- a/src/core/sip-sec-gssapi.c
+++ b/src/core/sip-sec-gssapi.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2010-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2010-2021 SIPE Project <http://sipe.sourceforge.net/>
* Copyright (C) 2009 pier11 <pier11@operamail.com>
*
*
@@ -602,7 +602,7 @@ sip_sec_init_sec_context__gssapi(SipSecContext context,
out_buff->length = output_token.length;
if (out_buff->length)
- out_buff->value = g_memdup(output_token.value, output_token.length);
+ out_buff->value = sipe_utils_memdup(output_token.value, output_token.length);
else
/* Special case: empty token */
out_buff->value = (guint8 *) g_strdup("");
@@ -653,8 +653,8 @@ sip_sec_make_signature__gssapi(SipSecContext context,
return FALSE;
} else {
signature->length = output_token.length;
- signature->value = g_memdup(output_token.value,
- output_token.length);
+ signature->value = sipe_utils_memdup(output_token.value,
+ output_token.length);
gss_release_buffer(&minor, &output_token);
return TRUE;
}
diff --git a/src/core/sip-sec-ntlm.c b/src/core/sip-sec-ntlm.c
index 2e2354f8..ef896bfe 100644
--- a/src/core/sip-sec-ntlm.c
+++ b/src/core/sip-sec-ntlm.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2010-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2010-2021 SIPE Project <http://sipe.sourceforge.net/>
* Copyright (C) 2009, 2010 pier11 <pier11@operamail.com>
* Copyright (C) 2008 Novell, Inc.
* Modify 2007, Anibal Avelar <avelar@gmail.com>
@@ -951,7 +951,7 @@ sip_sec_ntlm_parse_challenge(SipSecBuffer in_buff,
/* server challenge (nonce) */
if (server_challenge) {
- *server_challenge = g_memdup(cmsg->nonce, 8);
+ *server_challenge = sipe_utils_memdup(cmsg->nonce, 8);
}
/* flags */
@@ -984,7 +984,7 @@ sip_sec_ntlm_parse_challenge(SipSecBuffer in_buff,
*target_info_len = len;
}
if (target_info) {
- *target_info = g_memdup(content, len);
+ *target_info = sipe_utils_memdup(content, len);
}
}
}
@@ -1117,13 +1117,13 @@ sip_sec_ntlm_gen_authenticate(guchar **client_sign_key,
Set ServerSigningKey to SIGNKEY(ExportedSessionKey, "Server")
*/
SIGNKEY(exported_session_key, TRUE, key);
- *client_sign_key = g_memdup(key, 16);
+ *client_sign_key = sipe_utils_memdup(key, 16);
SIGNKEY(exported_session_key, FALSE, key);
- *server_sign_key = g_memdup(key, 16);
+ *server_sign_key = sipe_utils_memdup(key, 16);
SEALKEY(neg_flags, exported_session_key, TRUE, key);
- *client_seal_key = g_memdup(key, 16);
+ *client_seal_key = sipe_utils_memdup(key, 16);
SEALKEY(neg_flags, exported_session_key, FALSE, key);
- *server_seal_key = g_memdup(key, 16);
+ *server_seal_key = sipe_utils_memdup(key, 16);
}
/* @TODO: */
diff --git a/src/core/sip-sec-tls-dsk.c b/src/core/sip-sec-tls-dsk.c
index 70433eae..7f23f2c8 100644
--- a/src/core/sip-sec-tls-dsk.c
+++ b/src/core/sip-sec-tls-dsk.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2011-2015 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2011-2021 SIPE Project <http://sipe.sourceforge.net/>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -44,6 +44,7 @@
#include "sipe-backend.h"
#include "sipe-digest.h"
#include "sipe-tls.h"
+#include "sipe-utils.h"
/* Security context for TLS-DSK */
typedef struct _context_tls_dsk {
@@ -88,10 +89,10 @@ sip_sec_init_sec_context__tls_dsk(SipSecContext context,
/* copy key pair */
ctx->algorithm = state->algorithm;
ctx->key_length = state->key_length;
- ctx->client_key = g_memdup(state->client_key,
- state->key_length);
- ctx->server_key = g_memdup(state->server_key,
- state->key_length);
+ ctx->client_key = sipe_utils_memdup(state->client_key,
+ state->key_length);
+ ctx->server_key = sipe_utils_memdup(state->server_key,
+ state->key_length);
/* extract certicate expiration time */
ctx->common.expires = sipe_tls_expires(state);
diff --git a/src/core/sipe-media.c b/src/core/sipe-media.c
index e9c4b8a8..8b05d67e 100644
--- a/src/core/sipe-media.c
+++ b/src/core/sipe-media.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2011-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2011-2021 SIPE Project <http://sipe.sourceforge.net/>
* Copyright (C) 2010 Jakub Adam <jakub.adam@ktknet.cz>
*
* This program is free software; you can redistribute it and/or modify
@@ -578,8 +578,8 @@ media_stream_to_sdpmedia(struct sipe_media_call_private *call_private,
// Set our key if encryption is enabled.
if (stream_private->encryption_key &&
encryption_policy != SIPE_ENCRYPTION_POLICY_REJECTED) {
- sdpmedia->encryption_key = g_memdup(stream_private->encryption_key,
- SIPE_SRTP_KEY_LEN);
+ sdpmedia->encryption_key = sipe_utils_memdup(stream_private->encryption_key,
+ SIPE_SRTP_KEY_LEN);
sdpmedia->encryption_key_id = stream_private->encryption_key_id;
}
diff --git a/src/core/sipe-tls-tester.c b/src/core/sipe-tls-tester.c
index e80d7154..1cdb752d 100644
--- a/src/core/sipe-tls-tester.c
+++ b/src/core/sipe-tls-tester.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2011-2019 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2011-2021 SIPE Project <http://sipe.sourceforge.net/>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -65,6 +65,7 @@
#include "sipe-cert-crypto.h"
#include "sipe-crypt.h"
#include "sipe-tls.h"
+#include "sipe-utils.h"
/*
* Stubs
@@ -94,6 +95,17 @@ void sipe_backend_debug(sipe_debug_level level,
g_free(newformat);
}
+gpointer sipe_utils_memdup(gconstpointer mem, guint byte_size)
+{
+ return
+#if GLIB_CHECK_VERSION(2,68,0)
+ g_memdup2
+#else
+ g_memdup
+#endif
+ (mem, byte_size);
+}
+
/* needed when linking against NSS */
void md4sum(const uint8_t *data, uint32_t length, uint8_t *digest);
void md4sum(SIPE_UNUSED_PARAMETER const uint8_t *data,
@@ -155,7 +167,7 @@ static guchar *read_tls_record(int fd,
printf("received %d bytes from server\n", result);
record = g_new0(struct record, 1);
record->length = result;
- record->msg = g_memdup(buffer, result);
+ record->msg = sipe_utils_memdup(buffer, result);
length += result;
fragments = g_slist_append(fragments, record);
}
diff --git a/src/core/sipe-tls.c b/src/core/sipe-tls.c
index b0235d50..57f45af5 100644
--- a/src/core/sipe-tls.c
+++ b/src/core/sipe-tls.c
@@ -3,7 +3,7 @@
*
* pidgin-sipe
*
- * Copyright (C) 2011-2016 SIPE Project <http://sipe.sourceforge.net/>
+ * Copyright (C) 2011-2021 SIPE Project <http://sipe.sourceforge.net/>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -47,6 +47,9 @@
#include "sipe-digest.h"
#include "sipe-svc.h"
#include "sipe-tls.h"
+#ifndef _SIPE_COMPILING_ANALYZER
+#include "sipe-utils.h"
+#endif
/*
* Private part of TLS state tracking
@@ -427,7 +430,7 @@ static guchar *sipe_tls_prf(SIPE_UNUSED_PARAMETER struct tls_internal_state *sta
gsize half = (secret_length + 1) / 2;
gsize newseed_length = label_length + seed_length;
/* secret: used as S1; secret2: last half of original secret (S2) */
- guchar *secret2 = g_memdup(secret + secret_length - half, half);
+ guchar *secret2 = sipe_utils_memdup(secret + secret_length - half, half);
guchar *newseed = g_malloc(newseed_length);
guchar *md5, *dest;
guchar *sha1, *src;
@@ -1525,8 +1528,8 @@ static struct tls_compiled_message *tls_client_key_exchange(struct tls_internal_
/* found all the required fields */
state->server_random.length = server_random->length;
- state->server_random.buffer = g_memdup(server_random->data,
- server_random->length);
+ state->server_random.buffer = sipe_utils_memdup(server_random->data,
+ server_random->length);
tls_calculate_secrets(state);
/* ClientKeyExchange */
--
2.30.2