* [patch] vga_switcheroo: comparing too few characters in strncmp()
@ 2011-01-07 5:12 Dan Carpenter
2011-01-07 5:30 ` Alexey Dobriyan
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2011-01-07 5:12 UTC (permalink / raw)
To: Dave Airlie; +Cc: Jiri Slaby, linux-kernel, kernel-janitors
This is a copy-and-paste bug. We should be comparing 4 characters here
instead of 3.
Signed-off-by: Dan Carpenter <error27@gmail.com>
diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index d2d8543..e01cacb 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -346,11 +346,11 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
if (strncmp(usercmd, "DIS", 3) == 0)
client_id = VGA_SWITCHEROO_DIS;
- if (strncmp(usercmd, "MIGD", 3) == 0) {
+ if (strncmp(usercmd, "MIGD", 4) == 0) {
just_mux = true;
client_id = VGA_SWITCHEROO_IGD;
}
- if (strncmp(usercmd, "MDIS", 3) == 0) {
+ if (strncmp(usercmd, "MDIS", 4) == 0) {
just_mux = true;
client_id = VGA_SWITCHEROO_DIS;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [patch] vga_switcheroo: comparing too few characters in strncmp()
2011-01-07 5:12 [patch] vga_switcheroo: comparing too few characters in strncmp() Dan Carpenter
@ 2011-01-07 5:30 ` Alexey Dobriyan
2011-01-07 6:05 ` Dan Carpenter
2011-01-07 6:07 ` Mailing Lists
0 siblings, 2 replies; 4+ messages in thread
From: Alexey Dobriyan @ 2011-01-07 5:30 UTC (permalink / raw)
To: Dan Carpenter, Dave Airlie, Jiri Slaby, linux-kernel,
kernel-janitors
On Fri, Jan 07, 2011 at 08:12:27AM +0300, Dan Carpenter wrote:
> This is a copy-and-paste bug. We should be comparing 4 characters here
> instead of 3.
> --- a/drivers/gpu/vga/vga_switcheroo.c
> +++ b/drivers/gpu/vga/vga_switcheroo.c
> @@ -346,11 +346,11 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
> if (strncmp(usercmd, "DIS", 3) == 0)
> client_id = VGA_SWITCHEROO_DIS;
>
> - if (strncmp(usercmd, "MIGD", 3) == 0) {
> + if (strncmp(usercmd, "MIGD", 4) == 0) {
> just_mux = true;
> client_id = VGA_SWITCHEROO_IGD;
> }
> - if (strncmp(usercmd, "MDIS", 3) == 0) {
> + if (strncmp(usercmd, "MDIS", 4) == 0) {
How about you NUL-terminate, and use strcmp().
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] vga_switcheroo: comparing too few characters in strncmp()
2011-01-07 5:30 ` Alexey Dobriyan
@ 2011-01-07 6:05 ` Dan Carpenter
2011-01-07 6:07 ` Mailing Lists
1 sibling, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2011-01-07 6:05 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: Dave Airlie, Jiri Slaby, linux-kernel, kernel-janitors
On Fri, Jan 07, 2011 at 07:30:54AM +0200, Alexey Dobriyan wrote:
> On Fri, Jan 07, 2011 at 08:12:27AM +0300, Dan Carpenter wrote:
> > - if (strncmp(usercmd, "MDIS", 3) == 0) {
> > + if (strncmp(usercmd, "MDIS", 4) == 0) {
>
> How about you NUL-terminate, and use strcmp().
I assume there is a reason for this userspace API. Dave?
regards,
dan carpenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [patch] vga_switcheroo: comparing too few characters in strncmp()
2011-01-07 5:30 ` Alexey Dobriyan
2011-01-07 6:05 ` Dan Carpenter
@ 2011-01-07 6:07 ` Mailing Lists
1 sibling, 0 replies; 4+ messages in thread
From: Mailing Lists @ 2011-01-07 6:07 UTC (permalink / raw)
To: Alexey Dobriyan; +Cc: linux-kernel
On Fri, 2011-01-07 at 07:30 +0200, Alexey Dobriyan wrote:
> On Fri, Jan 07, 2011 at 08:12:27AM +0300, Dan Carpenter wrote:
> > This is a copy-and-paste bug. We should be comparing 4 characters here
> > instead of 3.
>
> > --- a/drivers/gpu/vga/vga_switcheroo.c
> > +++ b/drivers/gpu/vga/vga_switcheroo.c
> > @@ -346,11 +346,11 @@ vga_switcheroo_debugfs_write(struct file *filp, const char __user *ubuf,
> > if (strncmp(usercmd, "DIS", 3) == 0)
> > client_id = VGA_SWITCHEROO_DIS;
> >
> > - if (strncmp(usercmd, "MIGD", 3) == 0) {
> > + if (strncmp(usercmd, "MIGD", 4) == 0) {
> > just_mux = true;
> > client_id = VGA_SWITCHEROO_IGD;
> > }
> > - if (strncmp(usercmd, "MDIS", 3) == 0) {
> > + if (strncmp(usercmd, "MDIS", 4) == 0) {
>
> How about you NUL-terminate, and use strcmp().
Userspace data? How to guarantee NULL terminated string at runtime?
Still, the string constants being compared against are already NULL
terminated, so he could use strcmp as is.
Also, strcmp() would discard user strings that start with a matching
substring ("DIS", "DISK", "DISH", "DISINTERESTED" would all set
client_id to VGA_SWITCHEROO_DIS, using strncmp(), but strcmp() would
only match "DIS").
> --
> 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-01-07 6:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-07 5:12 [patch] vga_switcheroo: comparing too few characters in strncmp() Dan Carpenter
2011-01-07 5:30 ` Alexey Dobriyan
2011-01-07 6:05 ` Dan Carpenter
2011-01-07 6:07 ` Mailing Lists
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox