Date: Sat, 26 Jan 2013 20:16:58 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r245948 - head/sys/arm/arm Message-ID: <201301262016.r0QKGwu9038214@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Sat Jan 26 20:16:58 2013 New Revision: 245948 URL: http://svnweb.freebsd.org/changeset/base/245948 Log: Fix a buffer overrun while pre-formatting the names array, perpetrated in the prior commit. Use essentially the same sprintf() statement for both formatting and pre-formatting, and use a format string which eliminates the need for an extra temporary buffer when formatting the name. Noted by: Christoph Mallon Pointy hat to: ian Approved by: cognet (mentor) Modified: head/sys/arm/arm/intr.c Modified: head/sys/arm/arm/intr.c ============================================================================== --- head/sys/arm/arm/intr.c Sat Jan 26 13:44:24 2013 (r245947) +++ head/sys/arm/arm/intr.c Sat Jan 26 20:16:58 2013 (r245948) @@ -68,13 +68,13 @@ void (*arm_post_filter)(void *) = NULL; * consumers of this data. */ void -arm_intrnames_init() +arm_intrnames_init(void) { int i; - memset(intrnames, ' ', NIRQ * INTRNAME_LEN); for (i = 0; i < NIRQ; ++i) - intrnames[i * INTRNAME_LEN - 1] = 0; + snprintf(&intrnames[i * INTRNAME_LEN], INTRNAME_LEN, "%-*s", + INTRNAME_LEN - 1, ""); } void @@ -83,7 +83,6 @@ arm_setup_irqhandler(const char *name, d { struct intr_event *event; int error; - char namebuf[INTRNAME_LEN]; if (irq < 0 || irq >= NIRQ) return; @@ -95,9 +94,8 @@ arm_setup_irqhandler(const char *name, d if (error) return; intr_events[irq] = event; - snprintf(namebuf, sizeof(namebuf), "irq%d: %s", irq, name); - sprintf(intrnames + INTRNAME_LEN * irq, "%-*s", - INTRNAME_LEN - 1, namebuf); + snprintf(&intrnames[irq * INTRNAME_LEN], INTRNAME_LEN, "%-*s", + INTRNAME_LEN - 1, name); } intr_event_add_handler(event, name, filt, hand, arg, intr_priority(flags), flags, cookiep);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301262016.r0QKGwu9038214>