chiark / gitweb /
integer and buffer overflows: introduce a number of asserts
[secnet.git] / util.c
diff --git a/util.c b/util.c
index a795223600bbdd731e1ea36c525da8140ad49328..86a9cd82d55eddf5134b0135f996ac90af922159 100644 (file)
--- a/util.c
+++ b/util.c
@@ -198,12 +198,17 @@ bool_t remove_hook(uint32_t phase, hook_fn *fn, void *state)
     return False;
 }
 
-void log(struct log_if *lf, int priority, const char *message, ...)
+void vslilog(struct log_if *lf, int priority, const char *message, va_list ap)
+{
+    lf->vlog(lf->st,priority,message,ap);
+}
+
+void slilog(struct log_if *lf, int priority, const char *message, ...)
 {
     va_list ap;
     
     va_start(ap,message);
-    lf->vlog(lf->st,priority,message,ap);
+    vslilog(lf,priority,message,ap);
     va_end(ap);
 }
 
@@ -238,12 +243,14 @@ void buffer_init(struct buffer_if *buffer, uint32_t max_start_pad)
 
 void *buf_append(struct buffer_if *buf, uint32_t amount) {
     void *p;
+    assert(buf->size <= buf->len - amount);
     p=buf->start + buf->size;
     buf->size+=amount;
     return p;
 }
 
 void *buf_prepend(struct buffer_if *buf, uint32_t amount) {
+    assert(amount <= buf->start - buf->base);
     buf->size+=amount;
     return buf->start-=amount;
 }
@@ -268,6 +275,7 @@ void buf_append_string(struct buffer_if *buf, cstring_t s)
     uint16_t len;
 
     len=strlen(s);
+    /* fixme: if string is longer than 65535, result is a corrupted packet */
     buf_append_uint16(buf,len);
     memcpy(buf_append(buf,len),s,len);
 }
@@ -335,7 +343,6 @@ static list_t *buffer_apply(closure_t *self, struct cloc loc, dict_t *context,
     return new_closure(&st->cl);
 }
 
-init_module util_module;
 void util_module(dict_t *dict)
 {
     add_closure(dict,"sysbuffer",buffer_apply);