X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Fstring.h;h=d5686704c224d988e15655ea8a082ccd33722ee3;hb=d08ae85ee42d1914e60bd2566c533db6ec3e3598;hp=a25d461868b61c13c0f4b1e9ba273b2cb95db6a0;hpb=eaec2a6d9ab8b983aaee536be1a95846c07a9d7f;p=vpp.git diff --git a/src/vppinfra/string.h b/src/vppinfra/string.h index a25d461868b..d5686704c22 100644 --- a/src/vppinfra/string.h +++ b/src/vppinfra/string.h @@ -1031,10 +1031,20 @@ strncpy_s_inline (char *__restrict__ dest, rsize_t dmax, low = (uword) (src < dest ? src : dest); hi = (uword) (src < dest ? dest : src); + /* + * This check may fail innocently if src + dmax >= dst, but + * src + strlen(src) < dst. If it fails, check more carefully before + * blowing the whistle. + */ if (PREDICT_FALSE (low + (m - 1) >= hi)) { - clib_c11_violation ("src/dest overlap"); - return EINVAL; + m = clib_strnlen (src, m); + + if (low + (m - 1) >= hi) + { + clib_c11_violation ("src/dest overlap"); + return EINVAL; + } } clib_memcpy_fast (dest, src, m);