bin/83451: [ PATCH ] improper handling of malloc failures within
libusbhid
Dan Lukes
dan at obluda.cz
Thu Jul 14 12:40:17 GMT 2005
>Number: 83451
>Category: bin
>Synopsis: [ PATCH ] improper handling of malloc failures within libusbhid
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Jul 14 12:40:16 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Dan Lukes
>Release: FreeBSD 5.4-STABLE i386
>Organization:
Obludarium
>Environment:
System: FreeBSD 5.4-STABLE #8: Sat Jul 9 16:31:08 CEST 2005 i386
lib/libusbhid/parse.c,v 1.10 2004/02/11 21:09:13 emax
lib/libusbhid/Makefile,v 1.8 2003/04/09 01:52:48 mdodd
>Description:
Improper handling of malloc failures within libusbhid
WARNS can be raised to 6
>How-To-Repeat:
>Fix:
--- patch begins here ---
--- lib/libusbhid/parse.c.ORIG Wed Feb 25 22:05:47 2004
+++ lib/libusbhid/parse.c Thu Jul 14 13:33:25 2005
@@ -93,8 +93,8 @@
{
struct hid_data *s;
- s = malloc(sizeof *s);
- memset(s, 0, sizeof *s);
+ if ((s = calloc(1, sizeof *s)) == NULL)
+ return(NULL);
s->start = s->p = d->data;
s->end = d->data + d->size;
s->kindset = kindset;
@@ -346,6 +346,8 @@
break;
case 10: /* Push */
hi = malloc(sizeof *hi);
+ if (hi == NULL)
+ return(-6);
*hi = s->cur;
c->next = hi;
break;
@@ -413,7 +415,10 @@
memset(&h, 0, sizeof h);
size = 0;
- for (d = hid_start_parse(r, 1<<k, id); hid_get_item(d, &h); ) {
+ d = hid_start_parse(r, 1<<k, id);
+ if (d == NULL)
+ return(-1);
+ for ( ; hid_get_item(d, &h); ) {
if (h.report_ID == id && h.kind == k) {
size = d->kindpos[k];
}
@@ -428,13 +433,17 @@
{
hid_data_t d;
- for (d = hid_start_parse(desc, 1<<k, id); hid_get_item(d, h); ) {
+ d = hid_start_parse(desc, 1<<k, id);
+ if (d == NULL)
+ goto err;
+ for ( ; hid_get_item(d, h); ) {
if (h->kind == k && !(h->flags & HIO_CONST) && h->usage == u) {
hid_end_parse(d);
return (1);
}
}
hid_end_parse(d);
+err:
h->report_size = 0;
return (0);
}
--- lib/libusbhid/Makefile.ORIG Sun Apr 13 20:10:31 2003
+++ lib/libusbhid/Makefile Thu Jul 14 13:26:23 2005
@@ -21,4 +21,6 @@
INCS= usbhid.h
+WARNS+= 6
+
.include <bsd.lib.mk>
--- patch ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list