From: Sage Weil Date: Thu, 2 Feb 2012 01:11:29 +0000 (-0800) Subject: encoding: better DECODE_START_LEGACY_COMPAT_LEN X-Git-Tag: v0.44~93^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8623c64d0bfb8eaf685b733f6b7d8ffeb5d7cbfb;p=ceph.git encoding: better DECODE_START_LEGACY_COMPAT_LEN - let you specify whether to decode compat and/or len - put the argument order in the macro name so you know when you get it wrong This is useful for FileJournal::header_t. Signed-off-by: Sage Weil --- diff --git a/src/include/encoding.h b/src/include/encoding.h index 123a8d310b69..36fc040fbaba 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -669,25 +669,31 @@ inline void decode(std::deque& ls, bufferlist::iterator& p) throw buffer::malformed_input(DECODE_ERR_VERSION(__PRETTY_FUNCTION__, v)); \ __u32 struct_len; \ ::decode(struct_len, bl); \ + if (struct_len > bl.get_remaining()) \ + throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \ unsigned struct_end = bl.get_off() + struct_len; \ do { -#define DECODE_START_LEGACY(v, lencompat, bl) \ +#define DECODE_START_LEGACY_COMPAT_LEN(v, compatv, lenv, bl) \ __u8 struct_v; \ ::decode(struct_v, bl); \ - unsigned struct_end = 0; \ - if (struct_v >= lencompat) { \ + if (struct_v >= compatv) { \ __u8 struct_compat; \ ::decode(struct_compat, bl); \ - if (v < struct_compat) \ + if (v < struct_compat) \ throw buffer::malformed_input(DECODE_ERR_VERSION(__PRETTY_FUNCTION__, v)); \ + } \ + unsigned struct_end = 0; \ + if (struct_v >= lenv) { \ __u32 struct_len; \ ::decode(struct_len, bl); \ + if (struct_len > bl.get_remaining()) \ + throw buffer::malformed_input(DECODE_ERR_PAST(__PRETTY_FUNCTION__)); \ struct_end = bl.get_off() + struct_len; \ } \ do { -#define DECODE_FINISH(bl) \ +#define DECODE_FINISH(bl) \ } while (false); \ if (struct_end) { \ if (bl.get_off() > struct_end) \