On Mon, 2014-01-27 at 16:39 -0800, Kees Cook wrote:

> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
[]
> @@ -1735,14 +1735,10 @@ int vsnprintf(char *buf, size_t size, const char 
> *fmt, va_list args)
>               case FORMAT_TYPE_NRCHARS: {
>                       /*
>                        * Since %n poses a greater security risk than
> -                      * utility, ignore %n and skip its argument.
> +                      * utility, it should not be implemented. Instead,
> +                      * when encountering %n, ignore the arguments.
>                        */
> -                     void *skip_arg;
> -
> -                     WARN_ONCE(1, "Please remove ignored %%n in '%s'\n",
> -                                     old_fmt);
> -
> -                     skip_arg = va_arg(args, void *);
> +                     WARN_ONCE(1, "Ignored %%n in '%s'\n", old_fmt);
>                       break;
>               }

I don't think this is better either.

Why not tell people to fix the code?
checkpatch isn't run on quite a lot of patches.

anyway, here's a possible checkpatch test too.
---
 scripts/checkpatch.pl | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1dbd6d1..95c3264 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4069,6 +4069,15 @@ sub process {
                        }
                }
 
+# check for unsupported uses of %n in what appear to be formats
+               if ($sline =~ /\b$logFunctions\s*\(.*"/) {
+                       my $fmt = get_quoted_string($line, $rawline);
+                       if ($fmt ne "" && $fmt =~ /[^\%]\%n/) {
+                               WARN("PRINTF_CONTROL_N",
+                                    "printf style use of \%n is not 
supported\n" . $herecurr);
+                       }
+               }
+
 # Check for misused memsets
                if ($^V && $^V ge 5.10.0 &&
                    defined $stat &&


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to