summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <david@fubar.dk>2005-01-21 15:46:55 +0000
committerDavid Zeuthen <david@fubar.dk>2005-01-21 15:46:55 +0000
commit6d887248474e48815dbbec86ea2415ad78c7b565 (patch)
tree9502331f096102bb8824037f91ac3ce5e6d481a6
parent0fe6a6ddd80f6d104df6b883a9140c0ff32772e6 (diff)
Check for return value to avoid dereferencing a NULL pointer
Only do drive_id real SCSI since doing an INQUIRY on USB devices may crash the device if the transfer length is not exactly 36 bytes. Remove the #define DEBUG symbol again Add linux/pcmcia_bus_device.c New file Add support for 16-bit PCMCIA in sysfs; without this hald won't work for 16-bit PCMCIA cards and a kernel with sysfs support for those.
-rw-r--r--ChangeLog20
-rw-r--r--hald/Makefile.am1
-rw-r--r--hald/linux/block_class_device.c35
-rw-r--r--hald/linux/libsysfs/sysfs.h1
-rw-r--r--hald/linux/osspec.c2
-rw-r--r--hald/linux/pcmcia_bus_device.c93
-rw-r--r--tools/fstab-sync.c2
7 files changed, 141 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 43bed3c2..649dc126 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2005-01-21 David Zeuthen <davidz@redhat.com>
+
+ * tools/fstab-sync.c (remove_udi): Check for return value to
+ avoid dereferencing a NULL pointer
+
+ * hald/linux/block_class_device.c (block_class_pre_process): Only
+ do drive_id real SCSI since doing an INQUIRY on USB devices may
+ crash the device if the transfer length is not exactly 36 bytes.
+
+ * hald/linux/libsysfs/sysfs.h: Remove the #define DEBUG symbol
+ again
+
+ * hald/Makefile.am (hald_SOURCES): Add linux/pcmcia_bus_device.c
+
+ * hald/linux/pcmcia_bus_device.c: New file
+
+ * hald/linux/osspec.c: Add support for 16-bit PCMCIA in sysfs;
+ without this hald won't work for 16-bit PCMCIA cards and a
+ kernel with sysfs support for those.
+
2005-01-20 David Zeuthen <davidz@redhat.com>
* NEWS: Update for 0.4.6
diff --git a/hald/Makefile.am b/hald/Makefile.am
index 34510e85..f8476c28 100644
--- a/hald/Makefile.am
+++ b/hald/Makefile.am
@@ -48,6 +48,7 @@ hald_SOURCES += \
linux/ide_bus_device.c \
linux/pcmcia_socket_class_device.c \
linux/macio_bus_device.c \
+ linux/pcmcia_bus_device.c \
linux/ieee1394_class_device.c \
linux/ieee1394_node_class_device.c \
linux/ieee1394_host_class_device.c \
diff --git a/hald/linux/block_class_device.c b/hald/linux/block_class_device.c
index 8a63efe8..02e58519 100644
--- a/hald/linux/block_class_device.c
+++ b/hald/linux/block_class_device.c
@@ -1462,6 +1462,7 @@ block_class_pre_process (ClassDeviceHandler *self,
device_file = hal_device_property_get_string (d, "block.device");
did = drive_id_open_node(device_file);
+
if (drive_id_probe(did, DRIVE_ID_ATA) == 0) {
if (did->serial[0] != '\0')
hal_device_property_set_string (stordev, "storage.serial", did->serial);
@@ -1511,18 +1512,28 @@ block_class_pre_process (ClassDeviceHandler *self,
}
device_file = hal_device_property_get_string (d, "block.device");
- did = drive_id_open_node(device_file);
- if (drive_id_probe(did, DRIVE_ID_SCSI) == 0) {
- if (did->serial[0] != '\0')
- hal_device_property_set_string (stordev,
- "storage.serial",
- did->serial);
- if (did->revision[0] != '\0')
- hal_device_property_set_string (stordev,
- "storage.revision",
- did->revision);
- }
- drive_id_close(did);
+
+ /* Only do drive_id on real SCSI devices - not on USB which uses emulated SCSI
+ * since an INQUIRY on most USB devices may crash the storage device if the
+ * transfer length isn't exactly 36 bytes.
+ *
+ * (See also Red Hat bug #145256)
+ */
+ if (strcmp (hal_device_property_get_string (stordev, "storage.bus"), "scsi") == 0) {
+
+ did = drive_id_open_node(device_file);
+ if (drive_id_probe(did, DRIVE_ID_SCSI) == 0) {
+ if (did->serial[0] != '\0')
+ hal_device_property_set_string (stordev,
+ "storage.serial",
+ did->serial);
+ if (did->revision[0] != '\0')
+ hal_device_property_set_string (stordev,
+ "storage.revision",
+ did->revision);
+ }
+ drive_id_close(did);
+ }
/* see if this is really a SATA disk */
#if 0
diff --git a/hald/linux/libsysfs/sysfs.h b/hald/linux/libsysfs/sysfs.h
index 785ef9c7..4ef8c287 100644
--- a/hald/linux/libsysfs/sysfs.h
+++ b/hald/linux/libsysfs/sysfs.h
@@ -37,7 +37,6 @@
extern int isascii(int c);
/* Debugging */
-#define DEBUG
#ifdef DEBUG
#define dprintf(format, arg...) fprintf(stderr, format, ## arg)
#else
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 0edf1d91..9d7b8ae0 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -90,6 +90,7 @@ extern BusDeviceHandler ide_host_bus_handler;
extern BusDeviceHandler ide_bus_handler;
extern BusDeviceHandler scsi_bus_handler;
extern BusDeviceHandler macio_bus_handler;
+extern BusDeviceHandler pcmcia_bus_handler;
extern BusDeviceHandler platform_bus_handler;
extern BusDeviceHandler usb_serial_bus_handler;
@@ -123,6 +124,7 @@ static BusDeviceHandler* bus_device_handlers[] = {
&ide_host_bus_handler,
&ide_bus_handler,
&macio_bus_handler,
+ &pcmcia_bus_handler,
&platform_bus_handler,
&scsi_bus_handler,
&usb_serial_bus_handler,
diff --git a/hald/linux/pcmcia_bus_device.c b/hald/linux/pcmcia_bus_device.c
new file mode 100644
index 00000000..78656d0c
--- /dev/null
+++ b/hald/linux/pcmcia_bus_device.c
@@ -0,0 +1,93 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * PCMCIA bus device
+ *
+ * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
+ *
+ * Licensed under the Academic Free License version 2.0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <getopt.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdarg.h>
+
+#include "../logger.h"
+#include "../device_store.h"
+#include "bus_device.h"
+#include "common.h"
+
+/**
+ * @defgroup HalDaemonLinuxIde IDE
+ * @ingroup HalDaemonLinux
+ * @brief IDE
+ * @{
+ */
+
+
+static char *
+pcmcia_device_compute_udi (HalDevice *d, int append_num)
+{
+ static char buf[256];
+
+ if (append_num == -1)
+ sprintf (buf, "/org/freedesktop/Hal/devices/pcmcia_%s",
+ hal_device_property_get_string (d, "pcmcia.bus_id"));
+ else
+ sprintf (buf, "/org/freedesktop/Hal/devices/pcmcia_%s/%d",
+ hal_device_property_get_string (d, "pcmcia.bus_id"),
+ append_num);
+
+ return buf;
+}
+
+static void
+pcmcia_device_pre_process (BusDeviceHandler *self,
+ HalDevice *d,
+ const char *sysfs_path,
+ struct sysfs_device *device)
+{
+ hal_device_property_set_string (d, "pcmcia.bus_id", device->bus_id);
+}
+
+BusDeviceHandler pcmcia_bus_handler = {
+ bus_device_init, /**< init function */
+ bus_device_shutdown, /**< shutdown function */
+ bus_device_tick, /**< timer function */
+ bus_device_accept, /**< accept function */
+ bus_device_visit, /**< visitor function */
+ bus_device_removed, /**< device is removed */
+ pcmcia_device_compute_udi, /**< UDI computing function */
+ pcmcia_device_pre_process, /**< add more properties */
+ bus_device_got_udi, /**< got UDI */
+ bus_device_in_gdl, /**< in GDL */
+ "pcmcia", /**< sysfs bus name */
+ "pcmcia" /**< namespace */
+};
+
+
+/** @} */
diff --git a/tools/fstab-sync.c b/tools/fstab-sync.c
index aab84710..490eb774 100644
--- a/tools/fstab-sync.c
+++ b/tools/fstab-sync.c
@@ -1417,6 +1417,8 @@ remove_udi (const char *udi)
return FALSE;
block_device = hal_device_get_property_string (hal_context, udi, "block.device");
+ if (block_device == NULL)
+ return FALSE;
dir = strdup (_PATH_FSTAB);
last_slash = strrchr (dir, '/');