media: sq905.c: fix uninitialized variable
Subsystems (2)
PATCH 1/1 media: sq905.c: fix uninitialized variable
--- drivers/media/usb/gspca/sq905.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/gspca/sq905.c +2 -2
@@ -157,8 +157,8 @@ static int sq905_ack_frame(struct gspca_dev *gspca_dev)static int sq905_read_data (struct gspca_dev *gspca_dev,u8 *data,int size,int need_lock) { -int ret; -int act_len; +int ret =0 ; +int act_len =0 ; gspca_dev->usb_buf[0 ] ='\0' ;if (need_lock)
Signature · 1 line
2.25.1
Quoted 3 lines · Alaa Emad
Reported-by [email protected]Signed-off-by Alaa Emad <[email protected]>---
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
thanks,
greg k-h
Quoted 8 lines · Greg KH
Quoted 3 lines · Alaa Emad
Reported-by [email protected]Signed-off-by Alaa Emad <[email protected]>---
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
I wonder if it's the right fix or not.
Initializing variables will, of course, silence the warning, but it's not necessarily the right fix. I suspect there is something wrong in how ret/act_len are user/checked.
Hi!
Quoted 8 lines · Dmitry Vyukov' via syzkaller
Quoted 6 lines · Greg KH
Quoted 3 lines · Alaa Emad
Reported-by [email protected]Signed-off-by Alaa Emad <[email protected]>---
Quoted 8 lines
Quoted 2 lines
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
I wonder if it's the right fix or not.
Initializing variables will, of course, silence the warning, but it's not necessarily the right fix. I suspect there is something wrong in how ret/act_len are user/checked.
There is a problem in usb_bulk_msg() call. It could return before act_len initialization, so i think, act_len should be intialized with smth wrong like 0 or -1. BTW, I already send patch for that, but it was marked as obsoleted.
--
With regards,
Pavel Skripkin
Quoted 21 lines · Pavel Skripkin
Hi!
Quoted 8 lines · Dmitry Vyukov' via syzkaller
Quoted 6 lines · Greg KH
Quoted 3 lines · Alaa Emad
Reported-by [email protected]Signed-off-by Alaa Emad <[email protected]>---
Quoted 8 lines
Quoted 2 lines
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
I wonder if it's the right fix or not.
Initializing variables will, of course, silence the warning, but it's not necessarily the right fix. I suspect there is something wrong in how ret/act_len are user/checked.
Quoted 4 lines
There is a problem in
usb_bulk_msg()call. It could return beforeact_leninitialization, so i think,act_lenshould be intialized with smth wrong like 0 or -1. BTW, I already send patch for that, but it was marked as obsoleted.
If usb_bulk_msg returns before act_len initialization, it should signify that fact with an error code in return value or something, right? It does not initialize act_len only in case of errors, right? If so, sq905_read_data must check ret and don't use act_for any checks. But it does, and that's I think the bug. Or maybe usb_bulk_msg does not properly signify that it failed (and did not initialize act_len). Either way silencing the warning with pre-initializing act_len looks very fishy.
For example, consider, in some contexts it's OK to transmit 0-length packets, I don't know if it's the case for usb_bulk_msg or not, but it does not affect the idea. Now, if we pre-initialize act_len to 0, we can falsely think that such 0-length transfer has succeeded (act_len == size), while it actually failed (I assume so since usb_bulk_msg left act_len unitialized).
Hi!
Quoted 34 lines · Dmitry Vyukov
Quoted 26 lines · Pavel Skripkin
Hi!
Quoted 13 lines · Dmitry Vyukov' via syzkaller
Quoted 9 lines · Greg KH
Quoted 4 lines · Alaa Emad
Reported-by:
[email protected]Signed-off-by Alaa Emad <[email protected]>---
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
Quoted 7 lines
I wonder if it's the right fix or not.
Initializing variables will, of course, silence the warning, but it's
not necessarily the right fix. I suspect there is something wrong in
how ret/act_len are user/checked.Quoted 5 lines
There is a problem in
usb_bulk_msg()call. It could return beforeact_leninitialization, so i think,act_lenshould be intialized with smth wrong like 0 or -1. BTW, I already send patch for that, but it was
marked as obsoleted.
Quoted 14 lines
If
usb_bulk_msgreturns beforeact_leninitialization, it should signify that fact with an error code in return value or something, right? It does not initializeact_lenonly in case of errors, right? If so,sq905_read_datamust check ret and don't useact_forany checks. But it does, and that's I think the bug. Or maybeusb_bulk_msgdoes not properly signify that it failed (and did not initializeact_len). Either way silencing the warning with pre-initializingact_lenlooks very fishy.
For example, consider, in some contexts it's OK to transmit 0-length packets, I don't know if it's the case forusb_bulk_msgor not, but it does not affect the idea. Now, if we pre-initializeact_lento 0, we can falsely think that such 0-length transfer has succeeded (act_len== size), while it actually failed (I assume so sinceusb_bulk_msgleftact_lenunitialized).
You are absolutely rigth, and sq905_read_data doesn't use act_len for checks in case of usb_bulk_msg fail. But it uses it for error printing:
if (ret < 0 || act_len != size) {
pr_err("bulk read fail (%d) len %d/%d\n", ret,
act_len, size);
return -EIO;
}So, value like -1 can be a flag for smth went wrong internally. Or maybe remove this error log and replace it with other, which will rely on error code, idk how it will be better
--
With regards,
Pavel Skripkin
Quoted 62 lines · Pavel Skripkin
Hi!
Quoted 34 lines · Dmitry Vyukov
Quoted 26 lines · Pavel Skripkin
Hi!
Quoted 13 lines · Dmitry Vyukov' via syzkaller
Quoted 9 lines · Greg KH
Quoted 4 lines · Alaa Emad
Reported-by:
[email protected]Signed-off-by Alaa Emad <[email protected]>---
I know I do not take patches with no changelog text, but other maintainers might be more leniant :(
Quoted 7 lines
I wonder if it's the right fix or not.
Initializing variables will, of course, silence the warning, but it's
not necessarily the right fix. I suspect there is something wrong in
how ret/act_len are user/checked.Quoted 5 lines
There is a problem in
usb_bulk_msg()call. It could return beforeact_leninitialization, so i think,act_lenshould be intialized with smth wrong like 0 or -1. BTW, I already send patch for that, but it was
marked as obsoleted.Quoted 14 lines
If
usb_bulk_msgreturns beforeact_leninitialization, it should signify that fact with an error code in return value or something, right? It does not initializeact_lenonly in case of errors, right? If so,sq905_read_datamust check ret and don't useact_forany checks. But it does, and that's I think the bug. Or maybeusb_bulk_msgdoes not properly signify that it failed (and did not initializeact_len). Either way silencing the warning with pre-initializingact_lenlooks very fishy.
For example, consider, in some contexts it's OK to transmit 0-length packets, I don't know if it's the case forusb_bulk_msgor not, but it does not affect the idea. Now, if we pre-initializeact_lento 0, we can falsely think that such 0-length transfer has succeeded (act_len== size), while it actually failed (I assume so sinceusb_bulk_msgleftact_lenunitialized).You are absolutely rigth, and
sq905_read_datadoesn't useact_lenfor checks in case ofusb_bulk_msgfail. But it uses it for error printing:if (ret < 0 || act_len != size) { pr_err("bulk read fail (%d) len %d/%d\n", ret, act_len, size); return -EIO; }
Quoted 3 lines
So, value like -1 can be a flag for smth went wrong internally. Or maybe remove this error log and replace it with other, which will rely on error code, idk how it will be better
Oh, you are right.
I was thinking it's the "ret < 0 || act_len != size" check where we use uninit act_len, which would be much worse.
We could preinitialize act_len to, say, -1. But future readers may be confused as to why we need to init it (as I was confused). So another option may be to handle it during printing as:
pr_err("bulk read fail (%d) len %d/%d\n", ret, ret < 0 ? -1 : act_len, size);
It makes the intentions very explicit for a future reader.