From: Dan Williams <dcbw@redhat.com>
To: Dan Carpenter <error27@gmail.com>
Cc: javier@cozybit.com, "John W. Linville" <linville@tuxdriver.com>,
libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org,
netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] libertas: fix write past end of array in mesh_id_get()
Date: Thu, 10 Mar 2011 11:02:02 -0600 [thread overview]
Message-ID: <1299776524.17443.14.camel@dcbw.foobar.com> (raw)
In-Reply-To: <20110310152326.GA2008@bicker>
On Thu, 2011-03-10 at 18:23 +0300, Dan Carpenter wrote:
> defs.meshie.val.mesh_id is 32 chars long. It's not supposed to be NUL
> terminated. This code puts a terminator on the end to make it easier to
> print to sysfs. The problem is that if the mesh_id fills the entire
> buffer the original code puts the terminator one spot past the end.
>
> The way the original code was written, there was a check to make sure
> that maxlen was less than PAGE_SIZE. Since we know that maxlen is at
> most 34 chars, I just removed the check.
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
Acked-by: Dan Williams <dcbw@redhat.com>
> diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
> index acf3bf6..9d097b9 100644
> --- a/drivers/net/wireless/libertas/mesh.c
> +++ b/drivers/net/wireless/libertas/mesh.c
> @@ -918,7 +918,6 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
> char *buf)
> {
> struct mrvl_mesh_defaults defs;
> - int maxlen;
> int ret;
>
> ret = mesh_get_default_parameters(dev, &defs);
> @@ -931,13 +930,11 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
> defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
> }
>
> - /* SSID not null terminated: reserve room for \0 + \n */
> - maxlen = defs.meshie.val.mesh_id_len + 2;
> - maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE;
> + memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
> + buf[defs.meshie.val.mesh_id_len] = '\n';
> + buf[defs.meshie.val.mesh_id_len + 1] = '\0';
>
> - defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0';
> -
> - return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
> + return defs.meshie.val.mesh_id_len + 1;
> }
>
> /**
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
prev parent reply other threads:[~2011-03-10 17:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-10 15:23 [patch] libertas: fix write past end of array in mesh_id_get() Dan Carpenter
2011-03-10 17:02 ` Dan Williams [this message]
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=1299776524.17443.14.camel@dcbw.foobar.com \
--to=dcbw@redhat.com \
--cc=error27@gmail.com \
--cc=javier@cozybit.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=libertas-dev@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.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