[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 6 18:00:49 PDT 2018
NoQ added inline comments.
================
Comment at: test/Analysis/cstring-syntax.c:49
+ strlcat(dest, "0123456789", badlen / 2);
+ strlcat(dest, "0123456789", badlen); // expected-warning {{The third argument allows to potentially copy more bytes than it should. Replace with the value 'badlen' - strlen(dest) - 1 or lower}}
+ strlcat(dest, "0123456789", badlen - strlen(dest) - 1);
----------------
The suggested fix is a bit weird.
The correct code for appending `src` to `dst` is either `strlcat(dst, src, sizeof(dst));` (the approach suggested by the man page) or `strlcat(dst + strlen(dst) + 1, src, sizeof(dst) - strlen(dst) - 1)` (which is equivalent but faster if you already know `strlen(dst)`). In both cases you can specify a smaller value but not a larger value.
https://reviews.llvm.org/D49722
More information about the cfe-commits
mailing list