summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2001-01-07 17:02:56 +0000
committerMarcus Brinkmann <marcus@gnu.org>2001-01-07 17:02:56 +0000
commitc39b618a82580064c268ac9c88b4fe414741a1ec (patch)
treedaa2e3d67d41ef58638a16b6bc55caa568225f25
parentfdca3f5c92c7f5f5928e03c9e879c81f764a0b6a (diff)
2000-12-21 Marcus Brinkmann <marcus@gnu.org>
* boot.c (main): If malloc or realloc fails, print diagnostic message and exit. (queue_read): Change return type from void to kern_return_t. If malloc fails, return D_NO_MEMORY, otherwise D_SUCCESS (to simplify code flow, malloc before acquiring the queuelock). (ds_device_read): New variable err (local to the block in which it is used). If queue_read fails, pass through error. (ds_device_read_inband): Likewise. (S_io_read): Likewise. Reported by Igor Khavkine <i_khavki@alcor.concordia.ca>.
-rw-r--r--boot/ChangeLog13
-rw-r--r--boot/boot.c36
2 files changed, 44 insertions, 5 deletions
diff --git a/boot/ChangeLog b/boot/ChangeLog
index 57cf1677..e39de84f 100644
--- a/boot/ChangeLog
+++ b/boot/ChangeLog
@@ -1,3 +1,16 @@
+2000-12-21 Marcus Brinkmann <marcus@gnu.org>
+
+ * boot.c (main): If malloc or realloc fails, print diagnostic
+ message and exit.
+ (queue_read): Change return type from void to kern_return_t.
+ If malloc fails, return D_NO_MEMORY, otherwise D_SUCCESS (to simplify
+ code flow, malloc before acquiring the queuelock).
+ (ds_device_read): New variable err (local to the block in which it is used).
+ If queue_read fails, pass through error.
+ (ds_device_read_inband): Likewise.
+ (S_io_read): Likewise.
+ Reported by Igor Khavkine <i_khavki@alcor.concordia.ca>.
+
2000-03-17 Roland McGrath <roland@baalperazim.frob.com>
* boot.c (S_io_reauthenticate): Check mach_port_insert_right result
diff --git a/boot/boot.c b/boot/boot.c
index dc5ea083..c3277816 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -540,6 +540,7 @@ main (int argc, char **argv, char **envp)
{
char *p, *line;
static const char filemsg[] = "Can't open boot script\n";
+ static const char memmsg[] = "Not enough memory\n";
int amt, fd, err;
fd = open (bootscript, O_RDONLY, 0);
@@ -549,6 +550,11 @@ main (int argc, char **argv, char **envp)
host_exit (1);
}
p = buf = malloc (500);
+ if (!buf)
+ {
+ write (2, memmsg, sizeof (memmsg));
+ host_exit (1);
+ }
len = 500;
amt = 0;
while (1)
@@ -564,6 +570,11 @@ main (int argc, char **argv, char **envp)
len += 500;
newbuf = realloc (buf, len);
+ if (!newbuf)
+ {
+ write (2, memmsg, sizeof (memmsg));
+ host_exit (1);
+ }
p = newbuf + (p - buf);
buf = newbuf;
}
@@ -850,7 +861,7 @@ struct qr
struct qr *qrhead, *qrtail;
/* Queue a read for later reply. */
-void
+kern_return_t
queue_read (enum read_type type,
mach_port_t reply_port,
mach_msg_type_name_t reply_type,
@@ -858,9 +869,12 @@ queue_read (enum read_type type,
{
struct qr *qr;
+ qr = malloc (sizeof (struct qr));
+ if (!qr)
+ return D_NO_MEMORY;
+
spin_lock (&queuelock);
- qr = malloc (sizeof (struct qr));
qr->type = type;
qr->reply_port = reply_port;
qr->reply_type = reply_type;
@@ -872,6 +886,7 @@ queue_read (enum read_type type,
qrhead = qrtail = qr;
spin_unlock (&queuelock);
+ return D_SUCCESS;
}
/* TRUE if there's data available on stdin, which should be used to satisfy
@@ -1194,8 +1209,12 @@ ds_device_read (device_t device,
}
else
{
+ kern_return_t err;
+
unlock_readlock ();
- queue_read (DEV_READ, reply_port, reply_type, bytes_wanted);
+ err = queue_read (DEV_READ, reply_port, reply_type, bytes_wanted);
+ if (err)
+ return err;
return MIG_NO_REPLY;
}
}
@@ -1244,8 +1263,12 @@ ds_device_read_inband (device_t device,
}
else
{
+ kern_return_t err;
+
unlock_readlock ();
- queue_read (DEV_READI, reply_port, reply_type, bytes_wanted);
+ err = queue_read (DEV_READI, reply_port, reply_type, bytes_wanted);
+ if (err)
+ return err;
return MIG_NO_REPLY;
}
}
@@ -1515,8 +1538,11 @@ S_io_read (mach_port_t object,
}
else
{
+ kern_return_t err;
unlock_readlock ();
- queue_read (IO_READ, reply_port, reply_type, amount);
+ err = queue_read (IO_READ, reply_port, reply_type, amount);
+ if (err)
+ return err;
return MIG_NO_REPLY;
}
}