2019-05-13 09:18:23 +02:00
|
|
|
From b3c58e3b9237f90e865723837a9389fcb25f6945 Mon Sep 17 00:00:00 2001
|
2014-10-29 09:11:07 +01:00
|
|
|
From: Gary Ching-Pang Lin <glin@suse.com>
|
|
|
|
Date: Tue, 1 Jul 2014 14:43:35 +0800
|
|
|
|
Subject: [PATCH] authvar: fix the write loop
|
|
|
|
|
|
|
|
I forgot to move the pointer...
|
|
|
|
|
|
|
|
Also use offsetof() instead of the wordsize check.
|
|
|
|
|
|
|
|
Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
|
|
|
|
---
|
|
|
|
src/authvar_context.c | 16 +++++++---------
|
|
|
|
1 file changed, 7 insertions(+), 9 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/src/authvar_context.c b/src/authvar_context.c
|
2019-05-13 09:18:23 +02:00
|
|
|
index 7a753fc..c51c666 100644
|
2014-10-29 09:11:07 +01:00
|
|
|
--- a/src/authvar_context.c
|
|
|
|
+++ b/src/authvar_context.c
|
2019-05-13 09:18:23 +02:00
|
|
|
@@ -20,6 +20,7 @@
|
|
|
|
#include "fix_coverity.h"
|
2014-10-29 09:11:07 +01:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
+#include <stddef.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
|
|
#include <prerror.h>
|
2019-05-13 09:18:23 +02:00
|
|
|
@@ -135,11 +136,7 @@ generate_descriptor(authvar_context *ctx)
|
2014-10-29 09:11:07 +01:00
|
|
|
if (rc < 0)
|
|
|
|
cmsreterr(-1, ctx->cms_ctx, "could not create signed data");
|
|
|
|
|
|
|
|
-#if __WORDSIZE == 64
|
|
|
|
- offset = (uint64_t) &((win_cert_uefi_guid_t *)0)->data;
|
|
|
|
-#else
|
|
|
|
- offset = (uint32_t) &((win_cert_uefi_guid_t *)0)->data;
|
|
|
|
-#endif
|
|
|
|
+ offset = offsetof(win_cert_uefi_guid_t, data);
|
|
|
|
authinfo = calloc(offset + sd_der.len, 1);
|
|
|
|
if (!authinfo)
|
|
|
|
cmsreterr(-1, ctx->cms_ctx, "could not allocate authinfo");
|
2019-05-13 09:18:23 +02:00
|
|
|
@@ -162,6 +159,7 @@ write_authvar(authvar_context *ctx)
|
2014-10-29 09:11:07 +01:00
|
|
|
void *buffer, *ptr;
|
|
|
|
size_t buf_len, des_len, remain;
|
|
|
|
ssize_t wlen;
|
|
|
|
+ off_t offset;
|
|
|
|
|
|
|
|
if (!ctx->authinfo)
|
|
|
|
cmsreterr(-1, ctx->cms_ctx, "Not a valid authvar");
|
2019-05-13 09:18:23 +02:00
|
|
|
@@ -189,19 +187,19 @@ write_authvar(authvar_context *ctx)
|
2014-10-29 09:11:07 +01:00
|
|
|
if (ctx->value_size > 0)
|
|
|
|
memcpy(ptr, ctx->value, ctx->value_size);
|
|
|
|
|
|
|
|
- if (!ctx->to_firmware) {
|
|
|
|
- ftruncate(ctx->exportfd, buf_len);
|
|
|
|
+ if (!ctx->to_firmware)
|
|
|
|
lseek(ctx->exportfd, 0, SEEK_SET);
|
|
|
|
- }
|
|
|
|
|
|
|
|
remain = buf_len;
|
|
|
|
+ offset = 0;
|
|
|
|
do {
|
|
|
|
- wlen = write(ctx->exportfd, buffer, remain);
|
|
|
|
+ wlen = write(ctx->exportfd, buffer + offset, remain);
|
2019-05-13 09:18:23 +02:00
|
|
|
if (wlen < 0) {
|
|
|
|
free(buffer);
|
2014-10-29 09:11:07 +01:00
|
|
|
cmsreterr(-1, ctx->cms_ctx, "failed to write authvar");
|
2019-05-13 09:18:23 +02:00
|
|
|
}
|
2014-10-29 09:11:07 +01:00
|
|
|
remain -= wlen;
|
|
|
|
+ offset += wlen;
|
|
|
|
} while (remain > 0);
|
|
|
|
|
2019-05-13 09:18:23 +02:00
|
|
|
free(buffer);
|
2014-10-29 09:11:07 +01:00
|
|
|
--
|
2019-05-13 09:18:23 +02:00
|
|
|
2.21.0
|
2014-10-29 09:11:07 +01:00
|
|
|
|