From 30eb728e146dcc3c14ac10aaae97b9be73362e5e Mon Sep 17 00:00:00 2001 From: Dmitry Eremin Date: Wed, 26 Feb 2014 12:20:03 +0400 Subject: [PATCH] LU-4629 libcfs: fix issues found by Klocwork Insight tool sscanf format specification '%u' expects type 'unsigned int *' for 'u', but parameter 3 has a different type 'int*'. Pointer 'cfs_crypto_hash_type(d->hd_hash->ha_id)' returned from call to function 'cfs_crypto_hash_type' at line 261 may be NULL and will be dereferenced at line 261. Signed-off-by: Dmitry Eremin Change-Id: I9945a7e5d44329aa6417946106212cb269395290 Reviewed-on: http://review.whamcloud.com/9400 Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- libcfs/libcfs/linux/linux-cpu.c | 2 +- libcfs/libcfs/nidstrings.c | 16 ++++++++-------- libcfs/libcfs/user-crypto.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/libcfs/libcfs/linux/linux-cpu.c b/libcfs/libcfs/linux/linux-cpu.c index d0524da..ffdc440 100644 --- a/libcfs/libcfs/linux/linux-cpu.c +++ b/libcfs/libcfs/linux/linux-cpu.c @@ -923,7 +923,7 @@ cfs_cpt_table_create_pattern(char *pattern) break; } - if (sscanf(str, "%u%n", &cpt, &n) < 1) { + if (sscanf(str, "%d%n", &cpt, &n) < 1) { CERROR("Invalid cpu pattern %s\n", str); goto failed; } diff --git a/libcfs/libcfs/nidstrings.c b/libcfs/libcfs/nidstrings.c index 8235f0e..3c1b88e 100644 --- a/libcfs/libcfs/nidstrings.c +++ b/libcfs/libcfs/nidstrings.c @@ -313,11 +313,11 @@ libcfs_ip_addr2str(__u32 addr, char *str) int libcfs_ip_str2addr(const char *str, int nob, __u32 *addr) { - int a; - int b; - int c; - int d; - int n = nob; /* XscanfX */ + unsigned int a; + unsigned int b; + unsigned int c; + unsigned int d; + int n = nob; /* XscanfX */ /* numeric IP? */ if (sscanf(str, "%u.%u.%u.%u%n", &a, &b, &c, &d, &n) >= 4 && @@ -524,9 +524,9 @@ static struct netstrfns * libcfs_str2net_internal(const char *str, __u32 *net) { struct netstrfns *nf = NULL; - int nob; - int netnum; - int i; + int nob; + unsigned int netnum; + int i; for (i = 0; i < libcfs_nnetstrfns; i++) { nf = &libcfs_netstrfns[i]; diff --git a/libcfs/libcfs/user-crypto.c b/libcfs/libcfs/user-crypto.c index dd4c5dd..efc6782 100644 --- a/libcfs/libcfs/user-crypto.c +++ b/libcfs/libcfs/user-crypto.c @@ -257,9 +257,15 @@ int cfs_crypto_hash_update_page(struct cfs_crypto_hash_desc *desc, int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *desc, unsigned char *hash, unsigned int *hash_len) { + const struct cfs_crypto_hash_type *type; struct hash_desc *d = (struct hash_desc *)desc; - int size = (cfs_crypto_hash_type(d->hd_hash->ha_id))->cht_size; - int err; + int size; + int err; + + LASSERT(d != NULL); + type = cfs_crypto_hash_type(d->hd_hash->ha_id); + LASSERT(type != NULL); + size = type->cht_size; if (hash_len == NULL) { kfree(d); @@ -273,8 +279,8 @@ int cfs_crypto_hash_final(struct cfs_crypto_hash_desc *desc, LASSERT(d->hd_hash->final != NULL); err = d->hd_hash->final(d->hd_ctx, hash, *hash_len); if (err == 0) { - /* If get final digest success free hash descriptor */ - kfree(d); + /* If get final digest success free hash descriptor */ + kfree(d); } return err; -- 1.8.3.1