Skip to contentSkip to conversation

usbtty: avoid potential NULL pointer dereference

PATCH New Heinrich Schuchardt 3 participants 4 messages Apr 15, 2017 – Apr 19, 2017

lore
Share & tools
lore
#0 lore raw

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.

---
 drivers/serial/usbtty.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/serial/usbtty.c +7 -6
index 2e19813643..29799dce93 100644
@@ -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
#1 lore raw

PATCH 1/1 usbtty: avoid potential NULL pointer dereference

Quoted 5 lines · Heinrich Schuchardt

If current_urb is NULL it should not be dereferenced.

The problem was indicated by cppcheck.

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>
Applied
#2 lore raw

PATCH 1/1 usbtty: avoid potential NULL pointer dereference

In reply to Heinrich Schuchardt
Quoted 5 lines · Heinrich Schuchardt

If current_urb is NULL it should not be dereferenced.

The problem was indicated by cppcheck.

Applied, thanks.

Quoted 36 lines
---
 drivers/serial/usbtty.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/serial/usbtty.c +7 -6
index 2e19813643..29799dce93 100644
@@ -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
#3 lore raw

PATCH 1/1 usbtty: avoid potential NULL pointer dereference

In reply to Heinrich Schuchardt
Quoted 6 lines · xypron.glpk at gmx.de

If current_urb is NULL it should not be dereferenced.

The problem was indicated by cppcheck.

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>