From: Kefu Chai Date: Tue, 7 Jun 2016 03:20:06 +0000 (+0800) Subject: buffer: fix advance(unsigned) to avoid int underflow X-Git-Tag: v11.0.0~224^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=053bfa650ba1d656dfb20e389ef25afc4c383bb3;p=ceph.git buffer: fix advance(unsigned) to avoid int underflow by chaning - the signature of advance(unsigned) to advance(size_t) - the signature of seek(int) to seek(ssize_t) Fixes: http://tracker.ceph.com/issues/16010 Signed-off-by: Kefu Chai --- diff --git a/src/common/buffer.cc b/src/common/buffer.cc index be6fa65eda5d..19b4cd2ef7c6 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -1041,7 +1041,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; : iterator_impl(i.bl, i.off, i.p, i.p_off) {} template - void buffer::list::iterator_impl::advance(int o) + void buffer::list::iterator_impl::advance(ssize_t o) { //cout << this << " advance " << o << " from " << off << " (p_off " << p_off << " in " << p->length() << ")" << std::endl; if (o > 0) { @@ -1080,7 +1080,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; } template - void buffer::list::iterator_impl::seek(unsigned o) + void buffer::list::iterator_impl::seek(size_t o) { p = ls->begin(); off = p_off = 0; @@ -1247,12 +1247,12 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; : iterator_impl(l, o, ip, po) {} - void buffer::list::iterator::advance(int o) + void buffer::list::iterator::advance(ssize_t o) { buffer::list::iterator_impl::advance(o); } - void buffer::list::iterator::seek(unsigned o) + void buffer::list::iterator::seek(size_t o) { buffer::list::iterator_impl::seek(o); } diff --git a/src/include/buffer.h b/src/include/buffer.h index 999857323786..49fd999ee6df 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -308,8 +308,8 @@ namespace buffer CEPH_BUFFER_API { //return off == bl->length(); } - void advance(int o); - void seek(unsigned o); + void advance(ssize_t o); + void seek(size_t o); char operator*() const; iterator_impl& operator++(); ptr get_current_ptr() const; @@ -351,8 +351,8 @@ namespace buffer CEPH_BUFFER_API { iterator(bl_t *l, unsigned o=0); iterator(bl_t *l, unsigned o, list_iter_t ip, unsigned po); - void advance(int o); - void seek(unsigned o); + void advance(ssize_t o); + void seek(size_t o); char operator*(); iterator& operator++(); ptr get_current_ptr();