diff options
Diffstat (limited to 'host')
-rw-r--r-- | host/arch/arm/lib/crossystem_arch.c | 4 | ||||
-rw-r--r-- | host/arch/x86/lib/crossystem_arch.c | 4 | ||||
-rw-r--r-- | host/include/crossystem.h | 15 | ||||
-rw-r--r-- | host/lib/crossystem.c | 6 | ||||
-rw-r--r-- | host/lib/include/crossystem_arch.h | 4 |
5 files changed, 27 insertions, 6 deletions
diff --git a/host/arch/arm/lib/crossystem_arch.c b/host/arch/arm/lib/crossystem_arch.c index 99b86897..b5422dec 100644 --- a/host/arch/arm/lib/crossystem_arch.c +++ b/host/arch/arm/lib/crossystem_arch.c @@ -5,6 +5,7 @@ #include <stdio.h> #include <string.h> +#include <stddef.h> #include <stdlib.h> #include <linux/fs.h> #include <sys/types.h> @@ -533,7 +534,8 @@ int VbGetArchPropertyInt(const char* name) { return -1; } -const char* VbGetArchPropertyString(const char* name, char* dest, int size) { +const char* VbGetArchPropertyString(const char* name, char* dest, + size_t size) { char *str = NULL; char *rv = NULL; char *prop = NULL; diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index 9398a35a..2b379a71 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -7,6 +7,7 @@ #include <dirent.h> #include <errno.h> #include <linux/nvram.h> +#include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> @@ -671,7 +672,8 @@ int VbGetArchPropertyInt(const char* name) { } -const char* VbGetArchPropertyString(const char* name, char* dest, int size) { +const char* VbGetArchPropertyString(const char* name, char* dest, + size_t size) { if (!strcasecmp(name,"arch")) { return StrCopy(dest, "x86", size); diff --git a/host/include/crossystem.h b/host/include/crossystem.h index c116b0c2..25b9cc0b 100644 --- a/host/include/crossystem.h +++ b/host/include/crossystem.h @@ -10,6 +10,12 @@ extern "C" { #endif +#include <stddef.h> + +/* Recommended size for string property buffers used with + * VbGetSystemPropertyString(). */ +#define VB_MAX_STRING_PROPERTY ((size_t) 8192) + /* Reads a system property integer. * * Returns the property value, or -1 if error. */ @@ -19,8 +25,12 @@ int VbGetSystemPropertyInt(const char* name); * specified size. Returned string will be null-terminated. If the * buffer is too small, the returned string will be truncated. * + * The caller can expect an un-truncated value if the size provided is + * at least VB_MAX_STRING_PROPERTY. + * * Returns the passed buffer, or NULL if error. */ -const char* VbGetSystemPropertyString(const char* name, char* dest, int size); +const char* VbGetSystemPropertyString(const char* name, char* dest, + size_t size); /* Sets a system property integer. * @@ -29,6 +39,9 @@ int VbSetSystemPropertyInt(const char* name, int value); /* Set a system property string. * + * The maximum length of the value accepted depends on the specific + * property, not on VB_MAX_STRING_PROPERTY. + * * Returns 0 if success, -1 if error. */ int VbSetSystemPropertyString(const char* name, const char* value); diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index b4824332..b4962591 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -3,6 +3,7 @@ * found in the LICENSE file. */ +#include <stddef.h> #include <stdio.h> #include <string.h> #include <sys/types.h> @@ -69,7 +70,7 @@ typedef enum VbBuildOption { /* Return true if the FWID starts with the specified string. */ int FwidStartsWith(const char *start) { - char fwid[128]; + char fwid[VB_MAX_STRING_PROPERTY]; if (!VbGetSystemPropertyString("fwid", fwid, sizeof(fwid))) return 0; @@ -492,7 +493,8 @@ int VbGetSystemPropertyInt(const char* name) { } -const char* VbGetSystemPropertyString(const char* name, char* dest, int size) { +const char* VbGetSystemPropertyString(const char* name, char* dest, + size_t size) { static const char unknown_string[] = "unknown"; /* Check architecture-dependent properties first */ diff --git a/host/lib/include/crossystem_arch.h b/host/lib/include/crossystem_arch.h index 4044c749..50198b07 100644 --- a/host/lib/include/crossystem_arch.h +++ b/host/lib/include/crossystem_arch.h @@ -8,6 +8,8 @@ #ifndef VBOOT_REFERENCE_CROSSYSTEM_ARCH_H_ #define VBOOT_REFERENCE_CROSSYSTEM_ARCH_H_ +#include <stddef.h> + #include "vboot_nvstorage.h" #include "vboot_struct.h" @@ -76,7 +78,7 @@ int VbGetArchPropertyInt(const char* name); * will be truncated. * * Returns the passed buffer, or NULL if error. */ -const char* VbGetArchPropertyString(const char* name, char* dest, int size); +const char* VbGetArchPropertyString(const char* name, char* dest, size_t size); /* Set an architecture-specific system property integer. * |