[CIFS] Fix potential NULL pointer usage if kzalloc fails
authorSteve French <sfrench@us.ibm.com>
Sat, 15 Sep 2007 03:01:17 +0000 (03:01 +0000)
committerSteve French <sfrench@us.ibm.com>
Sat, 15 Sep 2007 03:01:17 +0000 (03:01 +0000)
Potential problem was noticed by Cyrill Gorcunov

CC: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Steve French <sfrench@us.ibm.com>
fs/cifs/cifs_debug.c
fs/cifs/connect.c

index 1bf8cf522ad668a2832f095f1b75aaf40a7fde0a..0356694b5cd0c8b249b94f4c233053ba76f2de90 100644 (file)
@@ -209,13 +209,15 @@ cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
                i++;
                tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
                dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
-               length =
-                   sprintf(buf,
-                           "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x "
-                           "Attributes: 0x%x\nPathComponentMax: %d Status: %d",
-                           i, tcon->treeName,
-                           atomic_read(&tcon->useCount),
-                           tcon->nativeFileSystem,
+               length = sprintf(buf, "\n%d) %s Uses: %d ", i,
+                                tcon->treeName, atomic_read(&tcon->useCount));
+               buf += length;
+               if (tcon->nativeFileSystem) {
+                       length = sprintf("Type: %s ", tcon->nativeFileSystem);
+                       buf += length;
+               }
+               length = sprintf(buf, "DevInfo: 0x%x Attributes: 0x%x"
+                                "\nPathComponentMax: %d Status: %d",
                            le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
                            le32_to_cpu(tcon->fsAttrInfo.Attributes),
                            le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
index a83684d8eb5a9e4f4b71d3da37c76db0a92cf401..5f2ec1946776c743203f35d35c53a724b901bbd1 100644 (file)
@@ -3386,9 +3386,11 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                                kfree(tcon->nativeFileSystem);
                                tcon->nativeFileSystem =
                                    kzalloc(length + 2, GFP_KERNEL);
-                               cifs_strfromUCS_le(tcon->nativeFileSystem,
-                                                  (__le16 *) bcc_ptr,
-                                                  length, nls_codepage);
+                               if (tcon->nativeFileSystem)
+                                       cifs_strfromUCS_le(
+                                               tcon->nativeFileSystem,
+                                               (__le16 *) bcc_ptr,
+                                               length, nls_codepage);
                                bcc_ptr += 2 * length;
                                bcc_ptr[0] = 0; /* null terminate the string */
                                bcc_ptr[1] = 0;
@@ -3403,8 +3405,9 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                                kfree(tcon->nativeFileSystem);
                                tcon->nativeFileSystem =
                                    kzalloc(length + 1, GFP_KERNEL);
-                               strncpy(tcon->nativeFileSystem, bcc_ptr,
-                                       length);
+                               if (tcon->nativeFileSystem)
+                                       strncpy(tcon->nativeFileSystem, bcc_ptr,
+                                               length);
                        }
                        /* else do not bother copying these information fields*/
                }