if (!strncmp(msg, "334 ", 4)) {
gchar *response;
gchar *response64;
- gchar *challenge, *tmp;
+ gchar *challenge;
gsize challengelen;
guchar hexdigest[33];
- tmp = g_base64_decode(msg + 4, &challengelen);
- challenge = g_strndup(tmp, challengelen);
- g_free(tmp);
+ challenge = g_base64_decode_zero(msg + 4, &challengelen);
log_print(LOG_PROTOCOL, "ESMTP< [Decoded: %s]\n", challenge);
g_snprintf(buf, sizeof(buf), "%s", session->pass);
return 0;
}
+/* Returns a decoded base64 string, guaranteed to be null-terminated. */
+guchar *g_base64_decode_zero(const gchar *text, gsize *out_len)
+{
+ gchar *tmp = g_base64_decode(text, out_len);
+ gchar *out = g_strndup(tmp, *out_len);
+
+ g_free(tmp);
+
+ return out;
+}
+
#if !GLIB_CHECK_VERSION(2, 30, 0)
/**
* g_utf8_substring:
int cm_canonicalize_filename(const gchar *filename, gchar **canonical_name);
+guchar *g_base64_decode_zero(const gchar *text, gsize *out_len);
+
#if !GLIB_CHECK_VERSION(2, 30, 0)
gchar *g_utf8_substring (const gchar *p,
glong start_pos,
GtkWidget *face_get_from_header(const gchar *o_face)
{
gchar face[2048];
- gchar face_png[2048];
+ gchar *face_png;
gchar *tmp;
gsize pngsize;
GdkPixbuf *pixbuf;
unfold_line(face); /* strip all whitespace and linebreaks */
remove_space(face);
- tmp = g_base64_decode(face, &pngsize);
- memcpy(face_png, tmp, pngsize);
- face_png[pngsize] = '\0';
+ face_png = g_base64_decode(face, &pngsize);
debug_print("---------------------- loaded face png\n");
if (!gdk_pixbuf_loader_write (loader, face_png, pngsize, &error) ||
!gdk_pixbuf_loader_close (loader, &error)) {
g_warning("loading face failed\n");
g_object_unref(loader);
+ g_free(face_png);
return NULL;
}
+ g_free(face_png);
pixbuf = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader));
/* Save record */
fullValue = mgu_list_coalesce( listValue );
if (fullValue && last64) {
+ gchar *tmp = g_base64_decode_zero(fullValue, &len);
g_free(fullValue);
- fullValue = g_base64_decode(fullValue, &len);
+ fullValue = tmp;
}
ldif_add_value( rec, lastTag, fullValue, hashField );
fullValue =
mgu_list_coalesce( listValue );
if (fullValue && last64) {
- out = g_base64_decode(fullValue, &len);
- if (len >= 0) {
- g_free(fullValue);
- fullValue = out;
- fullValue[len] = '\0';
- } else
- g_free(out);
+ gchar *tmp = g_base64_decode_zero(fullValue, &len);
+ g_free(fullValue);
+ fullValue = tmp;
}
/* Base-64 encoded data */
/*
strv = g_strsplit(privacy_prefs, ",", 0);
for (cur = strv; *cur != NULL; cur++) {
gchar *encvalue, *tmp;
- gchar value[1024];
encvalue = strchr(*cur, '=');
if (encvalue == NULL)
encvalue[0] = '\0';
encvalue++;
- tmp = g_base64_decode(encvalue, &len);
- if (len > 0) {
- g_strlcat(value, tmp, 1024);
- value[len] = '\0';
- g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), g_strdup(value));
- }
- g_free(tmp);
+ tmp = g_base64_decode_zero(encvalue, &len);
+ if (len > 0)
+ g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), tmp);
+ else
+ g_free(tmp);
}
g_strfreev(strv);
g_free(privacy_prefs);
case P_PASSWORD:
g_free(*((gchar **)param[i].data));
if (value[0] == '!') {
- gchar *tmp, buf[1024];
+ gchar *tmp;
gsize len;
- tmp = g_base64_decode(&value[1], &len);
- g_strlcat(buf, tmp, 1024);
- g_free(tmp);
- buf[len] = '\0';
- passcrypt_decrypt(buf, len);
+ tmp = g_base64_decode_zero(&value[1], &len);
+ passcrypt_decrypt(tmp, len);
+
*((gchar **)param[i].data) =
- *buf ? g_strdup(buf) : NULL;
+ *tmp ? g_strdup(tmp) : NULL;
+ g_free(tmp);
} else {
*((gchar **)param[i].data) =
*value ? g_strdup(value) : NULL;
if (encoding == 'B') {
gchar *tmp;
tmp = g_strndup(text_begin_p + 1, eword_end_p - (text_begin_p + 1) + 1);
- decoded_text = g_base64_decode(tmp, &out_len);
+ decoded_text = g_base64_decode_zero(tmp, &out_len);
g_free(tmp);
- decoded_text[out_len] = '\0';
} else if (encoding == 'Q') {
decoded_text = g_malloc
(eword_end_p - (text_begin_p + 1) + 1);