dovecot-1.2: my_vsnprintf() implementation was broken (for old n...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Dec 3 02:25:33 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/1bb73f69b3f3
changeset: 8514:1bb73f69b3f3
user: Timo Sirainen <tss at iki.fi>
date: Wed Dec 03 02:25:11 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 0691f5294bb9 -r 1bb73f69b3f3 src/lib/compat.c
--- a/src/lib/compat.c Tue Dec 02 19:24:57 2008 +0200
+++ b/src/lib/compat.c Wed Dec 03 02:25:11 2008 +0200
@@ -258,8 +258,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;
}
@@ -269,9 +274,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