talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 4dbe7a8759f8928986bd00a0ea635c5c18954651
parent 18b45d52267d0d418db258446fac2511088d9c5b
Author: Colin Leroy <colin@colino.net>
Date:   Tue, 17 Jun 2014 20:21:49 +0200

Make sure we don't access out of bounds of the match string.

Diffstat:
Msrc/addr_compl.c | 7++++---
Msrc/common/utils.h | 7+++++++
2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/addr_compl.c b/src/addr_compl.c @@ -191,7 +191,7 @@ static gint weight_addr_match(const address_entry* addr) if (match != NULL) { if (match == addr->name) n_weight = -4; - else if (*(match - 1) == ' ') + else if (match > addr->name && *(match - 1) == ' ') n_weight = -3; else n_weight = match - addr->name; @@ -205,7 +205,8 @@ static gint weight_addr_match(const address_entry* addr) else a_weight = match - addr->address; - if (*(match + strlen(g_completion_prefix)) == '@') + if (strlen(match) < strlen(g_completion_prefix) + && *(match + strlen(g_completion_prefix)) == '@') a_weight--; } } @@ -213,7 +214,7 @@ static gint weight_addr_match(const address_entry* addr) if (n_weight == -4 && a_weight < 0) n_weight = -5; - return a_weight < n_weight ? a_weight : n_weight; + return MIN(a_weight, n_weight); } static gint addr_comparison_func(gconstpointer a, gconstpointer b) diff --git a/src/common/utils.h b/src/common/utils.h @@ -222,6 +222,13 @@ G_STMT_END } \ } G_STMT_END +#ifndef MIN + #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef MAX + #define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + #ifdef __cplusplus extern "C" { #endif