Whamcloud - gitweb
LU-4629 libcfs: fix issues found by Klocwork Insight tool 00/9400/7
authorDmitry Eremin <dmitry.eremin@intel.com>
Wed, 26 Feb 2014 08:20:03 +0000 (12:20 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 25 Mar 2014 18:49:25 +0000 (18:49 +0000)
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 <dmitry.eremin@intel.com>
Change-Id: I9945a7e5d44329aa6417946106212cb269395290
Reviewed-on: http://review.whamcloud.com/9400
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/libcfs/linux/linux-cpu.c
libcfs/libcfs/nidstrings.c
libcfs/libcfs/user-crypto.c

index d0524da..ffdc440 100644 (file)
@@ -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;
                }
index 8235f0e..3c1b88e 100644 (file)
@@ -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];
index dd4c5dd..efc6782 100644 (file)
@@ -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;