<div dir="ltr">I'm trying to count the number of ways this code snippet would fail a commercial coding standard such as MISRA... ;-)<div><br></div><div>I believe you're right Daniel: res should be bounds checked something like 0 < res < (BUFFER_SIZE-pos) ?? and adding an assert(pos < BUFFER_SIZE) somewhere would be nice too...</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, 11 Jul 2018 at 21:28, Daniel Gutson <<a href="mailto:danielgutson@gmail.com">danielgutson@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div> considering this: <pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px;margin-top:0px;margin-bottom:0px;color:rgb(36,41,46);text-decoration-style:initial;text-decoration-color:initial;width:1px;height:1px"><a href="https://github.com/mkj/dropbear/blob/d740dc548924f2faf0934e5f9a4b83d2b5d6902d/atomicio.c#L55" target="_blank">https://github.com/mkj/dropbear/blob/d740dc548924f2faf0934e5f9a4b83d2b5d6902d/atomicio.c#L55</a></pre><div><br></div><div><br></div><div><br></div><div><div><span style="white-space:pre-wrap">                </span>switch (res) {</div><div><span style="white-space:pre-wrap">                </span>case -1:</div><div><span style="white-space:pre-wrap">                        </span>if (errno == EINTR || errno == EAGAIN)</div><div><span style="white-space:pre-wrap">                                </span>continue;</div><div><span style="white-space:pre-wrap">                        </span>return 0;</div><div><span style="white-space:pre-wrap">                </span>case 0:</div><div><span style="white-space:pre-wrap">                        </span>errno = EPIPE;</div><div><span style="white-space:pre-wrap">                        </span>return pos;</div><div><span style="white-space:pre-wrap">                </span>default:</div><div><span style="white-space:pre-wrap">                        </span>pos += (size_t)res;</div><div><span style="white-space:pre-wrap">                </span>}</div></div><div><br></div><div>What if res is negative less than -1, for example -2 ? Shouldn't be a check there that res is > 0 ?</div><div><br></div><div>Thanks,</div><div><br></div><div> Daniel.</div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-4730024076993518599gmail_signature">Who’s got the sweetest disposition?<br>One guess, that’s who?<br>Who’d never, ever start an argument?<br>Who never shows a bit of temperament?<br>Who's never wrong but always right?<br>Who'd never dream of starting a fight?<br>Who get stuck with all the bad luck? </div></div></div>
</blockquote></div>