From: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, stefanha@gmail.com
Cc: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>, jvrao@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH v4] v9fs_walk: As per 9p2000 RFC, MAXWELEM >= nwnames >= 0.
Date: Tue, 5 Apr 2011 16:05:35 +0530 [thread overview]
Message-ID: <1301999735-24141-1-git-send-email-harsh@linux.vnet.ibm.com> (raw)
The nwnames field in TWALK message is assumed to be >=0 and <= MAXWELEM
which is defined as macro P9_MAXWELEM (16) in virtio-9p.h as per 9p2000
RFC. Appropriate changes are required in V9fsWalkState and v9fs_walk.
v4:
- rebased on mainline repo, else condition updated as required.
v3:
- Updated if-else conditions to appropriately handle nwnames = 0.
v2:
- Added check in v9fs_walk_complete as well.
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
---
hw/virtio-9p.c | 7 +++++--
hw/virtio-9p.h | 2 +-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 7c59988..1656862 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1482,7 +1482,7 @@ static void v9fs_walk_complete(V9fsState *s, V9fsWalkState *vs, int err)
{
complete_pdu(s, vs->pdu, err);
- if (vs->nwnames) {
+ if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) {
for (vs->name_idx = 0; vs->name_idx < vs->nwnames; vs->name_idx++) {
v9fs_string_free(&vs->wnames[vs->name_idx]);
}
@@ -1578,7 +1578,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "ddw", &fid,
&newfid, &vs->nwnames);
- if (vs->nwnames) {
+ if (vs->nwnames && vs->nwnames <= P9_MAXWELEM) {
vs->wnames = qemu_mallocz(sizeof(vs->wnames[0]) * vs->nwnames);
vs->qids = qemu_mallocz(sizeof(vs->qids[0]) * vs->nwnames);
@@ -1587,6 +1587,9 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
vs->offset += pdu_unmarshal(vs->pdu, vs->offset, "s",
&vs->wnames[i]);
}
+ } else if (vs->nwnames > P9_MAXWELEM) {
+ err = -EINVAL;
+ goto out;
}
vs->fidp = lookup_fid(s, fid);
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 2ae4ce7..3c92c74 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -282,7 +282,7 @@ typedef struct V9fsStatStateDotl {
typedef struct V9fsWalkState {
V9fsPDU *pdu;
size_t offset;
- int16_t nwnames;
+ uint16_t nwnames;
int name_idx;
V9fsQID *qids;
V9fsFidState *fidp;
--
1.7.1.1
next reply other threads:[~2011-04-05 10:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-05 10:35 Harsh Prateek Bora [this message]
2011-04-05 12:27 ` [Qemu-devel] Re: [PATCH v4] v9fs_walk: As per 9p2000 RFC, MAXWELEM >= nwnames >= 0 Stefan Hajnoczi
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=1301999735-24141-1-git-send-email-harsh@linux.vnet.ibm.com \
--to=harsh@linux.vnet.ibm.com \
--cc=jvrao@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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).