diff --git a/devicemodel/core/inout.c b/devicemodel/core/inout.c index a16f3db5a..4855eb62d 100644 --- a/devicemodel/core/inout.c +++ b/devicemodel/core/inout.c @@ -28,10 +28,8 @@ #include #include -#include #include "inout.h" - SET_DECLARE(inout_port_set, struct inout_port); #define MAX_IOPORTS (1 << 16) @@ -99,8 +97,9 @@ emulate_inout(struct vmctx *ctx, int *pvcpu, struct pio_request *pio_request) in = (pio_request->direction == REQUEST_READ); port = pio_request->address; - assert(port + bytes - 1 < MAX_IOPORTS); - assert(bytes == 1 || bytes == 2 || bytes == 4); + if ((port + bytes - 1 >= MAX_IOPORTS) || + ((bytes != 1) && (bytes != 2) && (bytes != 4))) + return -1; handler = inout_handlers[port].handler; flags = inout_handlers[port].flags; @@ -133,7 +132,11 @@ init_inout(void) */ SET_FOREACH(iopp, inout_port_set) { iop = *iopp; - assert(iop->port < MAX_IOPORTS); + if (iop->port >= MAX_IOPORTS) { + printf("%s: invalid port:0x%x", __func__, iop->port); + continue; + } + inout_handlers[iop->port].name = iop->name; inout_handlers[iop->port].flags = iop->flags; inout_handlers[iop->port].handler = iop->handler; @@ -183,8 +186,6 @@ unregister_inout(struct inout_port *iop) return -1; } - assert(inout_handlers[iop->port].name == iop->name); - register_default_iohandler(iop->port, iop->size); return 0; diff --git a/devicemodel/core/post.c b/devicemodel/core/post.c index 1455c1f6b..68fff1246 100644 --- a/devicemodel/core/post.c +++ b/devicemodel/core/post.c @@ -26,8 +26,6 @@ * $FreeBSD$ */ -#include - #include "inout.h" #include "lpc.h" @@ -35,9 +33,7 @@ static int post_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { - assert(in == 1); - - if (bytes != 1) + if ((in != 1) || (bytes != 1)) return -1; *eax = 0xff; /* return some garbage */