* [PATCH] staging: speakup: kobjects.c: fix char argument to %02x
@ 2015-12-06 0:05 Rasmus Villemoes
2015-12-06 0:12 ` Joe Perches
2015-12-12 23:49 ` Andy Shevchenko
0 siblings, 2 replies; 5+ messages in thread
From: Rasmus Villemoes @ 2015-12-06 0:05 UTC (permalink / raw)
To: William Hubbs, Chris Brannon, Kirk Reiser, Samuel Thibault,
Greg Kroah-Hartman
Cc: Rasmus Villemoes, speakup, devel, linux-kernel
If char is signed and ch happens to be negative, printing ch with
"%02x" will not do as intended (when ch is -19, one will get
"ffffffed"). Fix that by masking with 0xff.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
drivers/staging/speakup/kobjects.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index fdfeb42b2b8f..8b88f03e266b 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -567,7 +567,7 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
if (ch >= ' ' && ch < '~')
*cp1++ = ch;
else
- cp1 += sprintf(cp1, "\\x%02x", ch);
+ cp1 += sprintf(cp1, "\\x%02x", ch & 0xff);
}
*cp1++ = '"';
*cp1++ = '\n';
--
2.6.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: speakup: kobjects.c: fix char argument to %02x
2015-12-06 0:05 [PATCH] staging: speakup: kobjects.c: fix char argument to %02x Rasmus Villemoes
@ 2015-12-06 0:12 ` Joe Perches
2015-12-06 0:21 ` Rasmus Villemoes
2015-12-12 23:49 ` Andy Shevchenko
1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2015-12-06 0:12 UTC (permalink / raw)
To: Rasmus Villemoes, William Hubbs, Chris Brannon, Kirk Reiser,
Samuel Thibault, Greg Kroah-Hartman
Cc: speakup, devel, linux-kernel
On Sun, 2015-12-06 at 01:05 +0100, Rasmus Villemoes wrote:
> If char is signed and ch happens to be negative, printing ch with
> "%02x" will not do as intended (when ch is -19, one will get
> "ffffffed"). Fix that by masking with 0xff.
I presume there are a lot of these in the kernel.
Did you use a tool to find this or just inspection?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: speakup: kobjects.c: fix char argument to %02x
2015-12-06 0:12 ` Joe Perches
@ 2015-12-06 0:21 ` Rasmus Villemoes
2015-12-06 0:28 ` Joe Perches
0 siblings, 1 reply; 5+ messages in thread
From: Rasmus Villemoes @ 2015-12-06 0:21 UTC (permalink / raw)
To: Joe Perches
Cc: William Hubbs, Chris Brannon, Kirk Reiser, Samuel Thibault,
Greg Kroah-Hartman, devel, speakup, linux-kernel
On Sun, Dec 06 2015, Joe Perches <joe@perches.com> wrote:
> On Sun, 2015-12-06 at 01:05 +0100, Rasmus Villemoes wrote:
>> If char is signed and ch happens to be negative, printing ch with
>> "%02x" will not do as intended (when ch is -19, one will get
>> "ffffffed"). Fix that by masking with 0xff.
>
> I presume there are a lot of these in the kernel.
> Did you use a tool to find this or just inspection?
Initially I just used coccinelle, for the most obvious candidates (with
--include-headers-for-types):
@r depends on !patch@
char c;
@@
* \( sprintf \| snprintf \| scnprintf \) (..., c, ...)
That gives lots of false positives (arguments to %c), but it's not too
bad piping to less, searching for "%[0.]2[xX]", and then checking
manually.
I'm now doing a much wider range of printf functions, but it's really
past my bedtime, so feel free to pick up the ball :-)
Rasmus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: speakup: kobjects.c: fix char argument to %02x
2015-12-06 0:21 ` Rasmus Villemoes
@ 2015-12-06 0:28 ` Joe Perches
0 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2015-12-06 0:28 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: William Hubbs, Chris Brannon, Kirk Reiser, Samuel Thibault,
Greg Kroah-Hartman, devel, speakup, linux-kernel
On Sun, 2015-12-06 at 01:21 +0100, Rasmus Villemoes wrote:
> On Sun, Dec 06 2015, Joe Perches <joe@perches.com> wrote:
>
> > On Sun, 2015-12-06 at 01:05 +0100, Rasmus Villemoes wrote:
> > > If char is signed and ch happens to be negative, printing ch with
> > > "%02x" will not do as intended (when ch is -19, one will get
> > > "ffffffed"). Fix that by masking with 0xff.
> >
> > I presume there are a lot of these in the kernel.
> > Did you use a tool to find this or just inspection?
>
> Initially I just used coccinelle, for the most obvious candidates
> (with
> --include-headers-for-types):
>
> @r depends on !patch@
> char c;
> @@
> * \( sprintf \| snprintf \| scnprintf \) (..., c, ...)
>
> That gives lots of false positives (arguments to %c), but it's not
> too
> bad piping to less, searching for "%[0.]2[xX]", and then checking
> manually.
>
> I'm now doing a much wider range of printf functions, but it's really
> past my bedtime, so feel free to pick up the ball :-)
>
Thanks, but no thanks. It's your ball. Enjoy...
You might consider looking for s8 and s16 emitted as %u too.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] staging: speakup: kobjects.c: fix char argument to %02x
2015-12-06 0:05 [PATCH] staging: speakup: kobjects.c: fix char argument to %02x Rasmus Villemoes
2015-12-06 0:12 ` Joe Perches
@ 2015-12-12 23:49 ` Andy Shevchenko
1 sibling, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2015-12-12 23:49 UTC (permalink / raw)
To: Rasmus Villemoes
Cc: William Hubbs, Chris Brannon, Kirk Reiser, Samuel Thibault,
Greg Kroah-Hartman, speakup, devel, linux-kernel@vger.kernel.org
On Sun, Dec 6, 2015 at 2:05 AM, Rasmus Villemoes
<linux@rasmusvillemoes.dk> wrote:
> If char is signed and ch happens to be negative, printing ch with
> "%02x" will not do as intended (when ch is -19, one will get
> "ffffffed"). Fix that by masking with 0xff.
>
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
> drivers/staging/speakup/kobjects.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
> index fdfeb42b2b8f..8b88f03e266b 100644
> --- a/drivers/staging/speakup/kobjects.c
> +++ b/drivers/staging/speakup/kobjects.c
> @@ -567,7 +567,7 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
> if (ch >= ' ' && ch < '~')
> *cp1++ = ch;
> else
> - cp1 += sprintf(cp1, "\\x%02x", ch);
> + cp1 += sprintf(cp1, "\\x%02x", ch & 0xff);
Have you considered to use string_escape_str()?
This one clearly looks like ESCAPE_HEX.
> }
> *cp1++ = '"';
> *cp1++ = '\n';
> --
> 2.6.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-12-12 23:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-06 0:05 [PATCH] staging: speakup: kobjects.c: fix char argument to %02x Rasmus Villemoes
2015-12-06 0:12 ` Joe Perches
2015-12-06 0:21 ` Rasmus Villemoes
2015-12-06 0:28 ` Joe Perches
2015-12-12 23:49 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox