[dovecot-cvs]
dovecot/src/lib buffer.c,1.8,1.9 buffer.h,1.4,1.5 str.c,1.8,1.9
cras at procontrol.fi
cras at procontrol.fi
Thu May 15 23:22:24 EEST 2003
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv28191/lib
Modified Files:
buffer.c buffer.h str.c
Log Message:
Renamed buffer_*_space() to buffer_*_space_unsafe() and added several
warnings about using them. Fixed their usage in a few places in sources
where they could have produced invalid results (no buffer overflows,
luckily).
Index: buffer.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- buffer.c 10 Jan 2003 20:58:28 -0000 1.8
+++ buffer.c 15 May 2003 19:22:22 -0000 1.9
@@ -311,7 +311,7 @@
src, src_pos, copy_size);
}
-void *buffer_get_space(buffer_t *buf, size_t pos, size_t size)
+void *buffer_get_space_unsafe(buffer_t *buf, size_t pos, size_t size)
{
if (!buffer_check_write(buf, &pos, &size, FALSE))
return NULL;
@@ -319,9 +319,9 @@
return buf->w_buffer + pos;
}
-void *buffer_append_space(buffer_t *buf, size_t size)
+void *buffer_append_space_unsafe(buffer_t *buf, size_t size)
{
- return buffer_get_space(buf, buf->used - buf->start_pos, size);
+ return buffer_get_space_unsafe(buf, buf->used - buf->start_pos, size);
}
const void *buffer_get_data(const buffer_t *buf, size_t *used_size)
Index: buffer.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/buffer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- buffer.h 5 Jan 2003 13:09:51 -0000 1.4
+++ buffer.h 15 May 2003 19:22:22 -0000 1.5
@@ -1,6 +1,11 @@
#ifndef __BUFFER_H
#define __BUFFER_H
+/* WARNING: Be careful with functions that return pointers to data.
+ With dynamic buffers they are valid only as long as buffer is not
+ realloc()ed. You shouldn't rely on it being valid if you have modified
+ buffer in any way. */
+
/* Create a static sized buffer. Writes past this size will simply not
succeed. */
buffer_t *buffer_create_static(pool_t pool, size_t size);
@@ -47,17 +52,19 @@
size_t src_pos, size_t copy_size);
/* Returns pointer to specified position in buffer, or NULL if there's not
- enough space. */
-void *buffer_get_space(buffer_t *buf, size_t pos, size_t size);
+ enough space. WARNING: The returned address may become invalid if you add
+ more data to buffer. */
+void *buffer_get_space_unsafe(buffer_t *buf, size_t pos, size_t size);
/* Increase the buffer usage by given size, and return a pointer to beginning
of it, or NULL if there's not enough space in buffer. */
-void *buffer_append_space(buffer_t *buf, size_t size);
+void *buffer_append_space_unsafe(buffer_t *buf, size_t size);
/* Returns pointer to beginning of buffer data. Current used size of buffer is
stored in used_size if it's non-NULL. */
const void *buffer_get_data(const buffer_t *buf, size_t *used_size);
/* Like buffer_get_data(), but don't return it as const. Returns NULL if the
- buffer is non-modifyable. */
+ buffer is non-modifyable. WARNING: The returned address may become invalid
+ if you add more data to buffer. */
void *buffer_get_modifyable_data(const buffer_t *buf, size_t *used_size);
/* Set the "used size" of buffer, ie. 0 would set the buffer empty.
Index: str.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/str.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- str.c 21 Jan 2003 06:45:51 -0000 1.8
+++ str.c 15 May 2003 19:22:22 -0000 1.9
@@ -143,7 +143,7 @@
fmt = printf_string_fix_format(fmt);
append_len = printf_string_upper_bound(fmt, args);
- buf = buffer_append_space(str, append_len);
+ buf = buffer_append_space_unsafe(str, append_len);
#ifdef HAVE_VSNPRINTF
ret = vsnprintf(buf, append_len, fmt, args2);
More information about the dovecot-cvs
mailing list