From: Roel Kluin <roel.kluin@gmail.com>
To: Jarek Poplawski <jarkao2@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Andrew Morton <akpm@linux-foundation.org>,
philb@gnu.org
Subject: [PATCH] 3c505: do not set pcb->data.raw beyond its size
Date: Wed, 11 Feb 2009 23:55:40 +0100 [thread overview]
Message-ID: <4993576C.8080409@gmail.com> (raw)
In-Reply-To: <20090211205854.GB2550@ami.dom.local>
Many thanks, Jarek,
Is this changelog ok?
------------------------------>8----------------8<------------------------------
Ensure that we do not set pcb->data.raw beyond its size, print an error message
and return false if we attempt to. A timout message was printed one too early.
Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/net/3c505.c b/drivers/net/3c505.c
index 6124605..a8107f9 100644
--- a/drivers/net/3c505.c
+++ b/drivers/net/3c505.c
@@ -493,21 +493,27 @@ static bool receive_pcb(struct net_device *dev, pcb_struct * pcb)
}
/* read the data */
spin_lock_irqsave(&adapter->lock, flags);
- i = 0;
- do {
- j = 0;
- while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && j++ < 20000);
- pcb->data.raw[i++] = inb_command(dev->base_addr);
- if (i > MAX_PCB_DATA)
- INVALID_PCB_MSG(i);
- } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
+ for (i = 0; i < MAX_PCB_DATA; i++) {
+ for (j = 0; j < 20000; j++) {
+ stat = get_status(dev->base_addr);
+ if (stat & ACRF)
+ break;
+ }
+ pcb->data.raw[i] = inb_command(dev->base_addr);
+ if ((stat & ASF_PCB_MASK) == ASF_PCB_END || j >= 20000)
+ break;
+ }
spin_unlock_irqrestore(&adapter->lock, flags);
+ if (i >= MAX_PCB_DATA) {
+ INVALID_PCB_MSG(i);
+ return false;
+ }
if (j >= 20000) {
TIMEOUT_MSG(__LINE__);
return false;
}
- /* woops, the last "data" byte was really the length! */
- total_length = pcb->data.raw[--i];
+ /* the last "data" byte was really the length! */
+ total_length = pcb->data.raw[i];
/* safety check total length vs data length */
if (total_length != (pcb->length + 2)) {
next prev parent reply other threads:[~2009-02-11 22:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-11 10:01 [PATCH] net: off by one, try #2 Roel Kluin
2009-02-11 13:33 ` Jarek Poplawski
2009-02-11 14:22 ` Roel Kluin
2009-02-11 17:14 ` Jarek Poplawski
2009-02-11 19:33 ` Roel Kluin
2009-02-11 20:27 ` Jarek Poplawski
2009-02-11 20:58 ` Jarek Poplawski
2009-02-11 22:55 ` Roel Kluin [this message]
2009-02-12 6:37 ` [PATCH] 3c505: do not set pcb->data.raw beyond its size Jarek Poplawski
2009-02-13 0:52 ` David Miller
2009-02-11 21:22 ` [PATCH] IRDA: cnt is off by 1 Roel Kluin
2009-02-13 0:42 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4993576C.8080409@gmail.com \
--to=roel.kluin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=jarkao2@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=philb@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).