Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 96756a588 -> b7e14d961
nmgr_uart; use os_mbuf api to null-terminate incoming data before passing it to base64_decode. 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/b7e14d96 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b7e14d96 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b7e14d96 Branch: refs/heads/develop Commit: b7e14d961f0507b422ce4ff39bf1a5bff7628f12 Parents: 96756a5 Author: Marko Kiiskila <ma...@runtime.io> Authored: Sun Oct 9 14:51:34 2016 -0700 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Sun Oct 9 14:51:34 2016 -0700 ---------------------------------------------------------------------- mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b7e14d96/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c ---------------------------------------------------------------------- diff --git a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c index c7fa34d..0cc79fb 100644 --- a/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c +++ b/mgmt/newtmgr/transport/nmgr_uart/src/nmgr_uart.c @@ -233,7 +233,21 @@ nmgr_uart_rx_pkt(struct nmgr_uart_state *nus, struct os_mbuf_pkthdr *rxm) default: goto err; } - m->om_data[m->om_len] = '\0'; /* XXXX wrong */ + + if (os_mbuf_append(m, "\0", 1)) { + /* + * Null-terminate the line for base64_decode's sake. + */ + goto err; + } + m = os_mbuf_pullup(m, rxm->omp_len); + if (!m) { + /* + * Make data contiguous for base64_decode's sake. + */ + goto err; + } + rxm = OS_MBUF_PKTHDR(m); rc = base64_decode((char *)m->om_data + 2, (char *)m->om_data + 2); if (rc < 0) { goto err;