From: Adham Masarwah Date: Thu, 19 Jun 2014 10:25:13 +0000 (+0300) Subject: Fix out of range address when trying to read invalid address X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=059cc1c9134ce3679094ea5d5f32e31efa982c43;p=~adrianc%2Fmstflint.git Fix out of range address when trying to read invalid address --- diff --git a/mtcr_ul/mtcr_ul.c b/mtcr_ul/mtcr_ul.c index 51b36d7..cef82f2 100644 --- a/mtcr_ul/mtcr_ul.c +++ b/mtcr_ul/mtcr_ul.c @@ -456,6 +456,10 @@ int mtcr_mmap(struct pcicr_context *mf, const char *name, off_t off, int ioctl_n int mtcr_pcicr_mread4(mfile *mf, unsigned int offset, u_int32_t *value) { struct pcicr_context *ctx = mf->ctx; + if (offset >= MTCR_MAP_SIZE) { + errno = EINVAL; + return 0; + } if (ctx->need_flush) { mtcr_connectx_flush(ctx->ptr); ctx->need_flush = 0; @@ -468,6 +472,10 @@ int mtcr_pcicr_mwrite4(mfile *mf, unsigned int offset, u_int32_t value) { struct pcicr_context *ctx = mf->ctx; + if (offset >= MTCR_MAP_SIZE) { + errno = EINVAL; + return 0; + } *((u_int32_t *)((char *)ctx->ptr + offset)) = __cpu_to_be32(value); ctx->need_flush = ctx->connectx_flush; return 4; diff --git a/small_utils/mcra.c b/small_utils/mcra.c index 7297f55..d330a73 100644 --- a/small_utils/mcra.c +++ b/small_utils/mcra.c @@ -369,7 +369,9 @@ int main(int argc, char *argv[]) val = MERGE(tmp_val, val, bit_offs, bit_size); } - rc = mwrite4(mf, addr, val); + if(mwrite4(mf, addr, val) != 4) { + goto access_error; + } } goto success;