Commit d89dba7a authored by Dan Carpenter's avatar Dan Carpenter Committed by John W. Linville

libertas: fix write past end of array in mesh_id_get()

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: default avatarDan Carpenter <error27@gmail.com>
Acked-by: default avatarDan Williams <dcbw@redhat.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 23952ec9
...@@ -918,7 +918,6 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr, ...@@ -918,7 +918,6 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct mrvl_mesh_defaults defs; struct mrvl_mesh_defaults defs;
int maxlen;
int ret; int ret;
ret = mesh_get_default_parameters(dev, &defs); ret = mesh_get_default_parameters(dev, &defs);
...@@ -931,13 +930,11 @@ static ssize_t mesh_id_get(struct device *dev, struct device_attribute *attr, ...@@ -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; defs.meshie.val.mesh_id_len = IEEE80211_MAX_SSID_LEN;
} }
/* SSID not null terminated: reserve room for \0 + \n */ memcpy(buf, defs.meshie.val.mesh_id, defs.meshie.val.mesh_id_len);
maxlen = defs.meshie.val.mesh_id_len + 2; buf[defs.meshie.val.mesh_id_len] = '\n';
maxlen = (PAGE_SIZE > maxlen) ? maxlen : PAGE_SIZE; buf[defs.meshie.val.mesh_id_len + 1] = '\0';
defs.meshie.val.mesh_id[defs.meshie.val.mesh_id_len] = '\0'; return defs.meshie.val.mesh_id_len + 1;
return snprintf(buf, maxlen, "%s\n", defs.meshie.val.mesh_id);
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment