bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
...
return (len == 0 && *hexstr == 0) ? true : false;
}
Should the return value not be || rather than &&?
I think the code is correct. It also checks input parameters.
If size of buffer (p) is too small for a given hex str,the caller would know that something is wrong.
If the hexStr is truncated to size less than buffer (p) length, the caller would know.
For example: if hexStr points to 32 hex numbers, but the size of buffer pointed by p is 64, the function would return false.
If you had || instead of &&, the function would return true and the caller would assume that there are 64 valid (0-255) bytes.
If you had a prototype:
bool hex2bin(unsigned char *buf, int bufSize, const char *hexstr, int * outlen)
it would allow callers to check the size of the converted binary buffer.
Thing is, the BFL uses hex2bin the other way round: the string is longer than p. The BFL returns a string of nonces, hex2bin is used to extract these nonces. There's no null terminator on each nonce, so hex2bin is returning an error, even though everything is fine.
Not sure which version of driver-bitforce.c you are looking at but 2.4.1 does not check return code from hex2bin().