On Tuesday, July 23, 2013 8:03 PM, Dan Carpenter wrote:
>
> The following test program illustrates the memory corruption. You
> would hope foo.b would be 42 but it is corrupted to -1.
>
> #include <stdio.h>
> #include <limits.h>
>
> struct foo {
> int a, b;
> };
>
> void kstrtol(long *x)
> {
> *x = -1;
> }
>
> int main(void)
> {
> struct foo foo;
>
> foo.b = 42;
> kstrtol((long *)&foo.a);
> printf("%d %d\n", foo.a, foo.b);
> return 0;
> }
>
> The error handling should return an error, it shouldn't just print
> something. It shouldn't print anything actually, it should just
> handle the error without printing or complaining. :P
Oh, thank you very much.
Your comment is very kind. :)
I will use kstrtos32() instead of kstrtol() as below:
- if (count >= 3)
- strict_strtol(sz_last_token, 10, (long *)&req);
+ if (count >= 3) {
+ status = kstrtos32(sz_last_token, 10, &req);
+ if (status)
+ goto func_cont;
+ }
I really appreciate your comment.
Best regards,
Jingoo Han
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel