diff options
author | Robert Varga <nite@hq.alert.sk> | 2008-06-16 12:58:50 +0200 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2008-06-16 14:27:53 +0200 |
commit | b4a7fef1555d2dc3573cd0cba9a6a1eb67d890ee (patch) | |
tree | 6ac1cccea052a4e9019845d45bfa673277c50d22 | |
parent | b5d53dac1cb24be6d075eaee24f0d1611cc13dc0 (diff) | |
download | pcmciautils-b4a7fef1555d2dc3573cd0cba9a6a1eb67d890ee.tar.gz |
pccardctl: add array out-of-bounds exception
The following patch fixes an array out-of-bounds exception, which is easily
triggered with Ricoh's Bay8Controller.
Additionally, following improvements are made:
- correct a check for NULL path name
- make lookup tables const
- fix warnings stemming from printf() format strings
Signed-off-by: Robert Varga <nite@hq.alert.sk>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
-rw-r--r-- | src/pccardctl.c | 12 | ||||
-rw-r--r-- | src/pcmcia-check-broken-cis.c | 4 | ||||
-rw-r--r-- | src/startup.c | 4 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/pccardctl.c b/src/pccardctl.c index da5c4d3..d3d3317 100644 --- a/src/pccardctl.c +++ b/src/pccardctl.c @@ -26,7 +26,7 @@ #define MAX_SOCKET 8 -static char *fn[] = { +static const char * const fn[] = { "multifunction", "memory", "serial", @@ -79,7 +79,7 @@ static int pccardctl_echo_one(unsigned long socket_no, const char *in_file) char file[SYSFS_PATH_MAX]; struct sysfs_attribute *attr; - if (!file) + if (!in_file) return -EINVAL; snprintf(file, SYSFS_PATH_MAX, "/sys/class/pcmcia_socket/pcmcia_socket%lu/%s", @@ -249,8 +249,12 @@ static int pccardctl_ident(unsigned long socket_no) if (!pccardctl_get_one(socket_no, "card_id", &card_id)) printf(" manfid: 0x%04x, 0x%04x\n", manf_id, card_id); - if (!pccardctl_get_one(socket_no, "func_id", &manf_id)) - printf(" function: %d (%s)\n", manf_id, fn[manf_id]); + if (!pccardctl_get_one(socket_no, "func_id", &manf_id)) { + const char *s = "unknown"; + if (manf_id < sizeof(fn)/sizeof(*fn)) + s = fn[manf_id]; + printf(" function: %d (%s)\n", manf_id, s); + } return 0; diff --git a/src/pcmcia-check-broken-cis.c b/src/pcmcia-check-broken-cis.c index b99929c..dd65b1c 100644 --- a/src/pcmcia-check-broken-cis.c +++ b/src/pcmcia-check-broken-cis.c @@ -42,7 +42,7 @@ struct needs_cis { #define NEEDS_CIS_ENTRY(_code, _ofs, _info, _cisfile) \ { .code = _code, .ofs = _ofs, .info = _info, .cisfile = _cisfile, } -static struct needs_cis cis_table[] = { +static const struct needs_cis cis_table[] = { /* "D-Link DE-650 Ethernet" */ NEEDS_CIS_ENTRY(0x40, 0x0009, "D-Link PC Ethernet Card", "D-Link.cis"), /* "Linksys Ethernet E-CARD PC Ethernet Card */ @@ -161,7 +161,7 @@ int main(int argc, char **argv) { int ret; char *socket; unsigned int socket_no; - struct needs_cis * entry = NULL; + const struct needs_cis * entry = NULL; tuple_t tuple; unsigned char buf[256]; int opt; diff --git a/src/startup.c b/src/startup.c index 1439a65..f735db8 100644 --- a/src/startup.c +++ b/src/startup.c @@ -93,7 +93,7 @@ static int add_available_resource(unsigned int socket_no, unsigned int type, if (!attr) return -ENODEV; - dprintf("open, len %d\n", len); + dprintf("open, len %zu\n", len); ret = sysfs_write_attribute(attr, content, len); @@ -148,7 +148,7 @@ static int disallow_irq(unsigned int socket_no, unsigned int irq) if (!attr) return -ENODEV; - dprintf("open, len %d\n", len); + dprintf("open, len %zu\n", len); ret = sysfs_read_attribute(attr); if (ret) { |