From 32acc283c8ae44d9c4e306dbaf6a9fead5e71952 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Sat, 27 Aug 2005 06:29:52 +0000 Subject: [PATCH] a few more bug fixes svn:r177 --- event.h | 1 + event_rpcgen.py | 48 +++++++++++++++++++++++++++++++++--------------- event_tagging.c | 20 ++++++++++++++++++++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/event.h b/event.h index 18e8d9da..31bcbd16 100644 --- a/event.h +++ b/event.h @@ -296,6 +296,7 @@ void evtag_test(void); int evtag_unmarshal(struct evbuffer *src, uint8_t *ptag, struct evbuffer *dst); int evtag_peek(struct evbuffer *evbuf, uint8_t *ptag); int evtag_peek_length(struct evbuffer *evbuf, uint32_t *plength); +int evtag_payload_length(struct evbuffer *evbuf, uint32_t *plength); int evtag_consume(struct evbuffer *evbuf); int evtag_unmarshal_int(struct evbuffer *evbuf, uint8_t need_tag, diff --git a/event_rpcgen.py b/event_rpcgen.py index ef98721c..7af014f5 100755 --- a/event_rpcgen.py +++ b/event_rpcgen.py @@ -260,12 +260,13 @@ class Struct: 'evtag_marshal_%s(struct evbuffer *evbuf, uint8_t tag, ' 'const struct %s *msg)\n' % (self._name, self._name) + '{\n' - ' if (_buf == NULL)\n' - ' _buf = evbuffer_new();\n' + ' struct evbuffer *_buf = evbuffer_new();\n' + ' assert(_buf != NULL);\n' ' evbuffer_drain(_buf, -1);\n' ' %s_marshal(_buf, msg);\n' % self._name + ' evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), ' 'EVBUFFER_LENGTH(_buf));\n' + ' evbuffer_free(_buf);\n' '}\n' ) class Entry: @@ -438,9 +439,13 @@ class EntryBytes(Entry): def CodeUnmarshal(self, buf, tag_name, var_name): code = [ 'if (evtag_unmarshal_fixed(%s, %s, ' % (buf, tag_name) + '%s->%s_data, ' % (var_name, self._name) + - 'sizeof(%s->%s_data)) == -1)' % ( + 'sizeof(%s->%s_data)) == -1) {' % ( var_name, self._name), - ' return (-1);' ] + ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( + self._name ), + ' return (-1);', + '}' + ] return code def CodeMarshal(self, buf, tag_name, var_name): @@ -477,9 +482,12 @@ class EntryInt(Entry): self._ctype = 'uint32_t' def CodeUnmarshal(self, buf, tag_name, var_name): - code = ['if (evtag_unmarshal_int(%s, %s, &%s->%s_data) == -1)' % ( + code = ['if (evtag_unmarshal_int(%s, %s, &%s->%s_data) == -1) {' % ( buf, tag_name, var_name, self._name), - ' return (-1);'] + ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( + self._name ), + ' return (-1);', + '}' ] return code def CodeMarshal(self, buf, tag_name, var_name): @@ -516,9 +524,13 @@ class EntryString(Entry): return code def CodeUnmarshal(self, buf, tag_name, var_name): - code = ['if (evtag_unmarshal_string(%s, %s, &%s->%s_data) == -1)' % ( + code = ['if (evtag_unmarshal_string(%s, %s, &%s->%s_data) == -1) {' % ( buf, tag_name, var_name, self._name), - ' return (-1);'] + ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( + self._name ), + ' return (-1);', + '}' + ] return code def CodeMarshal(self, buf, tag_name, var_name): @@ -650,9 +662,13 @@ class EntryStruct(Entry): var_name, self._name, self._refname), 'if (%s->%s_data == NULL)' % (var_name, self._name), ' return (-1);', - 'if (evtag_unmarshal_%s(%s, %s, %s->%s_data) == -1)' % ( + 'if (evtag_unmarshal_%s(%s, %s, %s->%s_data) == -1) {' % ( self._refname, buf, tag_name, var_name, self._name), - ' return (-1);'] + ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( + self._name ), + ' return (-1);', + '}' + ] return code def CodeMarshal(self, buf, tag_name, var_name): @@ -741,16 +757,20 @@ class EntryVarBytes(Entry): return code def CodeUnmarshal(self, buf, tag_name, var_name): - code = ['if (evtag_peek_length(%s, &%s->%s_length) == -1)' % ( + code = ['if (evtag_payload_length(%s, &%s->%s_length) == -1)' % ( buf, var_name, self._name), ' return (-1);', 'if ((%s->%s_data = malloc(%s->%s_length)) == NULL)' % ( var_name, self._name, var_name, self._name), ' return (-1);', 'if (evtag_unmarshal_fixed(%s, %s, %s->%s_data, ' - '%s->%s_length) == -1)' % ( + '%s->%s_length) == -1) {' % ( buf, tag_name, var_name, self._name, var_name, self._name), - ' return (-1);'] + ' event_warnx("%%s: failed to unmarshal %s", __func__);' % ( + self._name ), + ' return (-1);', + '}' + ] return code def CodeMarshal(self, buf, tag_name, var_name): @@ -1058,8 +1078,6 @@ def BodyPreamble(name): pre += 'void event_errx(int eval, const char *fmt, ...);\n' pre += 'void event_warnx(const char *fmt, ...);\n\n' - pre += 'static struct evbuffer *_buf;\n\n' - return pre def main(argv): diff --git a/event_tagging.c b/event_tagging.c index 89fd4131..c8dbac16 100644 --- a/event_tagging.c +++ b/event_tagging.c @@ -209,6 +209,26 @@ evtag_peek_length(struct evbuffer *evbuf, uint32_t *plength) return (0); } +int +evtag_payload_length(struct evbuffer *evbuf, uint32_t *plength) +{ + struct evbuffer tmp; + int res; + + if (EVBUFFER_LENGTH(evbuf) < 2) + return (-1); + + tmp = *evbuf; + tmp.buffer += 1; + tmp.off -= 1; + + res = decode_int_internal(plength, &tmp, 0); + if (res == -1) + return (-1); + + return (0); +} + int evtag_consume(struct evbuffer *evbuf) { -- 2.40.0