diff options
author | dd <dd@FreeBSD.org> | 2001-07-02 00:18:04 +0000 |
---|---|---|
committer | dd <dd@FreeBSD.org> | 2001-07-02 00:18:04 +0000 |
commit | 4a798fb83a60241d607536db8b69d9709995a803 (patch) | |
tree | eb3e6d3ae80fce772bbe283df44e815263d1b83f /usr.sbin/sade | |
parent | b1763d41ddf8b57a46b69e3e8423b9d57392bd6a (diff) | |
download | FreeBSD-src-4a798fb83a60241d607536db8b69d9709995a803.zip FreeBSD-src-4a798fb83a60241d607536db8b69d9709995a803.tar.gz |
Introduce DEVICE_INIT, DEVICE_GET, and DEVICE_SHUTDOWN macros. As the
names suggest, they perform methods on Device's. In addition, they
check that the pointer passed to them is valid; if it isn't, they
pretend that the action failed. This fixes some crashes due to NULL
dereferences (e.g., PR 26509).
Approved by: jkh (some time ago)
Diffstat (limited to 'usr.sbin/sade')
-rw-r--r-- | usr.sbin/sade/devices.c | 2 | ||||
-rw-r--r-- | usr.sbin/sade/dispatch.c | 4 | ||||
-rw-r--r-- | usr.sbin/sade/install.c | 11 | ||||
-rw-r--r-- | usr.sbin/sade/sade.h | 7 |
4 files changed, 16 insertions, 8 deletions
diff --git a/usr.sbin/sade/devices.c b/usr.sbin/sade/devices.c index 484a3d6..aa98bd0 100644 --- a/usr.sbin/sade/devices.c +++ b/usr.sbin/sade/devices.c @@ -236,7 +236,7 @@ deviceReset(void) int i; for (i = 0; i < numDevs; i++) { - Devices[i]->shutdown(Devices[i]); + DEVICE_SHUTDOWN(Devices[i]); /* XXX this potentially leaks Devices[i]->private if it's being * used to point to something dynamic, but you're not supposed diff --git a/usr.sbin/sade/dispatch.c b/usr.sbin/sade/dispatch.c index cd64bf0..6373476 100644 --- a/usr.sbin/sade/dispatch.c +++ b/usr.sbin/sade/dispatch.c @@ -406,14 +406,14 @@ dispatch_load_floppy(dialogMenuItem *self) return what; } - if (!mediaDevice->init(mediaDevice)) { + if (!DEVICE_INIT(mediaDevice)) { msgConfirm("Unable to mount floppy filesystem."); what |= DITEM_FAILURE; mediaClose(); return what; } - fp = mediaDevice->get(mediaDevice, cp, TRUE); + fp = DEVICE_GET(mediaDevice, cp, TRUE); if (fp) { list = dispatch_load_fp(fp); fclose(fp); diff --git a/usr.sbin/sade/install.c b/usr.sbin/sade/install.c index d5820a6..3d8539f 100644 --- a/usr.sbin/sade/install.c +++ b/usr.sbin/sade/install.c @@ -269,8 +269,9 @@ installFixitCDROM(dialogMenuItem *self) (void)rmdir("/mnt2"); while (1) { - msgConfirm("Please insert a FreeBSD live filesystem CD/DVD and press return"); - if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS || !mediaDevice || !mediaDevice->init(mediaDevice)) { + msgConfirm("Please insert a FreeBSD live filesystem CDROM and press return"); + if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS + || !DEVICE_INIT(mediaDevice)) { /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */ mediaClose(); if (msgYesNo("Unable to mount the disc - do you want to try again?") != 0) @@ -357,7 +358,7 @@ installFixitFloppy(dialogMenuItem *self) variable_set2(SYSTEM_STATE, "fixit", 0); while (1) { - if (!mediaDevice->init(mediaDevice)) { + if (!DEVICE_INIT(mediaDevice)) { if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n" "or unclean filesystem. Do you want to try again?")) return DITEM_FAILURE; @@ -562,7 +563,7 @@ nodisks: Device *tmp = tcpDeviceSelect(); if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) - if (!tmp->init(tmp)) + if (!DEVICE_INIT(tmp)) msgConfirm("Initialization of %s device failed.", tmp->name); } dialog_clear_norefresh(); @@ -702,7 +703,7 @@ installCommit(dialogMenuItem *self) return i; try_media: - if (!mediaDevice->init(mediaDevice)) { + if (!DEVICE_INIT(mediaDevice)) { if (!msgYesNo("Unable to initialize selected media. Would you like to\n" "adjust your media configuration and try again?")) { mediaDevice = NULL; diff --git a/usr.sbin/sade/sade.h b/usr.sbin/sade/sade.h index b8cf0e1..0f8fd75 100644 --- a/usr.sbin/sade/sade.h +++ b/usr.sbin/sade/sade.h @@ -770,5 +770,12 @@ extern int dump_variables(dialogMenuItem *self); /* wizard.c */ extern void slice_wizard(Disk *d); +/* + * Macros. Please find a better place for us! + */ +#define DEVICE_INIT(d) ((d) != NULL ? (d)->init((d)) : NULL) +#define DEVICE_GET(d, b, f) ((d) != NULL ? (d)->get((d), (b), (f)) : NULL) +#define DEVICE_SHUTDOWN(d) ((d) != NULL ? (d)->shutdown((d)) : (void)0) + #endif /* _SYSINSTALL_H_INCLUDE */ |