Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Ensure that the return string is NUL-terminated...



details:   https://anonhg.NetBSD.org/src/rev/42510e16a70d
branches:  trunk
changeset: 750905:42510e16a70d
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Jan 18 17:34:37 2010 +0000

description:
Ensure that the return string is NUL-terminated in acpi_eval_string().

ok jmcneill@, pgoyette@

diffstat:

 sys/dev/acpi/acpi.c |  48 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 31 insertions(+), 17 deletions(-)

diffs (75 lines):

diff -r 6cfab6ac6b6c -r 42510e16a70d sys/dev/acpi/acpi.c
--- a/sys/dev/acpi/acpi.c       Mon Jan 18 17:11:00 2010 +0000
+++ b/sys/dev/acpi/acpi.c       Mon Jan 18 17:34:37 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi.c,v 1.144 2010/01/12 12:21:04 jruoho Exp $        */
+/*     $NetBSD: acpi.c,v 1.145 2010/01/18 17:34:37 jruoho Exp $        */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.144 2010/01/12 12:21:04 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.145 2010/01/18 17:34:37 jruoho Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -1189,27 +1189,41 @@
 ACPI_STATUS
 acpi_eval_string(ACPI_HANDLE handle, const char *path, char **stringp)
 {
+       ACPI_OBJECT *obj;
+       ACPI_BUFFER buf;
        ACPI_STATUS rv;
-       ACPI_BUFFER buf;
+
+       rv = acpi_eval_struct(handle, path, &buf);
 
-       if (handle == NULL)
-               handle = ACPI_ROOT_OBJECT;
+       if (ACPI_FAILURE(rv))
+               return rv;
+
+       obj = buf.Pointer;
 
-       buf.Pointer = NULL;
-       buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+       if (obj->Type != ACPI_TYPE_STRING) {
+               rv = AE_TYPE;
+               goto out;
+       }
 
-       rv = AcpiEvaluateObjectTyped(handle, path, NULL, &buf, ACPI_TYPE_STRING);
-       if (ACPI_SUCCESS(rv)) {
-               ACPI_OBJECT *param = buf.Pointer;
-               const char *ptr = param->String.Pointer;
-               size_t len = param->String.Length;
-               if ((*stringp = ACPI_ALLOCATE(len)) == NULL)
-                       rv = AE_NO_MEMORY;
-               else
-                       (void)memcpy(*stringp, ptr, len);
-               ACPI_FREE(param);
+       if (obj->String.Length == 0) {
+               rv = AE_BAD_DATA;
+               goto out;
        }
 
+       *stringp = ACPI_ALLOCATE(obj->String.Length + 1);
+
+       if (*stringp == NULL) {
+               rv = AE_NO_MEMORY;
+               goto out;
+       }
+
+       (void)memcpy(*stringp, obj->String.Pointer, obj->String.Length);
+
+       (*stringp)[obj->String.Length] = '\0';
+
+out:
+       ACPI_FREE(buf.Pointer);
+
        return rv;
 }
 



Home | Main Index | Thread Index | Old Index