Skip to contentSkip to conversation

static analysis fixes

GIT PULL Dan Williams 2 participants 2 messages Dec 23, 2009 – Dec 30, 2009 MD RAID

lore
Share & tools
lore
#0 lore raw

Hi Neil, please pull from:

git://github.com/djbw/mdadm.git klockwork

...to receive a collection of static analysis fixes. These are independent of other recent development and can be pulled separately. Full diff below.

Thanks,
Dan

Artur Wojcik (16):
Fix for buffer overflow defect in 'link'. Fix for possible NULL pointer dereference. Fix for memory and resource leak.
Fix for NULL pointer dereference.
Fix for NULL pointer dereference.
Fix for buffer overflow defect.
Fix for NULL pointer dereference defect. Fix for NULL pointer dereference defect. Fix for NULL pointer dereference defect. Fix for memory leak defect.
Fix for memory leak defect.
Fix for memory leak defect.
Fix for buffer overflow error.
Fix for buffer overflow defect.
Fix for resource leak on error path. Fix required to enable RAID arrays on SAS disks.

Dan Williams (2):
imsm: no need to report the component device name from container_content
imsm: prune dead code in validate_geometry_imsm

 mdadm.h          |    7 ++++
 platform-intel.c |   10 ++++--
 probe_roms.c     |    8 +++--
 super-intel.c    |   83 +++++++++++++++++++++++++++++++----------------------
 sysfs.c          |   13 ++------
 5 files changed, 71 insertions(+), 50 deletions(-)
mdadm.h +7 -0
index c7f864b..fb243e5 100644
@@ -1001,3 +1001,10 @@ static inline int xasprintf(char **strp, const char *fmt, ...) {
 #define ALGORITHM_PARITY_0_6		20
 #define ALGORITHM_PARITY_N_6		ALGORITHM_PARITY_N
 
+/* Define PATH_MAX in case we don't use glibc or standard library does
+ * not have PATH_MAX defined. Assume max path length is 4K characters.
+ */
+#ifndef PATH_MAX
+#define PATH_MAX	4096
+#endif
+
platform-intel.c +7 -3
index d568ca6..30f7914 100644
@@ -44,7 +44,7 @@ void free_sys_dev(struct sys_dev **list)
 struct sys_dev *find_driver_devices(const char *bus, const char *driver)
 {
 	/* search sysfs for devices driven by 'driver' */
-	char path[256];
+	char path[292];
 	char link[256];
 	char *c;
 	DIR *driver_dir;
@@ -57,13 +57,17 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
 	if (!driver_dir)
 		return NULL;
 	for (de = readdir(driver_dir); de; de = readdir(driver_dir)) {
+		int n;
+
 		/* is 'de' a device? check that the 'subsystem' link exists and
 		 * that its target matches 'bus'
 		 */
 		sprintf(path, "/sys/bus/%s/drivers/%s/%s/subsystem",
 			bus, driver, de->d_name);
-		if (readlink(path, link, sizeof(link)) < 0)
+		n = readlink(path, link, sizeof(link));
+		if (n < 0 || n >= sizeof(link))
 			continue;
+		link[n] = '\0';
 		c = strrchr(link, '/');
 		if (!c)
 			continue;
@@ -202,7 +206,7 @@ const struct imsm_orom *find_imsm_orom(void)
 
 char *devt_to_devpath(dev_t dev)
 {
-	char device[40];
+	char device[46];
 
 	sprintf(device, "/sys/dev/block/%d:%d/device", major(dev), minor(dev));
 	return canonicalize_file_name(device);
probe_roms.c +5 -3
index a9a8638..0f0ffbc 100644
@@ -80,7 +80,7 @@ void probe_roms_exit(void)
 
 int probe_roms_init(unsigned long align)
 {
-	int fd;
+	int fd = -1;
 	int rc = 0;
 
 	/* valid values are 2048 and 512.  512 is for PCI-3.0 compliant
@@ -107,9 +107,11 @@ int probe_roms_init(unsigned long align)
 
 	if (rc == 0)
 		rom_fd = fd;
-	else
+	else {
+		if (fd >= 0) 
+			close(fd);
 		probe_roms_exit();
-
+	}
 	return rc;
 }
 
super-intel.c +48 -35

209 lines not on this page · raw message

sysfs.c +4 -9
index 35dfbd4..1d15ff6 100644
@@ -100,13 +100,8 @@ void sysfs_init(struct mdinfo *mdi, int fd, int devnum)
 
 struct mdinfo *sysfs_read(int fd, int devnum, unsigned long options)
 {
-	/* Longest possible name in sysfs, mounted at /sys, is
-	 *  /sys/block/md_dXXX/md/dev-XXXXX/block/dev
-	 *  /sys/block/md_dXXX/md/metadata_version
-	 * which is about 41 characters.  50 should do for now
-	 */
-	char fname[50];
-	char buf[1024];
+	char fname[PATH_MAX];
+	char buf[PATH_MAX];
 	char *base;
 	char *dbase;
 	struct mdinfo *sra;
@@ -574,8 +569,8 @@ int sysfs_set_array(struct mdinfo *info, int vers)
 
 int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int in_sync)
 {
-	char dv[100];
-	char nm[100];
+	char dv[PATH_MAX];
+	char nm[PATH_MAX];
 	char *dname;
 	int rv;
 
#1 lore raw
Quoted 7 lines · On Tue, 22 Dec 2009 17:09:38 -0700 Dan Williams <[email protected]>…

Hi Neil, please pull from:

git://github.com/djbw/mdadm.git klockwork

...to receive a collection of static analysis fixes. These are independent of other recent development and can be pulled separately. Full diff below.

I did get a conflict with validate_geometry_imsm_orom, but it was easily sorted out.

All pulled and pushed.

Thanks,
NeilBrown