mirror of
https://github.com/samba-team/samba.git
synced 2025-01-20 14:03:59 +03:00
ctdb:utils: Improve error handling of hex_decode()
This has been found by covscan and make analyzers happy. Pair-programmed-with: Andreas Schneider <asn@samba.org> Signed-off-by: Pavel Filipenský <pfilipen@redhat.com> Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
41c86c9dda
commit
5ac8762256
@ -30,30 +30,42 @@
|
|||||||
#include "lib/tdb/common/tdb_private.h"
|
#include "lib/tdb/common/tdb_private.h"
|
||||||
#include "lib/tdb/common/mutex.c"
|
#include "lib/tdb/common/mutex.c"
|
||||||
|
|
||||||
static uint8_t *hex_decode(const char *hex_in, size_t *len)
|
static uint8_t *hex_decode(const char *hex_in, size_t *plen)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int num;
|
int num;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
*len = strlen(hex_in) / 2;
|
len = strlen(hex_in) / 2;
|
||||||
buffer = malloc(*len);
|
if (len == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i<*len; i++) {
|
buffer = malloc(len);
|
||||||
|
if (buffer == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
sscanf(&hex_in[i*2], "%02X", &num);
|
sscanf(&hex_in[i*2], "%02X", &num);
|
||||||
buffer[i] = (uint8_t)num;
|
buffer[i] = (uint8_t)num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*plen = len;
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_hash_chain(struct tdb_context *tdb, const char *hex_key)
|
static int get_hash_chain(struct tdb_context *tdb, const char *hex_key)
|
||||||
{
|
{
|
||||||
TDB_DATA key;
|
TDB_DATA key = {
|
||||||
|
.dsize = 0,
|
||||||
|
};
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
|
|
||||||
key.dptr = hex_decode(hex_key, &key.dsize);
|
key.dptr = hex_decode(hex_key, &key.dsize);
|
||||||
if (key.dsize == 0) {
|
if (key.dptr == NULL || key.dsize == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
hash = tdb_jenkins_hash(&key);
|
hash = tdb_jenkins_hash(&key);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user