dovecot-1.1: my_vsnprintf() implementation was broken (for old n...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Dec 3 02:24:59 EET 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/4fe0193918c6
changeset: 8030:4fe0193918c6
user: Timo Sirainen <tss at iki.fi>
date: Wed Dec 03 02:24:52 2008 +0200
description:
my_vsnprintf() implementation was broken (for old non-C99 compliant OSes)
diffstat:
1 file changed, 14 insertions(+), 3 deletions(-)
src/lib/compat.c | 17 ++++++++++++++---
diffs (36 lines):
diff -r 5bd0c1ba48af -r 4fe0193918c6 src/lib/compat.c
--- a/src/lib/compat.c Tue Dec 02 19:12:05 2008 +0200
+++ b/src/lib/compat.c Wed Dec 03 02:24:52 2008 +0200
@@ -257,8 +257,13 @@ int my_vsnprintf(char *str, size_t size,
if (tmp_size > size) {
tmp = t_buffer_get(tmp_size);
ret = vsnprintf(tmp, tmp_size, format, ap);
- if (ret >= 0 && (size_t)ret+1 != size)
+ if (ret >= 0 && (size_t)ret+1 != tmp_size) {
+ if (size > 0) {
+ memcpy(str, tmp, size-1);
+ str[size-1] = '\0';
+ }
return ret;
+ }
} else {
tmp_size = size;
}
@@ -268,9 +273,15 @@ int my_vsnprintf(char *str, size_t size,
tmp_size = nearest_power(tmp_size+1);
tmp = i_malloc(tmp_size);
ret = vsnprintf(tmp, tmp_size, format, ap);
+ if (ret >= 0 && (size_t)ret+1 != tmp_size) {
+ if (size > 0) {
+ memcpy(str, tmp, size-1);
+ str[size-1] = '\0';
+ }
+ i_free(tmp);
+ return ret;
+ }
i_free(tmp);
- if (ret >= 0 && (size_t)ret+1 != size)
- return ret;
} while (tmp_size < 1024*1024);
i_panic("my_vsnprintf(): Output string too big");
More information about the dovecot-cvs
mailing list