comparison src/lib/temp-string.c @ 50:d493b9cc265e HEAD

Introduced uoff_t which is the unsigned-equilevant of off_t. This was needed to be able to handle off_t overflows properly. Also changed a few unsigned int fields into uoff_t so we should now support >2G mails if uoff_t is 64bit. Also fixed several potential integer overflows.
author Timo Sirainen <tss@iki.fi>
date Tue, 27 Aug 2002 22:16:54 +0300
parents 3b1985cbc908
children 4a7ab9e94f25
comparison
equal deleted inserted replaced
49:6be018ca51ef 50:d493b9cc265e
52 static void t_string_inc(TempString *tstr, unsigned int size) 52 static void t_string_inc(TempString *tstr, unsigned int size)
53 { 53 {
54 RealTempString *rstr = (RealTempString *) tstr; 54 RealTempString *rstr = (RealTempString *) tstr;
55 char *str; 55 char *str;
56 56
57 if (rstr->len + size + 1 > rstr->alloc_size) { 57 size += rstr->len + 1;
58 rstr->alloc_size = nearest_power(rstr->len + size + 1); 58 if (size <= rstr->len || size > INT_MAX) {
59 /* overflow */
60 i_panic("t_string_inc(): Out of memory for %u bytes", size);
61 }
62
63 if (size > rstr->alloc_size) {
64 rstr->alloc_size = nearest_power(size);
59 65
60 if (!t_try_grow(rstr->str, rstr->alloc_size)) { 66 if (!t_try_grow(rstr->str, rstr->alloc_size)) {
61 str = t_malloc(rstr->alloc_size); 67 str = t_malloc(rstr->alloc_size);
62 memcpy(str, rstr->str, rstr->len+1); 68 memcpy(str, rstr->str, rstr->len+1);
63 rstr->str = str; 69 rstr->str = str;