<p>Vadim Yanitskiy <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/14973">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty/vty.c: fix vty_read(): prevent further heap-buffer overrun<br><br>After reading data from the socket, assigned to a given VTY, we<br>need to '\0'-terminate the received string. Otherwise, further<br>access to that string, stored in a heap buffer vty->buf, would<br>lead to a heap overrun.<br><br>== How to reproduce?<br><br>  $ python -c "print 'A' * 512" | telnet $HOST $PORT<br><br>  ==21264==ERROR: AddressSanitizer: heap-buffer-overflow on address<br>                                    0x6190000211e0 at pc 0x000000435d2f<br>                                 bp 0x7ffc06c7add0 sp 0x7ffc06c7a578<br>  READ of size 1025 at 0x6190000211e0 thread T0<br>    #0 0x435d2e in __interceptor_strlen (/usr/local/bin/osmo-msc+0x435d2e)<br>    #1 0x7fb95bfa5624 in talloc_strdup (/usr/lib/x86_64-linux-gnu/libtalloc.so.2+0x6624)<br>    #2 0x7fb95c1be2bc in vty_hist_add /opt/osmocom/libosmocore/src/vty/vty.c:578<br>    #3 0x7fb95c1be2bc in vty_execute /opt/osmocom/libosmocore/src/vty/vty.c:703<br>    #4 0x7fb95c1be2bc in vty_read /opt/osmocom/libosmocore/src/vty/vty.c:1425<br>    #5 0x7fb95c1bfd78 in client_data /opt/osmocom/libosmocore/src/vty/telnet_interface.c:157<br>    #6 0x7fb95b90bd33 in osmo_fd_disp_fds /opt/osmocom/libosmocore/src/select.c:223<br>    #7 0x7fb95b90bd33 in osmo_select_main /opt/osmocom/libosmocore/src/select.c:263<br>    #8 0x5006cc in main /opt/osmocom/osmo-msc/src/osmo-msc/msc_main.c:723:3<br>    #9 0x7fb959935f44 in __libc_start_main /build/eglibc-xkFqqE/eglibc-2.19/csu/libc-start.c:287<br>    #10 0x4226fb in _start (/usr/local/bin/osmo-msc+0x4226fb)<br><br>== Why exactly 512?<br><br>Because the initial size of the heap buffer is 512 (see VTY_BUFSIZ).<br>Later on it can be realloc()ated, so X > 512 should also work.<br><br>Found using AddressSanitizer and Radamsa [1] fuzzer.<br><br>[1] https://gitlab.com/akihe/radamsa<br><br>Change-Id: I82f774ad18d0e555eb8f3590a519946d9c583c78<br>---<br>M src/vty/vty.c<br>1 file changed, 2 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/vty/vty.c b/src/vty/vty.c</span><br><span>index 98b332d..b1bb3f4 100644</span><br><span>--- a/src/vty/vty.c</span><br><span>+++ b/src/vty/vty.c</span><br><span>@@ -1416,6 +1416,8 @@</span><br><span>              case '\n':</span><br><span>           case '\r':</span><br><span>                   vty_out(vty, "%s", VTY_NEWLINE);</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* '\0'-terminate the command buffer */</span><br><span style="color: hsl(120, 100%, 40%);">+                       vty->buf[vty->length] = '\0';</span><br><span>                  vty_execute(vty);</span><br><span>                    break;</span><br><span>               case '\t':</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/14973">change 14973</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/14973"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I82f774ad18d0e555eb8f3590a519946d9c583c78 </div>
<div style="display:none"> Gerrit-Change-Number: 14973 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Vadim Yanitskiy <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: Vadim Yanitskiy <axilirator@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-CC: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>