From 17b12ee1837671075b255c7703416db017d517e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 18 Oct 2008 19:03:19 +0200 Subject: Add extra parameter consistent with samba3. --- lib/util/util.h | 2 +- lib/util/util_str.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/util') diff --git a/lib/util/util.h b/lib/util/util.h index 38b59862fc6..4c9a2230937 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -236,7 +236,7 @@ _PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength); **/ -_PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex); +_PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len); /** * Parse a hex string and return a data blob. diff --git a/lib/util/util_str.c b/lib/util/util_str.c index afa772a8a81..c105e1d58f5 100644 --- a/lib/util/util_str.c +++ b/lib/util/util_str.c @@ -178,7 +178,7 @@ _PUBLIC_ char *safe_strcat(char *dest, const char *src, size_t maxlength) **/ -_PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) +_PUBLIC_ size_t strhex_to_str(char *p, size_t p_len, const char *strhex, size_t strhex_len) { size_t i; size_t num_chars = 0; @@ -186,7 +186,7 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) const char *hexchars = "0123456789ABCDEF"; char *p1 = NULL, *p2 = NULL; - for (i = 0; i < len && strhex[i] != 0; i++) { + for (i = 0; i < strhex_len && strhex[i] != 0; i++) { if (strncasecmp(hexchars, "0x", 2) == 0) { i++; /* skip two chars */ continue; @@ -204,6 +204,10 @@ _PUBLIC_ size_t strhex_to_str(char *p, size_t len, const char *strhex) hinybble = PTR_DIFF(p1, hexchars); lonybble = PTR_DIFF(p2, hexchars); + if (num_chars >= p_len) { + break; + } + p[num_chars] = (hinybble << 4) | lonybble; num_chars++; @@ -220,9 +224,9 @@ _PUBLIC_ _PURE_ DATA_BLOB strhex_to_data_blob(TALLOC_CTX *mem_ctx, const char *s { DATA_BLOB ret_blob = data_blob(mem_ctx, strlen(strhex)/2+1); - ret_blob.length = strhex_to_str((char *)ret_blob.data, - strlen(strhex), - strhex); + ret_blob.length = strhex_to_str((char *)ret_blob.data, ret_blob.length, + strhex, + strlen(strhex)); return ret_blob; } -- cgit v1.2.1