diff options
author | ASOU Masato <asou@cvs.openbsd.org> | 2023-01-07 06:40:22 +0000 |
---|---|---|
committer | ASOU Masato <asou@cvs.openbsd.org> | 2023-01-07 06:40:22 +0000 |
commit | d90890ed6e363834686d5c3307a6c8688278e2b7 (patch) | |
tree | 89b6894587780d9c1ef02e646af63e0a976e3230 /usr.sbin/hostctl | |
parent | 9232dcce6bb242e47f9429b04e02836e23f9cb03 (diff) |
The maximum length of the value is extended to 64k bytes.
ok yasuoka
Diffstat (limited to 'usr.sbin/hostctl')
-rw-r--r-- | usr.sbin/hostctl/hostctl.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/usr.sbin/hostctl/hostctl.c b/usr.sbin/hostctl/hostctl.c index f0639dd55f3..a6b6c72ea67 100644 --- a/usr.sbin/hostctl/hostctl.c +++ b/usr.sbin/hostctl/hostctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hostctl.c,v 1.5 2019/06/28 13:32:47 deraadt Exp $ */ +/* $OpenBSD: hostctl.c,v 1.6 2023/01/07 06:40:21 asou Exp $ */ /* * Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org> @@ -178,15 +178,29 @@ main(int argc, char *argv[]) usage(); /* Re-open read-writable */ - if (cmd == PVBUSIOC_KVWRITE) { + if (cmd != PVBUSIOC_KVREAD) { close(fd); if ((fd = open(path_pvbus, O_RDWR)) == -1) err(1, "open: %s", path_pvbus); + if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == -1) + err(1, "ioctl"); + } else { + while (1) { + if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == 0) + break; + if (errno == ERANGE && + pvr.pvr_valuelen < PVBUS_KVOP_MAXSIZE) { + /* the buffer is not enough, expand it */ + pvr.pvr_valuelen *= 2; + if ((pvr.pvr_value = realloc(pvr.pvr_value, + pvr.pvr_valuelen)) == NULL) + err(1, "realloc"); + continue; + } + err(1, "ioctl"); + } } - if ((ret = ioctl(fd, cmd, &pvr, sizeof(pvr))) == -1) - err(1, "ioctl"); - if (!qflag && strlen(pvr.pvr_value)) { /* * The value can contain newlines and basically anything; |