usbtty: avoid potential NULL pointer dereference
PATCH 1/1 usbtty: avoid potential NULL pointer dereference
If current_urb is NULL it should not be dereferenced.
The problem was indicated by cppcheck.
Signed-off-by Heinrich Schuchardt <[email protected]>
--- drivers/serial/usbtty.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/serial/usbtty.c +7 -6
@@ -850,6 +850,13 @@ static int write_buffer (circbuf_t * buf)struct urb *current_urb =NULL ; current_urb =next_urb (device_instance, endpoint); + +if (!current_urb) { +TTYERR ("current_urb is NULL, buf->size %d\n" , + buf->size); +return 0 ; + } +/* TX data still exists - send it now */ if (endpoint->sent < current_urb->actual_length){
@@ -871,12 +878,6 @@ static int write_buffer (circbuf_t * buf)*/ while (buf->size >0 ) { -if (!current_urb) { -TTYERR ("current_urb is NULL, buf->size %d\n" , - buf->size); -return total; - } - dest = (char *)current_urb->buffer + current_urb->actual_length;
Signature · 1 line
2.11.0
PATCH 1/1 usbtty: avoid potential NULL pointer dereference
Quoted 5 lines · Heinrich Schuchardt
If
current_urbis NULL it should not be dereferenced.The problem was indicated by cppcheck.
Signed-off-by Heinrich Schuchardt <[email protected]>
Reviewed-by Tom Rini <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170415/b51ec251/attachment.sig>
Marek Vasut
AppliedPATCH 1/1 usbtty: avoid potential NULL pointer dereference
In reply to Heinrich SchuchardtQuoted 5 lines · Heinrich Schuchardt
If
current_urbis NULL it should not be dereferenced.The problem was indicated by cppcheck.
Signed-off-by Heinrich Schuchardt <[email protected]>
Applied, thanks.
Quoted 36 lines
--- drivers/serial/usbtty.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/serial/usbtty.c +7
-6@@ -850,6 +850,13 @@ static int write_buffer (circbuf_t * buf)struct urb *current_urb =NULL ; current_urb =next_urb (device_instance, endpoint); + +if (!current_urb) { +TTYERR ("current_urb is NULL, buf->size %d\n" , + buf->size); +return 0 ; + } +/* TX data still exists - send it now */ if (endpoint->sent < current_urb->actual_length){@@ -871,12 +878,6 @@ static int write_buffer (circbuf_t * buf)*/ while (buf->size >0 ) { -if (!current_urb) { -TTYERR ("current_urb is NULL, buf->size %d\n" , - buf->size); -return total; - } - dest = (char *)current_urb->buffer + current_urb->actual_length;
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/1 usbtty: avoid potential NULL pointer dereference
In reply to Heinrich SchuchardtQuoted 6 lines · xypron.glpk at gmx.de
If
current_urbis NULL it should not be dereferenced.The problem was indicated by cppcheck.
Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170419/f7ea5cb6/attachment.sig>