Messages in this thread | | | From | Kees Cook <> | Date | Mon, 14 Jan 2019 17:07:16 -0800 | Subject | Re: [PATCH 1/8] lkdtm: change snprintf to scnprintf for possible overflow |
| |
On Mon, Jan 14, 2019 at 5:02 PM Kees Cook <keescook@chromium.org> wrote: > On Sat, Jan 12, 2019 at 7:28 AM Willy Tarreau <w@1wt.eu> wrote: > > From: Silvio Cesare <silvio.cesare@gmail.com> > > Change snprintf to scnprintf. There are generally two cases where using > > snprintf causes problems. > > (I didn't find a 0/8 cover letter, so I'm replying here...)
I forgot to mention: can we please get a Coccinelle rule added to catch these cases in the future? (And make sure sfr is running it? :) )
My attempt at it was:
@@ expression LEN, BUF, SIZE; identifier FUNC; @@
LEN += snprintf(BUF + LEN, SIZE - LEN, ...); ... when != LEN > SIZE when != LEN >= SIZE * FUNC(..., LEN, ...)
But this needs adjustment to deal with some false positives (like using min()).
-- Kees Cook
| |