os_mbuf_appendfrom - Detect source mbuf overrun.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2d39d3b8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2d39d3b8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2d39d3b8 Branch: refs/heads/sterly_refactor Commit: 2d39d3b86895e341d3c43bccd1b05526b529a4a5 Parents: 229927d Author: Christopher Collins <[email protected]> Authored: Tue Aug 9 12:29:28 2016 -0700 Committer: Sterling Hughes <[email protected]> Committed: Tue Aug 9 16:05:21 2016 -0700 ---------------------------------------------------------------------- libs/os/src/os_mbuf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2d39d3b8/libs/os/src/os_mbuf.c ---------------------------------------------------------------------- diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c index eda58ef..a2302df 100644 --- a/libs/os/src/os_mbuf.c +++ b/libs/os/src/os_mbuf.c @@ -520,6 +520,10 @@ err: * @param src_off The absolute offset within the source mbuf * chain to read from. * @param len The number of bytes to append. + * + * @return 0 on success; + * OS_EINVAL if the specified range extends beyond + * the end of the source mbuf chain. */ int os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src, @@ -531,11 +535,11 @@ os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src, int rc; src_cur_om = os_mbuf_off(src, src_off, &src_cur_off); - if (src_cur_om == NULL) { - return OS_EINVAL; - } - while (len > 0) { + if (src_cur_om == NULL) { + return OS_EINVAL; + } + chunk_sz = min(len, src_cur_om->om_len - src_cur_off); rc = os_mbuf_append(dst, src_cur_om->om_data + src_cur_off, chunk_sz); if (rc != 0) {
