diff options
-rw-r--r-- | host/lib/crossystem.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c index c8938225..061d4b71 100644 --- a/host/lib/crossystem.c +++ b/host/lib/crossystem.c @@ -103,13 +103,18 @@ int vb2_get_nv_storage(enum vb2_nv_param param) VbSharedDataHeader* sh = VbSharedDataRead(); static struct vb2_context cached_ctx; + if (!sh) + return -1; + /* TODO: locking around NV access */ if (!vnc_read) { memset(&cached_ctx, 0, sizeof(cached_ctx)); if (sh && sh->flags & VBSD_NVDATA_V2) cached_ctx.flags |= VB2_CONTEXT_NVDATA_V2; - if (0 != vb2_read_nv_storage(&cached_ctx)) + if (0 != vb2_read_nv_storage(&cached_ctx)) { + free(sh); return -1; + } vb2_nv_init(&cached_ctx); /* TODO: If vnc.raw_changed, attempt to reopen NVRAM for write @@ -118,6 +123,7 @@ int vb2_get_nv_storage(enum vb2_nv_param param) vnc_read = 1; } + free(sh); return (int)vb2_nv_get(&cached_ctx, param); } @@ -126,22 +132,30 @@ int vb2_set_nv_storage(enum vb2_nv_param param, int value) VbSharedDataHeader* sh = VbSharedDataRead(); struct vb2_context ctx; + if (!sh) + return -1; + /* TODO: locking around NV access */ memset(&ctx, 0, sizeof(ctx)); if (sh && sh->flags & VBSD_NVDATA_V2) ctx.flags |= VB2_CONTEXT_NVDATA_V2; - if (0 != vb2_read_nv_storage(&ctx)) + if (0 != vb2_read_nv_storage(&ctx)) { + free(sh); return -1; + } vb2_nv_init(&ctx); vb2_nv_set(&ctx, param, (uint32_t)value); if (ctx.flags & VB2_CONTEXT_NVDATA_CHANGED) { vnc_read = 0; - if (0 != vb2_write_nv_storage(&ctx)) + if (0 != vb2_write_nv_storage(&ctx)) { + free(sh); return -1; + } } /* Success */ + free(sh); return 0; } |