summaryrefslogtreecommitdiffstats
path: root/src/core/settings.c
diff options
context:
space:
mode:
authorMichael Brown2013-08-12 19:23:25 +0200
committerMichael Brown2013-08-12 19:25:18 +0200
commit55daa953fb82412e2e4dced4a39c6f7a3ff39b46 (patch)
tree0ecd41cdad183030d25a047224b51a399adb0b7a /src/core/settings.c
parent[test] Add self-tests for snprintf() (diff)
downloadipxe-55daa953fb82412e2e4dced4a39c6f7a3ff39b46.tar.gz
ipxe-55daa953fb82412e2e4dced4a39c6f7a3ff39b46.tar.xz
ipxe-55daa953fb82412e2e4dced4a39c6f7a3ff39b46.zip
[settings] Allow numeric_setting_value() to handle long setting values
Allow numeric_setting_value() to handle e.g. the byte sequence 00:00:00:00:12:34:56:78 by returning -ERANGE only if the value actually overflows the return type. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/settings.c')
-rw-r--r--src/core/settings.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/core/settings.c b/src/core/settings.c
index 889e1078..87de0d1b 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -862,18 +862,18 @@ static int numeric_setting_value ( int is_signed, const void *raw, size_t len,
const int8_t *signed_bytes = raw;
int is_negative;
unsigned int i;
+ uint8_t pad;
uint8_t byte;
- /* Range check */
- if ( len > sizeof ( long ) )
- return -ERANGE;
-
/* Convert to host-ordered longs */
is_negative = ( len && ( signed_bytes[0] < 0 ) );
*value = ( ( is_signed && is_negative ) ? -1L : 0 );
+ pad = *value;
for ( i = 0 ; i < len ; i++ ) {
byte = unsigned_bytes[i];
*value = ( ( *value << 8 ) | byte );
+ if ( ( ( i + sizeof ( *value ) ) < len ) && ( byte != pad ) )
+ return -ERANGE;
}
return len;