Message ID | 243065110.2784373.1606322502779.JavaMail.zimbra@robart.cc |
---|---|
State | Accepted |
Headers | show |
Series | libuboot_env: correct length to usable env size length | expand |
Hi Manuel, On 25.11.20 17:41, Manuel Dipolt wrote: > > ctx->size would be correct from start of struct / environment, > however usable environment payload starts from data header (offsetdata) > > Signed-off-by: Manuel Dipolt <manuel.dipolt@robart.cc> > --- > src/uboot_env.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/src/uboot_env.c b/src/uboot_env.c > index af40565..94d371e 100644 > --- a/src/uboot_env.c > +++ b/src/uboot_env.c > @@ -942,7 +942,7 @@ static int libuboot_load(struct uboot_ctx *ctx) > int ret, i; > int copies = 1; > void *buf[2]; > - size_t bufsize; > + size_t bufsize, usable_envsize; > struct uboot_flash_env *dev; > bool crcenv[2]; > unsigned char flags[2]; > @@ -954,7 +954,8 @@ static int libuboot_load(struct uboot_ctx *ctx) > struct var_entry *entry; > > ctx->valid = false; > - > + usable_envsize = ctx->size - offsetdata; > + > bufsize = ctx->size; > if (ctx->redundant) { > copies++; > @@ -980,7 +981,7 @@ static int libuboot_load(struct uboot_ctx *ctx) > return -EIO; > } > crc = *(uint32_t *)(buf[i] + offsetcrc); > - dev->crc = crc32(0, (uint8_t *)data, ctx->size - offsetdata); > + dev->crc = crc32(0, (uint8_t *)data, usable_envsize); > crcenv[i] = dev->crc == crc; > if (ctx->redundant) > dev->flags = *(uint8_t *)(buf[i] + offsetflags); > @@ -1041,7 +1042,7 @@ static int libuboot_load(struct uboot_ctx *ctx) > * Search the end of the string pointed by line > */ > for (next = line; *next; ++next) { > - if ((next - (char *)data) > ctx->size) { > + if ((next - (char *)data) > usable_envsize) { > free(buf[0]); > return -EIO; > } > It seems correct to me. Acked-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/src/uboot_env.c b/src/uboot_env.c index af40565..94d371e 100644 --- a/src/uboot_env.c +++ b/src/uboot_env.c @@ -942,7 +942,7 @@ static int libuboot_load(struct uboot_ctx *ctx) int ret, i; int copies = 1; void *buf[2]; - size_t bufsize; + size_t bufsize, usable_envsize; struct uboot_flash_env *dev; bool crcenv[2]; unsigned char flags[2]; @@ -954,7 +954,8 @@ static int libuboot_load(struct uboot_ctx *ctx) struct var_entry *entry; ctx->valid = false; - + usable_envsize = ctx->size - offsetdata; + bufsize = ctx->size; if (ctx->redundant) { copies++; @@ -980,7 +981,7 @@ static int libuboot_load(struct uboot_ctx *ctx) return -EIO; } crc = *(uint32_t *)(buf[i] + offsetcrc); - dev->crc = crc32(0, (uint8_t *)data, ctx->size - offsetdata); + dev->crc = crc32(0, (uint8_t *)data, usable_envsize); crcenv[i] = dev->crc == crc; if (ctx->redundant) dev->flags = *(uint8_t *)(buf[i] + offsetflags); @@ -1041,7 +1042,7 @@ static int libuboot_load(struct uboot_ctx *ctx) * Search the end of the string pointed by line */ for (next = line; *next; ++next) { - if ((next - (char *)data) > ctx->size) { + if ((next - (char *)data) > usable_envsize) { free(buf[0]); return -EIO; }
ctx->size would be correct from start of struct / environment, however usable environment payload starts from data header (offsetdata) Signed-off-by: Manuel Dipolt <manuel.dipolt@robart.cc> --- src/uboot_env.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)