X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Funittest%2Fstring_test.c;h=95a95d78c1d716b09e7817a8b742e7fc28fd4c43;hb=refs%2Fchanges%2F29%2F25429%2F2;hp=5016a86ac824a2321ebedaca93d45d34c2598098;hpb=2de9c0f92bb486072d8371a24d9b23fd85e1aa80;p=vpp.git diff --git a/src/plugins/unittest/string_test.c b/src/plugins/unittest/string_test.c index 5016a86ac82..95a95d78c1d 100644 --- a/src/plugins/unittest/string_test.c +++ b/src/plugins/unittest/string_test.c @@ -85,11 +85,20 @@ test_memcpy_s (vlib_main_t * vm, unformat_input_t * input) if (src[i] != dst[i]) return -1; - /* Size fail */ - err = memcpy_s (dst + 1, sizeof (dst) - 1, src, sizeof (src)); + /* + * Size test: sizeof (src) > sizeof (dst) + * Skip this test when __builtin_constant_p (sizeof (src)) is true. + * This is because memcpy_s_inline skips all the errors checking when the + * the above buildin function returns true which may cause overrun problem + * for dst buffer if this test is executed. + */ + if (__builtin_constant_p (sizeof (src)) == 0) + { + err = memcpy_s (dst + 1, sizeof (dst) - 1, src, sizeof (src)); - if (err == EOK) - return -1; + if (err == EOK) + return -1; + } /* overlap fail */ err = memcpy_s (dst, sizeof (dst), dst + 1, sizeof (dst) - 1);