**/
-_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.
**/
-_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;
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;
hinybble = PTR_DIFF(p1, hexchars);
lonybble = PTR_DIFF(p2, hexchars);
+ if (num_chars >= p_len) {
+ break;
+ }
+
p[num_chars] = (hinybble << 4) | lonybble;
num_chars++;
{
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;
}