aboutsummaryrefslogtreecommitdiff
path: root/lib/libsecureboot/vectx.c
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2024-02-12 22:35:01 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2024-02-12 22:35:01 +0000
commitf616d61ab6b071e5fbfdbae7033a9ef04c1444ad (patch)
tree47edbc56733109d8f3552b3ac2247120e5304f8a /lib/libsecureboot/vectx.c
parent57e27ff07aff35289892f79288bebf76a3c31fec (diff)
downloadsrc-f616d61ab6b071e5fbfdbae7033a9ef04c1444ad.tar.gz
src-f616d61ab6b071e5fbfdbae7033a9ef04c1444ad.zip
Diffstat (limited to 'lib/libsecureboot/vectx.c')
-rw-r--r--lib/libsecureboot/vectx.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/libsecureboot/vectx.c b/lib/libsecureboot/vectx.c
index dba728421ce4..2d56830cd81d 100644
--- a/lib/libsecureboot/vectx.c
+++ b/lib/libsecureboot/vectx.c
@@ -306,19 +306,31 @@ vectx_lseek(struct vectx *ctx, off_t off, int whence)
DEBUG_PRINTF(3,
("%s(%s, %ld, %d)\n", __func__, ctx->vec_path, (long)off, whence));
if (whence == SEEK_END && off <= 0) {
- if (ctx->vec_closing && ctx->vec_hashed < ctx->vec_size) {
- DEBUG_PRINTF(3, ("%s: SEEK_END %ld\n",
- __func__,
- (long)(ctx->vec_size - ctx->vec_hashed)));
+ if (ctx->vec_size < 0) {
+ if (ctx->vec_closing) {
+ /* size unknown - read until EOF */
+ do {
+ n = vectx_read(ctx, buf, PAGE_SIZE);
+ if (n < 0)
+ return (n);
+ } while (n > 0);
+ return (ctx->vec_off);
+ }
+ } else {
+ if (ctx->vec_closing && ctx->vec_hashed < ctx->vec_size) {
+ DEBUG_PRINTF(3, ("%s: SEEK_END %ld\n",
+ __func__,
+ (long)(ctx->vec_size - ctx->vec_hashed)));
+ }
+ whence = SEEK_SET;
+ off += ctx->vec_size;
}
- whence = SEEK_SET;
- off += ctx->vec_size;
} else if (whence == SEEK_CUR) {
whence = SEEK_SET;
off += ctx->vec_off;
}
if (whence != SEEK_SET ||
- off > ctx->vec_size) {
+ (off > ctx->vec_size && ctx->vec_size > 0)) {
printf("ERROR: %s: unsupported operation: whence=%d off=%ld -> %ld\n",
__func__, whence, (long)ctx->vec_off, (long)off);
return (-1);