sync with OpenBSD -current

This commit is contained in:
purplerain 2024-02-03 01:45:10 +00:00
parent 037d8115db
commit 7d66fd8cb0
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
45 changed files with 2495 additions and 357 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: b_dump.c,v 1.27 2024/02/01 17:04:09 tb Exp $ */
/* $OpenBSD: b_dump.c,v 1.28 2024/02/02 10:53:48 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -56,90 +56,141 @@
* [including the GNU Public Licence.]
*/
/*
* Stolen from tjh's ssl/ssl_trc.c stuff.
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#define TRUNCATE
#define DUMP_WIDTH 16
#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4))
#include "bytestring.h"
#define MAX_BYTES_PER_LINE 16
/*
* The byte string s is dumped as lines of the following form:
* indent | byte count (4 digits) | " - " | hex dump | " " | ASCII dump
* Each byte uses 4 characters (two hex digits followed by a space and one
* ASCII character).
*/
int
BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
{
char buf[288 + 1], tmp[20], str[128 + 1];
int i, j, rows, trc, written;
unsigned char ch;
int dump_width;
int ret = 0;
CBB cbb;
CBS cbs;
int bytes_per_line, dumped, printed, trailing, written;
int ret = -1;
trc = 0;
memset(&cbb, 0, sizeof(cbb));
#ifdef TRUNCATE
for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--)
trc++;
#endif
if (len < 0)
goto err;
CBS_init(&cbs, s, len);
if (indent < 0)
indent = 0;
if (indent > 64)
indent = 64;
memset(str, ' ', indent);
str[indent] = '\0';
if ((dump_width = DUMP_WIDTH_LESS_INDENT(indent)) <= 0)
return -1;
rows = (len / dump_width);
if ((rows * dump_width) < len)
rows++;
for (i = 0; i < rows; i++) {
strlcpy(buf, str, sizeof buf);
snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width);
strlcat(buf, tmp, sizeof buf);
for (j = 0; j < dump_width; j++) {
if (((i*dump_width) + j) >= len) {
strlcat(buf, " ", sizeof buf);
} else {
ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff;
snprintf(tmp, sizeof tmp, "%02x%c", ch,
j == 7 ? '-' : ' ');
strlcat(buf, tmp, sizeof buf);
}
}
strlcat(buf, " ", sizeof buf);
for (j = 0; j < dump_width; j++) {
if (((i*dump_width) + j) >= len)
break;
ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
snprintf(tmp, sizeof tmp, "%c",
((ch >= ' ') && (ch <= '~')) ? ch : '.');
strlcat(buf, tmp, sizeof buf);
}
strlcat(buf, "\n", sizeof buf);
/* if this is the last call then update the ddt_dump thing so
* that we will move the selection point in the debug window
/*
* Less obfuscated version of the original calculation attempting to
* ensure that the dump doesn't overshoot 80 characters per line. For
* a very long string the byte count will still make it go past that.
*/
bytes_per_line = MAX_BYTES_PER_LINE;
if (indent > 6)
bytes_per_line -= (indent - 3) / 4;
if (bytes_per_line <= 0)
goto err;
/* Strip and count trailing spaces and NULs. */
trailing = 0;
while (CBS_len(&cbs) > 0) {
uint8_t u8;
if (!CBS_peek_last_u8(&cbs, &u8))
goto err;
if (u8 != '\0' && u8 != ' ')
break;
if (!CBS_get_last_u8(&cbs, &u8))
goto err;
trailing++;
}
printed = 0;
dumped = 0;
while (CBS_len(&cbs) > 0) {
CBS row;
uint8_t ascii_dump[MAX_BYTES_PER_LINE];
int missing, row_bytes;
if ((row_bytes = CBS_len(&cbs)) > bytes_per_line)
row_bytes = bytes_per_line;
if (!CBS_get_bytes(&cbs, &row, row_bytes))
goto err;
/* Write out indent, byte count and initial " - ". */
if ((written = BIO_printf(bio, "%*s%04x - ", indent, "",
dumped)) < 0)
goto err;
printed += written;
/*
* Write out hex dump, prepare ASCII dump.
*/
if ((written = BIO_write(bio, buf, strlen(buf))) < 0)
return -1;
ret += written;
if (!CBB_init_fixed(&cbb, ascii_dump, sizeof(ascii_dump)))
goto err;
while (CBS_len(&row) > 0) {
uint8_t u8;
char sep = ' ';
if (!CBS_get_u8(&row, &u8))
goto err;
/* Historic behavior: print a '-' after eighth byte. */
if (row_bytes - CBS_len(&row) == 8)
sep = '-';
if ((written = BIO_printf(bio, "%02x%c", u8, sep)) < 0)
goto err;
printed += written;
/* Locale-independent version of !isprint(u8). */
if (u8 < ' ' || u8 > '~')
u8 = '.';
if (!CBB_add_u8(&cbb, u8))
goto err;
}
if (!CBB_finish(&cbb, NULL, NULL))
goto err;
/* Calculate number of bytes missing in dump of last line. */
if ((missing = bytes_per_line - row_bytes) < 0)
goto err;
/* Pad missing bytes, add 2 spaces and print the ASCII dump. */
if ((written = BIO_printf(bio, "%*s%.*s\n", 3 * missing + 2, "",
row_bytes, ascii_dump)) < 0)
goto err;
printed += written;
dumped += row_bytes;
}
#ifdef TRUNCATE
if (trc > 0) {
snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n",
str, len + trc);
if ((written = BIO_write(bio, buf, strlen(buf))) < 0)
return -1;
ret += written;
if (trailing > 0) {
if ((written = BIO_printf(bio, "%*s%04x - <SPACES/NULS>\n",
indent, "", dumped + trailing)) < 0)
goto err;
printed += written;
}
#endif
return (ret);
ret = printed;
err:
CBB_cleanup(&cbb);
return ret;
}
LCRYPTO_ALIAS(BIO_dump_indent);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cms_kari.c,v 1.15 2023/07/08 08:26:26 beck Exp $ */
/* $OpenBSD: cms_kari.c,v 1.16 2024/02/02 14:11:45 tb Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
@ -279,7 +279,7 @@ cms_kek_cipher(unsigned char **pout, size_t *poutlen, const unsigned char *in,
explicit_bzero(kek, keklen);
if (!rv)
free(out);
EVP_CIPHER_CTX_reset(kari->ctx);
(void)EVP_CIPHER_CTX_reset(kari->ctx);
/* FIXME: WHY IS kari->pctx freed here? /RL */
EVP_PKEY_CTX_free(kari->pctx);
kari->pctx = NULL;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: cms_sd.c,v 1.29 2023/10/18 07:30:49 tb Exp $ */
/* $OpenBSD: cms_sd.c,v 1.30 2024/02/02 14:13:11 tb Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
@ -744,7 +744,7 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si)
}
if (si->pctx == NULL) {
EVP_MD_CTX_reset(si->mctx);
(void)EVP_MD_CTX_reset(si->mctx);
if (!EVP_DigestSignInit(si->mctx, &si->pctx, md, NULL, si->pkey))
goto err;
}
@ -779,8 +779,7 @@ CMS_SignerInfo_sign(CMS_SignerInfo *si)
ret = 1;
err:
if (si->mctx != NULL)
EVP_MD_CTX_reset(si->mctx);
(void)EVP_MD_CTX_reset(si->mctx);
freezero(buf, buf_len);
freezero(sig, sig_len);
@ -831,8 +830,7 @@ CMS_SignerInfo_verify(CMS_SignerInfo *si)
}
err:
if (si->mctx != NULL)
EVP_MD_CTX_reset(si->mctx);
(void)EVP_MD_CTX_reset(si->mctx);
freezero(buf, buf_len);
return ret;

View File

@ -1,7 +1,8 @@
# $OpenBSD: Makefile,v 1.7 2023/04/25 19:48:24 tb Exp $
# $OpenBSD: Makefile,v 1.8 2024/02/02 06:22:01 tb Exp $
PROGS += bio_asn1
PROGS += bio_chain
PROGS += bio_dump
PROGS += bio_host
PROGS += bio_mem

View File

@ -0,0 +1,777 @@
/* $OpenBSD: bio_dump.c,v 1.3 2024/02/02 06:47:21 tb Exp $ */
/*
* Copyright (c) 2024 Theo Buehler <tb@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <err.h>
#include <string.h>
#include <openssl/bio.h>
const uint8_t dump[] = {
0x74, 0x45, 0xc6, 0x20, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x36, 0xd8, 0x61, 0x48, 0x68, 0x3c, 0xc0, 0x68,
0xaa, 0x15, 0x57, 0x77, 0xe3, 0xec, 0xb4, 0x98,
0xc6, 0x08, 0xfc, 0x59, 0xb3, 0x4f, 0x45, 0xcf,
0x4b, 0xc2, 0xae, 0x98, 0xb5, 0xeb, 0xe0, 0xb5,
0xc1, 0x68, 0xba, 0xcf, 0x7c, 0xf7, 0x7b, 0x38,
0x43, 0x2f, 0xb9, 0x0e, 0x23, 0x02, 0xb9, 0x4f,
0x8c, 0x26, 0xeb, 0xef, 0x70, 0x98, 0x82, 0xa7,
0xb9, 0x78, 0xc5, 0x08, 0x96, 0x99, 0xb3, 0x84,
0xa3, 0x4f, 0xfb, 0xd7, 0x38, 0xa9, 0xd9, 0xd4,
0x53, 0x0f, 0x4f, 0x64, 0x97, 0xdf, 0xcf, 0xf3,
0x4f, 0xc8, 0xd2, 0x56, 0x3f, 0x0d, 0x72, 0xd4,
0x55, 0x98, 0x89, 0xb0, 0x45, 0x26, 0x3f, 0x7a,
0xbd, 0x9d, 0x96, 0x15, 0xa2, 0x10, 0x14, 0x85,
0xaa, 0xa1, 0x7c, 0x84, 0xfb, 0xc4, 0xa5, 0x7b,
0xc6, 0xe3, 0xad, 0x85, 0x57, 0x96, 0xbb, 0x81,
0x18, 0x0c, 0xed, 0x2f, 0xf7, 0x6a, 0x4c, 0x4d,
0x59, 0xe1, 0xcc, 0xc5, 0x3a, 0x9f, 0x48, 0xfc,
0x1d, 0x7c, 0x0d, 0xa4, 0x79, 0x96, 0xe7, 0x2b,
0x39, 0x15, 0xf9, 0x3a, 0x6a, 0x5e, 0x7c, 0x4e,
0xc9, 0x3b, 0xaf, 0xeb, 0x3b, 0xcf, 0x8d, 0x6a,
0x57, 0xe6, 0xc5, 0xba, 0xbd, 0xa6, 0xa0, 0x6b,
0x03, 0xd5, 0xa3, 0x9f, 0x99, 0x2a, 0xea, 0x88,
0x72, 0x1b, 0x66, 0x6c, 0x5e, 0x1d, 0x49, 0xd5,
0x1e, 0x1e, 0xcc, 0x1a, 0xb1, 0xd8, 0xf7, 0x91,
0x1e, 0x1e, 0xcc, 0x1a, 0x20, 0x00, 0x20, 0x00,
0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00,
0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00,
0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00,
0x20, 0x00, 0x20, 0x00, 0x20, 0x00,
};
#define DUMP_LEN (sizeof(dump) / sizeof(dump[0]))
static const struct bio_dump_testcase {
int indent;
const char *input;
int inlen;
const char *output;
} bio_dump_testcases[] = {
{
.indent = 0,
.input = "",
.inlen = 0,
.output = "",
},
{
.indent = 0,
.input = "",
.inlen = 1,
.output = "0001 - <SPACES/NULS>\n",
},
{
.indent = 6,
.input = " ",
.inlen = 1,
.output = " 0001 - <SPACES/NULS>\n",
},
{
.indent = -1,
.input = "!",
.inlen = 1,
.output =
"0000 - 21 !\n",
},
{
.indent = -1,
.input = "~",
.inlen = 1,
.output =
"0000 - 7e ~\n",
},
{
.indent = 4,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 00 00 00 tE. ............\n"
" 0010 - 36 d8 61 48 68 3c c0 68-aa 15 57 77 e3 ec b4 98 6.aHh<.h..Ww....\n"
" 0020 - c6 08 fc 59 b3 4f 45 cf-4b c2 ae 98 b5 eb e0 b5 ...Y.OE.K.......\n"
" 0030 - c1 68 ba cf 7c f7 7b 38-43 2f b9 0e 23 02 b9 4f .h..|.{8C/..#..O\n"
" 0040 - 8c 26 eb ef 70 98 82 a7-b9 78 c5 08 96 99 b3 84 .&..p....x......\n"
" 0050 - a3 4f fb d7 38 a9 d9 d4-53 0f 4f 64 97 df cf f3 .O..8...S.Od....\n"
" 0060 - 4f c8 d2 56 3f 0d 72 d4-55 98 89 b0 45 26 3f 7a O..V?.r.U...E&?z\n"
" 0070 - bd 9d 96 15 a2 10 14 85-aa a1 7c 84 fb c4 a5 7b ..........|....{\n"
" 0080 - c6 e3 ad 85 57 96 bb 81-18 0c ed 2f f7 6a 4c 4d ....W....../.jLM\n"
" 0090 - 59 e1 cc c5 3a 9f 48 fc-1d 7c 0d a4 79 96 e7 2b Y...:.H..|..y..+\n"
" 00a0 - 39 15 f9 3a 6a 5e 7c 4e-c9 3b af eb 3b cf 8d 6a 9..:j^|N.;..;..j\n"
" 00b0 - 57 e6 c5 ba bd a6 a0 6b-03 d5 a3 9f 99 2a ea 88 W......k.....*..\n"
" 00c0 - 72 1b 66 6c 5e 1d 49 d5-1e 1e cc 1a b1 d8 f7 91 r.fl^.I.........\n"
" 00d0 - 1e 1e cc 1a ....\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 11,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 00 tE. ..........\n"
" 000e - 00 00 36 d8 61 48 68 3c-c0 68 aa 15 57 77 ..6.aHh<.h..Ww\n"
" 001c - e3 ec b4 98 c6 08 fc 59-b3 4f 45 cf 4b c2 .......Y.OE.K.\n"
" 002a - ae 98 b5 eb e0 b5 c1 68-ba cf 7c f7 7b 38 .......h..|.{8\n"
" 0038 - 43 2f b9 0e 23 02 b9 4f-8c 26 eb ef 70 98 C/..#..O.&..p.\n"
" 0046 - 82 a7 b9 78 c5 08 96 99-b3 84 a3 4f fb d7 ...x.......O..\n"
" 0054 - 38 a9 d9 d4 53 0f 4f 64-97 df cf f3 4f c8 8...S.Od....O.\n"
" 0062 - d2 56 3f 0d 72 d4 55 98-89 b0 45 26 3f 7a .V?.r.U...E&?z\n"
" 0070 - bd 9d 96 15 a2 10 14 85-aa a1 7c 84 fb c4 ..........|...\n"
" 007e - a5 7b c6 e3 ad 85 57 96-bb 81 18 0c ed 2f .{....W....../\n"
" 008c - f7 6a 4c 4d 59 e1 cc c5-3a 9f 48 fc 1d 7c .jLMY...:.H..|\n"
" 009a - 0d a4 79 96 e7 2b 39 15-f9 3a 6a 5e 7c 4e ..y..+9..:j^|N\n"
" 00a8 - c9 3b af eb 3b cf 8d 6a-57 e6 c5 ba bd a6 .;..;..jW.....\n"
" 00b6 - a0 6b 03 d5 a3 9f 99 2a-ea 88 72 1b 66 6c .k.....*..r.fl\n"
" 00c4 - 5e 1d 49 d5 1e 1e cc 1a-b1 d8 f7 91 1e 1e ^.I...........\n"
" 00d2 - cc 1a ..\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 18,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 00 00 tE. .........\n"
" 000d - 00 00 00 36 d8 61 48 68-3c c0 68 aa 15 ...6.aHh<.h..\n"
" 001a - 57 77 e3 ec b4 98 c6 08-fc 59 b3 4f 45 Ww.......Y.OE\n"
" 0027 - cf 4b c2 ae 98 b5 eb e0-b5 c1 68 ba cf .K........h..\n"
" 0034 - 7c f7 7b 38 43 2f b9 0e-23 02 b9 4f 8c |.{8C/..#..O.\n"
" 0041 - 26 eb ef 70 98 82 a7 b9-78 c5 08 96 99 &..p....x....\n"
" 004e - b3 84 a3 4f fb d7 38 a9-d9 d4 53 0f 4f ...O..8...S.O\n"
" 005b - 64 97 df cf f3 4f c8 d2-56 3f 0d 72 d4 d....O..V?.r.\n"
" 0068 - 55 98 89 b0 45 26 3f 7a-bd 9d 96 15 a2 U...E&?z.....\n"
" 0075 - 10 14 85 aa a1 7c 84 fb-c4 a5 7b c6 e3 .....|....{..\n"
" 0082 - ad 85 57 96 bb 81 18 0c-ed 2f f7 6a 4c ..W....../.jL\n"
" 008f - 4d 59 e1 cc c5 3a 9f 48-fc 1d 7c 0d a4 MY...:.H..|..\n"
" 009c - 79 96 e7 2b 39 15 f9 3a-6a 5e 7c 4e c9 y..+9..:j^|N.\n"
" 00a9 - 3b af eb 3b cf 8d 6a 57-e6 c5 ba bd a6 ;..;..jW.....\n"
" 00b6 - a0 6b 03 d5 a3 9f 99 2a-ea 88 72 1b 66 .k.....*..r.f\n"
" 00c3 - 6c 5e 1d 49 d5 1e 1e cc-1a b1 d8 f7 91 l^.I.........\n"
" 00d0 - 1e 1e cc 1a ....\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 25,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00-00 00 00 tE. .......\n"
" 000b - 00 00 00 00 00 36 d8 61-48 68 3c .....6.aHh<\n"
" 0016 - c0 68 aa 15 57 77 e3 ec-b4 98 c6 .h..Ww.....\n"
" 0021 - 08 fc 59 b3 4f 45 cf 4b-c2 ae 98 ..Y.OE.K...\n"
" 002c - b5 eb e0 b5 c1 68 ba cf-7c f7 7b .....h..|.{\n"
" 0037 - 38 43 2f b9 0e 23 02 b9-4f 8c 26 8C/..#..O.&\n"
" 0042 - eb ef 70 98 82 a7 b9 78-c5 08 96 ..p....x...\n"
" 004d - 99 b3 84 a3 4f fb d7 38-a9 d9 d4 ....O..8...\n"
" 0058 - 53 0f 4f 64 97 df cf f3-4f c8 d2 S.Od....O..\n"
" 0063 - 56 3f 0d 72 d4 55 98 89-b0 45 26 V?.r.U...E&\n"
" 006e - 3f 7a bd 9d 96 15 a2 10-14 85 aa ?z.........\n"
" 0079 - a1 7c 84 fb c4 a5 7b c6-e3 ad 85 .|....{....\n"
" 0084 - 57 96 bb 81 18 0c ed 2f-f7 6a 4c W....../.jL\n"
" 008f - 4d 59 e1 cc c5 3a 9f 48-fc 1d 7c MY...:.H..|\n"
" 009a - 0d a4 79 96 e7 2b 39 15-f9 3a 6a ..y..+9..:j\n"
" 00a5 - 5e 7c 4e c9 3b af eb 3b-cf 8d 6a ^|N.;..;..j\n"
" 00b0 - 57 e6 c5 ba bd a6 a0 6b-03 d5 a3 W......k...\n"
" 00bb - 9f 99 2a ea 88 72 1b 66-6c 5e 1d ..*..r.fl^.\n"
" 00c6 - 49 d5 1e 1e cc 1a b1 d8-f7 91 1e I..........\n"
" 00d1 - 1e cc 1a ...\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 32,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00-00 tE. .....\n"
" 0009 - 00 00 00 00 00 00 00 36-d8 .......6.\n"
" 0012 - 61 48 68 3c c0 68 aa 15-57 aHh<.h..W\n"
" 001b - 77 e3 ec b4 98 c6 08 fc-59 w.......Y\n"
" 0024 - b3 4f 45 cf 4b c2 ae 98-b5 .OE.K....\n"
" 002d - eb e0 b5 c1 68 ba cf 7c-f7 ....h..|.\n"
" 0036 - 7b 38 43 2f b9 0e 23 02-b9 {8C/..#..\n"
" 003f - 4f 8c 26 eb ef 70 98 82-a7 O.&..p...\n"
" 0048 - b9 78 c5 08 96 99 b3 84-a3 .x.......\n"
" 0051 - 4f fb d7 38 a9 d9 d4 53-0f O..8...S.\n"
" 005a - 4f 64 97 df cf f3 4f c8-d2 Od....O..\n"
" 0063 - 56 3f 0d 72 d4 55 98 89-b0 V?.r.U...\n"
" 006c - 45 26 3f 7a bd 9d 96 15-a2 E&?z.....\n"
" 0075 - 10 14 85 aa a1 7c 84 fb-c4 .....|...\n"
" 007e - a5 7b c6 e3 ad 85 57 96-bb .{....W..\n"
" 0087 - 81 18 0c ed 2f f7 6a 4c-4d ..../.jLM\n"
" 0090 - 59 e1 cc c5 3a 9f 48 fc-1d Y...:.H..\n"
" 0099 - 7c 0d a4 79 96 e7 2b 39-15 |..y..+9.\n"
" 00a2 - f9 3a 6a 5e 7c 4e c9 3b-af .:j^|N.;.\n"
" 00ab - eb 3b cf 8d 6a 57 e6 c5-ba .;..jW...\n"
" 00b4 - bd a6 a0 6b 03 d5 a3 9f-99 ...k.....\n"
" 00bd - 2a ea 88 72 1b 66 6c 5e-1d *..r.fl^.\n"
" 00c6 - 49 d5 1e 1e cc 1a b1 d8-f7 I........\n"
" 00cf - 91 1e 1e cc 1a .....\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 35,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 00- tE. ....\n"
" 0008 - 00 00 00 00 00 00 00 00- ........\n"
" 0010 - 36 d8 61 48 68 3c c0 68- 6.aHh<.h\n"
" 0018 - aa 15 57 77 e3 ec b4 98- ..Ww....\n"
" 0020 - c6 08 fc 59 b3 4f 45 cf- ...Y.OE.\n"
" 0028 - 4b c2 ae 98 b5 eb e0 b5- K.......\n"
" 0030 - c1 68 ba cf 7c f7 7b 38- .h..|.{8\n"
" 0038 - 43 2f b9 0e 23 02 b9 4f- C/..#..O\n"
" 0040 - 8c 26 eb ef 70 98 82 a7- .&..p...\n"
" 0048 - b9 78 c5 08 96 99 b3 84- .x......\n"
" 0050 - a3 4f fb d7 38 a9 d9 d4- .O..8...\n"
" 0058 - 53 0f 4f 64 97 df cf f3- S.Od....\n"
" 0060 - 4f c8 d2 56 3f 0d 72 d4- O..V?.r.\n"
" 0068 - 55 98 89 b0 45 26 3f 7a- U...E&?z\n"
" 0070 - bd 9d 96 15 a2 10 14 85- ........\n"
" 0078 - aa a1 7c 84 fb c4 a5 7b- ..|....{\n"
" 0080 - c6 e3 ad 85 57 96 bb 81- ....W...\n"
" 0088 - 18 0c ed 2f f7 6a 4c 4d- .../.jLM\n"
" 0090 - 59 e1 cc c5 3a 9f 48 fc- Y...:.H.\n"
" 0098 - 1d 7c 0d a4 79 96 e7 2b- .|..y..+\n"
" 00a0 - 39 15 f9 3a 6a 5e 7c 4e- 9..:j^|N\n"
" 00a8 - c9 3b af eb 3b cf 8d 6a- .;..;..j\n"
" 00b0 - 57 e6 c5 ba bd a6 a0 6b- W......k\n"
" 00b8 - 03 d5 a3 9f 99 2a ea 88- .....*..\n"
" 00c0 - 72 1b 66 6c 5e 1d 49 d5- r.fl^.I.\n"
" 00c8 - 1e 1e cc 1a b1 d8 f7 91- ........\n"
" 00d0 - 1e 1e cc 1a ....\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 39,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 00 tE. ...\n"
" 0007 - 00 00 00 00 00 00 00 .......\n"
" 000e - 00 00 36 d8 61 48 68 ..6.aHh\n"
" 0015 - 3c c0 68 aa 15 57 77 <.h..Ww\n"
" 001c - e3 ec b4 98 c6 08 fc .......\n"
" 0023 - 59 b3 4f 45 cf 4b c2 Y.OE.K.\n"
" 002a - ae 98 b5 eb e0 b5 c1 .......\n"
" 0031 - 68 ba cf 7c f7 7b 38 h..|.{8\n"
" 0038 - 43 2f b9 0e 23 02 b9 C/..#..\n"
" 003f - 4f 8c 26 eb ef 70 98 O.&..p.\n"
" 0046 - 82 a7 b9 78 c5 08 96 ...x...\n"
" 004d - 99 b3 84 a3 4f fb d7 ....O..\n"
" 0054 - 38 a9 d9 d4 53 0f 4f 8...S.O\n"
" 005b - 64 97 df cf f3 4f c8 d....O.\n"
" 0062 - d2 56 3f 0d 72 d4 55 .V?.r.U\n"
" 0069 - 98 89 b0 45 26 3f 7a ...E&?z\n"
" 0070 - bd 9d 96 15 a2 10 14 .......\n"
" 0077 - 85 aa a1 7c 84 fb c4 ...|...\n"
" 007e - a5 7b c6 e3 ad 85 57 .{....W\n"
" 0085 - 96 bb 81 18 0c ed 2f ....../\n"
" 008c - f7 6a 4c 4d 59 e1 cc .jLMY..\n"
" 0093 - c5 3a 9f 48 fc 1d 7c .:.H..|\n"
" 009a - 0d a4 79 96 e7 2b 39 ..y..+9\n"
" 00a1 - 15 f9 3a 6a 5e 7c 4e ..:j^|N\n"
" 00a8 - c9 3b af eb 3b cf 8d .;..;..\n"
" 00af - 6a 57 e6 c5 ba bd a6 jW.....\n"
" 00b6 - a0 6b 03 d5 a3 9f 99 .k.....\n"
" 00bd - 2a ea 88 72 1b 66 6c *..r.fl\n"
" 00c4 - 5e 1d 49 d5 1e 1e cc ^.I....\n"
" 00cb - 1a b1 d8 f7 91 1e 1e .......\n"
" 00d2 - cc 1a ..\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 46,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 00 00 tE. ..\n"
" 0006 - 00 00 00 00 00 00 ......\n"
" 000c - 00 00 00 00 36 d8 ....6.\n"
" 0012 - 61 48 68 3c c0 68 aHh<.h\n"
" 0018 - aa 15 57 77 e3 ec ..Ww..\n"
" 001e - b4 98 c6 08 fc 59 .....Y\n"
" 0024 - b3 4f 45 cf 4b c2 .OE.K.\n"
" 002a - ae 98 b5 eb e0 b5 ......\n"
" 0030 - c1 68 ba cf 7c f7 .h..|.\n"
" 0036 - 7b 38 43 2f b9 0e {8C/..\n"
" 003c - 23 02 b9 4f 8c 26 #..O.&\n"
" 0042 - eb ef 70 98 82 a7 ..p...\n"
" 0048 - b9 78 c5 08 96 99 .x....\n"
" 004e - b3 84 a3 4f fb d7 ...O..\n"
" 0054 - 38 a9 d9 d4 53 0f 8...S.\n"
" 005a - 4f 64 97 df cf f3 Od....\n"
" 0060 - 4f c8 d2 56 3f 0d O..V?.\n"
" 0066 - 72 d4 55 98 89 b0 r.U...\n"
" 006c - 45 26 3f 7a bd 9d E&?z..\n"
" 0072 - 96 15 a2 10 14 85 ......\n"
" 0078 - aa a1 7c 84 fb c4 ..|...\n"
" 007e - a5 7b c6 e3 ad 85 .{....\n"
" 0084 - 57 96 bb 81 18 0c W.....\n"
" 008a - ed 2f f7 6a 4c 4d ./.jLM\n"
" 0090 - 59 e1 cc c5 3a 9f Y...:.\n"
" 0096 - 48 fc 1d 7c 0d a4 H..|..\n"
" 009c - 79 96 e7 2b 39 15 y..+9.\n"
" 00a2 - f9 3a 6a 5e 7c 4e .:j^|N\n"
" 00a8 - c9 3b af eb 3b cf .;..;.\n"
" 00ae - 8d 6a 57 e6 c5 ba .jW...\n"
" 00b4 - bd a6 a0 6b 03 d5 ...k..\n"
" 00ba - a3 9f 99 2a ea 88 ...*..\n"
" 00c0 - 72 1b 66 6c 5e 1d r.fl^.\n"
" 00c6 - 49 d5 1e 1e cc 1a I.....\n"
" 00cc - b1 d8 f7 91 1e 1e ......\n"
" 00d2 - cc 1a ..\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 53,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 c6 20 tE. \n"
" 0004 - 00 00 00 00 ....\n"
" 0008 - 00 00 00 00 ....\n"
" 000c - 00 00 00 00 ....\n"
" 0010 - 36 d8 61 48 6.aH\n"
" 0014 - 68 3c c0 68 h<.h\n"
" 0018 - aa 15 57 77 ..Ww\n"
" 001c - e3 ec b4 98 ....\n"
" 0020 - c6 08 fc 59 ...Y\n"
" 0024 - b3 4f 45 cf .OE.\n"
" 0028 - 4b c2 ae 98 K...\n"
" 002c - b5 eb e0 b5 ....\n"
" 0030 - c1 68 ba cf .h..\n"
" 0034 - 7c f7 7b 38 |.{8\n"
" 0038 - 43 2f b9 0e C/..\n"
" 003c - 23 02 b9 4f #..O\n"
" 0040 - 8c 26 eb ef .&..\n"
" 0044 - 70 98 82 a7 p...\n"
" 0048 - b9 78 c5 08 .x..\n"
" 004c - 96 99 b3 84 ....\n"
" 0050 - a3 4f fb d7 .O..\n"
" 0054 - 38 a9 d9 d4 8...\n"
" 0058 - 53 0f 4f 64 S.Od\n"
" 005c - 97 df cf f3 ....\n"
" 0060 - 4f c8 d2 56 O..V\n"
" 0064 - 3f 0d 72 d4 ?.r.\n"
" 0068 - 55 98 89 b0 U...\n"
" 006c - 45 26 3f 7a E&?z\n"
" 0070 - bd 9d 96 15 ....\n"
" 0074 - a2 10 14 85 ....\n"
" 0078 - aa a1 7c 84 ..|.\n"
" 007c - fb c4 a5 7b ...{\n"
" 0080 - c6 e3 ad 85 ....\n"
" 0084 - 57 96 bb 81 W...\n"
" 0088 - 18 0c ed 2f .../\n"
" 008c - f7 6a 4c 4d .jLM\n"
" 0090 - 59 e1 cc c5 Y...\n"
" 0094 - 3a 9f 48 fc :.H.\n"
" 0098 - 1d 7c 0d a4 .|..\n"
" 009c - 79 96 e7 2b y..+\n"
" 00a0 - 39 15 f9 3a 9..:\n"
" 00a4 - 6a 5e 7c 4e j^|N\n"
" 00a8 - c9 3b af eb .;..\n"
" 00ac - 3b cf 8d 6a ;..j\n"
" 00b0 - 57 e6 c5 ba W...\n"
" 00b4 - bd a6 a0 6b ...k\n"
" 00b8 - 03 d5 a3 9f ....\n"
" 00bc - 99 2a ea 88 .*..\n"
" 00c0 - 72 1b 66 6c r.fl\n"
" 00c4 - 5e 1d 49 d5 ^.I.\n"
" 00c8 - 1e 1e cc 1a ....\n"
" 00cc - b1 d8 f7 91 ....\n"
" 00d0 - 1e 1e cc 1a ....\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 60,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 45 tE\n"
" 0002 - c6 20 . \n"
" 0004 - 00 00 ..\n"
" 0006 - 00 00 ..\n"
" 0008 - 00 00 ..\n"
" 000a - 00 00 ..\n"
" 000c - 00 00 ..\n"
" 000e - 00 00 ..\n"
" 0010 - 36 d8 6.\n"
" 0012 - 61 48 aH\n"
" 0014 - 68 3c h<\n"
" 0016 - c0 68 .h\n"
" 0018 - aa 15 ..\n"
" 001a - 57 77 Ww\n"
" 001c - e3 ec ..\n"
" 001e - b4 98 ..\n"
" 0020 - c6 08 ..\n"
" 0022 - fc 59 .Y\n"
" 0024 - b3 4f .O\n"
" 0026 - 45 cf E.\n"
" 0028 - 4b c2 K.\n"
" 002a - ae 98 ..\n"
" 002c - b5 eb ..\n"
" 002e - e0 b5 ..\n"
" 0030 - c1 68 .h\n"
" 0032 - ba cf ..\n"
" 0034 - 7c f7 |.\n"
" 0036 - 7b 38 {8\n"
" 0038 - 43 2f C/\n"
" 003a - b9 0e ..\n"
" 003c - 23 02 #.\n"
" 003e - b9 4f .O\n"
" 0040 - 8c 26 .&\n"
" 0042 - eb ef ..\n"
" 0044 - 70 98 p.\n"
" 0046 - 82 a7 ..\n"
" 0048 - b9 78 .x\n"
" 004a - c5 08 ..\n"
" 004c - 96 99 ..\n"
" 004e - b3 84 ..\n"
" 0050 - a3 4f .O\n"
" 0052 - fb d7 ..\n"
" 0054 - 38 a9 8.\n"
" 0056 - d9 d4 ..\n"
" 0058 - 53 0f S.\n"
" 005a - 4f 64 Od\n"
" 005c - 97 df ..\n"
" 005e - cf f3 ..\n"
" 0060 - 4f c8 O.\n"
" 0062 - d2 56 .V\n"
" 0064 - 3f 0d ?.\n"
" 0066 - 72 d4 r.\n"
" 0068 - 55 98 U.\n"
" 006a - 89 b0 ..\n"
" 006c - 45 26 E&\n"
" 006e - 3f 7a ?z\n"
" 0070 - bd 9d ..\n"
" 0072 - 96 15 ..\n"
" 0074 - a2 10 ..\n"
" 0076 - 14 85 ..\n"
" 0078 - aa a1 ..\n"
" 007a - 7c 84 |.\n"
" 007c - fb c4 ..\n"
" 007e - a5 7b .{\n"
" 0080 - c6 e3 ..\n"
" 0082 - ad 85 ..\n"
" 0084 - 57 96 W.\n"
" 0086 - bb 81 ..\n"
" 0088 - 18 0c ..\n"
" 008a - ed 2f ./\n"
" 008c - f7 6a .j\n"
" 008e - 4c 4d LM\n"
" 0090 - 59 e1 Y.\n"
" 0092 - cc c5 ..\n"
" 0094 - 3a 9f :.\n"
" 0096 - 48 fc H.\n"
" 0098 - 1d 7c .|\n"
" 009a - 0d a4 ..\n"
" 009c - 79 96 y.\n"
" 009e - e7 2b .+\n"
" 00a0 - 39 15 9.\n"
" 00a2 - f9 3a .:\n"
" 00a4 - 6a 5e j^\n"
" 00a6 - 7c 4e |N\n"
" 00a8 - c9 3b .;\n"
" 00aa - af eb ..\n"
" 00ac - 3b cf ;.\n"
" 00ae - 8d 6a .j\n"
" 00b0 - 57 e6 W.\n"
" 00b2 - c5 ba ..\n"
" 00b4 - bd a6 ..\n"
" 00b6 - a0 6b .k\n"
" 00b8 - 03 d5 ..\n"
" 00ba - a3 9f ..\n"
" 00bc - 99 2a .*\n"
" 00be - ea 88 ..\n"
" 00c0 - 72 1b r.\n"
" 00c2 - 66 6c fl\n"
" 00c4 - 5e 1d ^.\n"
" 00c6 - 49 d5 I.\n"
" 00c8 - 1e 1e ..\n"
" 00ca - cc 1a ..\n"
" 00cc - b1 d8 ..\n"
" 00ce - f7 91 ..\n"
" 00d0 - 1e 1e ..\n"
" 00d2 - cc 1a ..\n"
" 00f6 - <SPACES/NULS>\n",
},
{
.indent = 67,
.input = dump,
.inlen = DUMP_LEN,
.output =
" 0000 - 74 t\n"
" 0001 - 45 E\n"
" 0002 - c6 .\n"
" 0003 - 20 \n"
" 0004 - 00 .\n"
" 0005 - 00 .\n"
" 0006 - 00 .\n"
" 0007 - 00 .\n"
" 0008 - 00 .\n"
" 0009 - 00 .\n"
" 000a - 00 .\n"
" 000b - 00 .\n"
" 000c - 00 .\n"
" 000d - 00 .\n"
" 000e - 00 .\n"
" 000f - 00 .\n"
" 0010 - 36 6\n"
" 0011 - d8 .\n"
" 0012 - 61 a\n"
" 0013 - 48 H\n"
" 0014 - 68 h\n"
" 0015 - 3c <\n"
" 0016 - c0 .\n"
" 0017 - 68 h\n"
" 0018 - aa .\n"
" 0019 - 15 .\n"
" 001a - 57 W\n"
" 001b - 77 w\n"
" 001c - e3 .\n"
" 001d - ec .\n"
" 001e - b4 .\n"
" 001f - 98 .\n"
" 0020 - c6 .\n"
" 0021 - 08 .\n"
" 0022 - fc .\n"
" 0023 - 59 Y\n"
" 0024 - b3 .\n"
" 0025 - 4f O\n"
" 0026 - 45 E\n"
" 0027 - cf .\n"
" 0028 - 4b K\n"
" 0029 - c2 .\n"
" 002a - ae .\n"
" 002b - 98 .\n"
" 002c - b5 .\n"
" 002d - eb .\n"
" 002e - e0 .\n"
" 002f - b5 .\n"
" 0030 - c1 .\n"
" 0031 - 68 h\n"
" 0032 - ba .\n"
" 0033 - cf .\n"
" 0034 - 7c |\n"
" 0035 - f7 .\n"
" 0036 - 7b {\n"
" 0037 - 38 8\n"
" 0038 - 43 C\n"
" 0039 - 2f /\n"
" 003a - b9 .\n"
" 003b - 0e .\n"
" 003c - 23 #\n"
" 003d - 02 .\n"
" 003e - b9 .\n"
" 003f - 4f O\n"
" 0040 - 8c .\n"
" 0041 - 26 &\n"
" 0042 - eb .\n"
" 0043 - ef .\n"
" 0044 - 70 p\n"
" 0045 - 98 .\n"
" 0046 - 82 .\n"
" 0047 - a7 .\n"
" 0048 - b9 .\n"
" 0049 - 78 x\n"
" 004a - c5 .\n"
" 004b - 08 .\n"
" 004c - 96 .\n"
" 004d - 99 .\n"
" 004e - b3 .\n"
" 004f - 84 .\n"
" 0050 - a3 .\n"
" 0051 - 4f O\n"
" 0052 - fb .\n"
" 0053 - d7 .\n"
" 0054 - 38 8\n"
" 0055 - a9 .\n"
" 0056 - d9 .\n"
" 0057 - d4 .\n"
" 0058 - 53 S\n"
" 0059 - 0f .\n"
" 005a - 4f O\n"
" 005b - 64 d\n"
" 005c - 97 .\n"
" 005d - df .\n"
" 005e - cf .\n"
" 005f - f3 .\n"
" 0060 - 4f O\n"
" 0061 - c8 .\n"
" 0062 - d2 .\n"
" 0063 - 56 V\n"
" 0064 - 3f ?\n"
" 0065 - 0d .\n"
" 0066 - 72 r\n"
" 0067 - d4 .\n"
" 0068 - 55 U\n"
" 0069 - 98 .\n"
" 006a - 89 .\n"
" 006b - b0 .\n"
" 006c - 45 E\n"
" 006d - 26 &\n"
" 006e - 3f ?\n"
" 006f - 7a z\n"
" 0070 - bd .\n"
" 0071 - 9d .\n"
" 0072 - 96 .\n"
" 0073 - 15 .\n"
" 0074 - a2 .\n"
" 0075 - 10 .\n"
" 0076 - 14 .\n"
" 0077 - 85 .\n"
" 0078 - aa .\n"
" 0079 - a1 .\n"
" 007a - 7c |\n"
" 007b - 84 .\n"
" 007c - fb .\n"
" 007d - c4 .\n"
" 007e - a5 .\n"
" 007f - 7b {\n"
" 0080 - c6 .\n"
" 0081 - e3 .\n"
" 0082 - ad .\n"
" 0083 - 85 .\n"
" 0084 - 57 W\n"
" 0085 - 96 .\n"
" 0086 - bb .\n"
" 0087 - 81 .\n"
" 0088 - 18 .\n"
" 0089 - 0c .\n"
" 008a - ed .\n"
" 008b - 2f /\n"
" 008c - f7 .\n"
" 008d - 6a j\n"
" 008e - 4c L\n"
" 008f - 4d M\n"
" 0090 - 59 Y\n"
" 0091 - e1 .\n"
" 0092 - cc .\n"
" 0093 - c5 .\n"
" 0094 - 3a :\n"
" 0095 - 9f .\n"
" 0096 - 48 H\n"
" 0097 - fc .\n"
" 0098 - 1d .\n"
" 0099 - 7c |\n"
" 009a - 0d .\n"
" 009b - a4 .\n"
" 009c - 79 y\n"
" 009d - 96 .\n"
" 009e - e7 .\n"
" 009f - 2b +\n"
" 00a0 - 39 9\n"
" 00a1 - 15 .\n"
" 00a2 - f9 .\n"
" 00a3 - 3a :\n"
" 00a4 - 6a j\n"
" 00a5 - 5e ^\n"
" 00a6 - 7c |\n"
" 00a7 - 4e N\n"
" 00a8 - c9 .\n"
" 00a9 - 3b ;\n"
" 00aa - af .\n"
" 00ab - eb .\n"
" 00ac - 3b ;\n"
" 00ad - cf .\n"
" 00ae - 8d .\n"
" 00af - 6a j\n"
" 00b0 - 57 W\n"
" 00b1 - e6 .\n"
" 00b2 - c5 .\n"
" 00b3 - ba .\n"
" 00b4 - bd .\n"
" 00b5 - a6 .\n"
" 00b6 - a0 .\n"
" 00b7 - 6b k\n"
" 00b8 - 03 .\n"
" 00b9 - d5 .\n"
" 00ba - a3 .\n"
" 00bb - 9f .\n"
" 00bc - 99 .\n"
" 00bd - 2a *\n"
" 00be - ea .\n"
" 00bf - 88 .\n"
" 00c0 - 72 r\n"
" 00c1 - 1b .\n"
" 00c2 - 66 f\n"
" 00c3 - 6c l\n"
" 00c4 - 5e ^\n"
" 00c5 - 1d .\n"
" 00c6 - 49 I\n"
" 00c7 - d5 .\n"
" 00c8 - 1e .\n"
" 00c9 - 1e .\n"
" 00ca - cc .\n"
" 00cb - 1a .\n"
" 00cc - b1 .\n"
" 00cd - d8 .\n"
" 00ce - f7 .\n"
" 00cf - 91 .\n"
" 00d0 - 1e .\n"
" 00d1 - 1e .\n"
" 00d2 - cc .\n"
" 00d3 - 1a .\n"
" 00f6 - <SPACES/NULS>\n",
},
};
#define N_TESTS (sizeof(bio_dump_testcases) / sizeof(bio_dump_testcases[0]))
static int
bio_dump_test(const struct bio_dump_testcase *tc)
{
BIO *bio;
char *got;
long got_len;
int ret;
int failed = 1;
if ((bio = BIO_new(BIO_s_mem())) == NULL)
errx(1, "BIO_new");
if ((ret = BIO_dump_indent(bio, tc->input, tc->inlen, tc->indent)) == -1)
errx(1, "BIO_dump_indent");
if ((got_len = BIO_get_mem_data(bio, &got)) < 0)
errx(1, "BIO_get_mem_data");
if (ret != got_len || strlen(tc->output) != (size_t)ret) {
fprintf(stderr, "indent %d: ret %d, got_len %ld, strlen %zu\n",
tc->indent, ret, got_len, strlen(tc->output));
goto err;
}
if (strncmp(tc->output, got, got_len) != 0) {
fprintf(stderr, "%d: mismatch\n", tc->indent);
goto err;
}
failed = 0;
err:
BIO_free(bio);
return failed;
}
int
main(void)
{
size_t i;
int failed = 0;
for (i = 0; i < N_TESTS; i++)
failed |= bio_dump_test(&bio_dump_testcases[i]);
return failed;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.43 2023/07/28 11:23:03 claudio Exp $ */
/* $OpenBSD: util.c,v 1.44 2024/02/03 00:38:08 jsg Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@ -701,8 +701,7 @@ print_proto(uint8_t proto)
if ((p = getprotobynumber(proto)) != NULL)
strlcpy(buf[idx], p->p_name, sizeof(buf[idx]));
else
snprintf(buf[idx], sizeof(buf), "%u", proto);
snprintf(buf[idx], sizeof(buf[idx]), "%u", proto);
return (buf[idx++]);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pfctl.c,v 1.393 2024/01/15 07:23:32 sashan Exp $ */
/* $OpenBSD: pfctl.c,v 1.394 2024/02/02 08:23:29 sashan Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@ -514,7 +514,7 @@ pfctl_kill_src_nodes(int dev, int opts)
dests++;
copy_satopfaddr(&psnk.psnk_src.addr.v.a.addr,
copy_satopfaddr(&psnk.psnk_dst.addr.v.a.addr,
resp[1]->ai_addr);
if (ioctl(dev, DIOCKILLSRCNODES, &psnk) == -1)
@ -595,7 +595,7 @@ pfctl_net_kill_states(int dev, const char *iface, int opts, int rdomain)
dests++;
copy_satopfaddr(&psk.psk_src.addr.v.a.addr,
copy_satopfaddr(&psk.psk_dst.addr.v.a.addr,
resp[1]->ai_addr);
if (ioctl(dev, DIOCKILLSTATES, &psk) == -1)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pci_machdep.c,v 1.78 2024/01/19 18:38:16 kettenis Exp $ */
/* $OpenBSD: pci_machdep.c,v 1.79 2024/02/02 21:13:35 kettenis Exp $ */
/* $NetBSD: pci_machdep.c,v 1.3 2003/05/07 21:33:58 fvdl Exp $ */
/*-
@ -499,8 +499,8 @@ pci_intr_map_msivec(struct pci_attach_args *pa, int vec,
return 1;
mme = ((reg & PCI_MSI_MC_MME_MASK) >> PCI_MSI_MC_MME_SHIFT);
if (vec > (1 << mme))
return 0;
if (vec >= (1 << mme))
return 1;
ihp->tag = PCI_MSI_PIN(tag, vec);
ihp->line = APIC_INT_VIA_MSG;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sxiccmu.c,v 1.33 2024/01/26 17:50:00 kettenis Exp $ */
/* $OpenBSD: sxiccmu.c,v 1.34 2024/02/02 12:01:49 kettenis Exp $ */
/*
* Copyright (c) 2007,2009 Dale Rahn <drahn@openbsd.org>
* Copyright (c) 2013 Artturi Alm
@ -1168,14 +1168,50 @@ sxiccmu_a80_get_frequency(struct sxiccmu_softc *sc, uint32_t idx)
}
/* Allwinner D1 */
#define D1_PLL_CPU_CTRL_REG 0x0000
#define D1_PLL_CPU_FACTOR_M(x) (((x) >> 0) & 0x3)
#define D1_PLL_CPU_FACTOR_N(x) (((x) >> 8) & 0xff)
#define D1_RISCV_CLK_REG 0x0d00
#define D1_RISCV_CLK_SEL (7 << 24)
#define D1_RISCV_CLK_SEL_HOSC (0 << 24)
#define D1_RISCV_CLK_SEL_PLL_CPU (5 << 24)
#define D1_RISCV_DIV_CFG_FACTOR_M(x) (((x) >> 0) & 0x1f)
uint32_t
sxiccmu_d1_get_frequency(struct sxiccmu_softc *sc, uint32_t idx)
{
uint32_t parent;
uint32_t reg;
uint32_t m, n;
switch (idx) {
case D1_CLK_HOSC:
return clock_get_frequency(sc->sc_node, "hosc");
case D1_CLK_PLL_CPU:
reg = SXIREAD4(sc, D1_PLL_CPU_CTRL_REG);
m = D1_PLL_CPU_FACTOR_M(reg) + 1;
n = D1_PLL_CPU_FACTOR_N(reg) + 1;
return (24000000 * n) / m;
case D1_CLK_PLL_PERIPH0:
/* Not hardcoded, but recommended. */
return 600000000;
case D1_CLK_APB1:
/* XXX Controlled by a MUX. */
return 24000000;
case D1_CLK_RISCV:
reg = SXIREAD4(sc, D1_RISCV_CLK_REG);
switch (reg & D1_RISCV_CLK_SEL) {
case D1_RISCV_CLK_SEL_HOSC:
parent = D1_CLK_HOSC;
break;
case D1_RISCV_CLK_SEL_PLL_CPU:
parent = D1_CLK_PLL_CPU;
break;
default:
return 0;
}
m = D1_RISCV_DIV_CFG_FACTOR_M(reg) + 1;
return sxiccmu_ccu_get_frequency(sc, &parent) / m;
}
printf("%s: 0x%08x\n", __func__, idx);
@ -1671,9 +1707,72 @@ sxiccmu_a80_set_frequency(struct sxiccmu_softc *sc, uint32_t idx, uint32_t freq)
return -1;
}
#define D1_SMHC0_CLK_REG 0x0830
#define D1_SMHC1_CLK_REG 0x0834
#define D1_SMHC2_CLK_REG 0x0838
#define D1_SMHC_CLK_SRC_SEL (0x3 << 24)
#define D1_SMHC_CLK_SRC_SEL_HOSC (0x0 << 24)
#define D1_SMHC_CLK_SRC_SEL_PLL_PERIPH0 (0x1 << 24)
#define D1_SMHC_FACTOR_N_MASK (0x3 << 8)
#define D1_SMHC_FACTOR_N_SHIFT 8
#define D1_SMHC_FACTOR_M_MASK (0xf << 0)
#define D1_SMHC_FACTOR_M_SHIFT 0
int
sxiccmu_d1_mmc_set_frequency(struct sxiccmu_softc *sc, bus_size_t offset,
uint32_t freq)
{
uint32_t parent_freq;
uint32_t reg, m, n;
uint32_t clk_src;
switch (freq) {
case 400000:
n = 2, m = 15;
clk_src = D1_SMHC_CLK_SRC_SEL_HOSC;
break;
case 20000000:
case 25000000:
case 26000000:
case 50000000:
case 52000000:
n = 0, m = 0;
clk_src = D1_SMHC_CLK_SRC_SEL_PLL_PERIPH0;
parent_freq =
sxiccmu_d1_get_frequency(sc, D1_CLK_PLL_PERIPH0);
while ((parent_freq / (1 << n) / 16) > freq)
n++;
while ((parent_freq / (1 << n) / (m + 1)) > freq)
m++;
break;
default:
return -1;
}
reg = SXIREAD4(sc, offset);
reg &= ~D1_SMHC_CLK_SRC_SEL;
reg |= clk_src;
reg &= ~D1_SMHC_FACTOR_N_MASK;
reg |= n << D1_SMHC_FACTOR_N_SHIFT;
reg &= ~D1_SMHC_FACTOR_M_MASK;
reg |= m << D1_SMHC_FACTOR_M_SHIFT;
SXIWRITE4(sc, offset, reg);
return 0;
}
int
sxiccmu_d1_set_frequency(struct sxiccmu_softc *sc, uint32_t idx, uint32_t freq)
{
switch (idx) {
case D1_CLK_MMC0:
return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC0_CLK_REG, freq);
case D1_CLK_MMC1:
return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC1_CLK_REG, freq);
case D1_CLK_MMC2:
return sxiccmu_d1_mmc_set_frequency(sc, D1_SMHC2_CLK_REG, freq);
}
printf("%s: 0x%08x\n", __func__, idx);
return -1;
}

View File

@ -304,7 +304,15 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_gates[] = {
/* D1 */
#define D1_CLK_PLL_CPU 0
#define D1_CLK_PLL_PERIPH0 5
#define D1_CLK_APB1 25
#define D1_CLK_MMC0 56
#define D1_CLK_MMC1 57
#define D1_CLK_MMC2 58
#define D1_CLK_BUS_MMC0 59
#define D1_CLK_BUS_MMC1 60
#define D1_CLK_BUS_MMC2 61
#define D1_CLK_BUS_UART0 62
#define D1_CLK_BUS_UART1 63
#define D1_CLK_BUS_UART2 64
@ -317,8 +325,17 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_gates[] = {
#define D1_CLK_BUS_OHCI1 100
#define D1_CLK_BUS_EHCI0 101
#define D1_CLK_BUS_EHCI1 102
#define D1_CLK_RISCV 132
#define D1_CLK_HOSC 255
const struct sxiccmu_ccu_bit sun20i_d1_gates[] = {
[D1_CLK_MMC0] = { 0x0830, 31 },
[D1_CLK_MMC1] = { 0x0834, 31 },
[D1_CLK_MMC2] = { 0x0838, 31 },
[D1_CLK_BUS_MMC0] = { 0x084c, 0 },
[D1_CLK_BUS_MMC1] = { 0x084c, 1 },
[D1_CLK_BUS_MMC2] = { 0x084c, 2 },
[D1_CLK_BUS_UART0] = { 0x090c, 0, D1_CLK_APB1 },
[D1_CLK_BUS_UART1] = { 0x090c, 1, D1_CLK_APB1 },
[D1_CLK_BUS_UART2] = { 0x090c, 2, D1_CLK_APB1 },
@ -801,6 +818,9 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_resets[] = {
/* D1 */
#define D1_RST_BUS_MMC0 15
#define D1_RST_BUS_MMC1 16
#define D1_RST_BUS_MMC2 17
#define D1_RST_BUS_UART0 18
#define D1_RST_BUS_UART1 19
#define D1_RST_BUS_UART2 20
@ -815,6 +835,9 @@ const struct sxiccmu_ccu_bit sun9i_a80_mmc_resets[] = {
#define D1_RST_BUS_EHCI1 45
const struct sxiccmu_ccu_bit sun20i_d1_resets[] = {
[D1_RST_BUS_MMC0] = { 0x084c, 16 },
[D1_RST_BUS_MMC1] = { 0x084c, 17 },
[D1_RST_BUS_MMC2] = { 0x084c, 18 },
[D1_RST_BUS_UART0] = { 0x090c, 16 },
[D1_RST_BUS_UART1] = { 0x090c, 17 },
[D1_RST_BUS_UART2] = { 0x090c, 18 },

View File

@ -1,4 +1,4 @@
/* $OpenBSD: sximmc.c,v 1.12 2021/10/24 17:52:27 mpi Exp $ */
/* $OpenBSD: sximmc.c,v 1.13 2024/02/02 12:02:26 kettenis Exp $ */
/* $NetBSD: awin_mmc.c,v 1.23 2015/11/14 10:32:40 bouyer Exp $ */
/*-
@ -261,6 +261,7 @@ struct sximmc_softc {
bus_dmamap_t sc_idma_map;
int sc_idma_ndesc;
char *sc_idma_desc;
int sc_idma_shift;
uint32_t sc_intr_rint;
uint32_t sc_intr_mint;
@ -297,6 +298,8 @@ sximmc_match(struct device *parent, void *match, void *aux)
OF_is_compatible(faa->fa_node, "allwinner,sun5i-a13-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun9i-a80-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-emmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun50i-a64-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun50i-a64-emmc"));
}
@ -394,6 +397,10 @@ sximmc_attach(struct device *parent, struct device *self, void *aux)
else
sc->sc_dma_ftrglevel = SXIMMC_DMA_FTRGLEVEL_A20;
if (OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-mmc") ||
OF_is_compatible(faa->fa_node, "allwinner,sun20i-d1-emmc"))
sc->sc_idma_shift = 2;
if (sc->sc_use_dma) {
if (sximmc_idma_setup(sc) != 0) {
printf("%s: failed to setup DMA\n", self->dv_xname);
@ -443,6 +450,8 @@ sximmc_attach(struct device *parent, struct device *self, void *aux)
}
if (OF_is_compatible(sc->sc_node, "allwinner,sun4i-a10-mmc") ||
OF_is_compatible(sc->sc_node, "allwinner,sun20i-d1-mmc") ||
OF_is_compatible(sc->sc_node, "allwinner,sun20i-d1-emmc") ||
OF_is_compatible(sc->sc_node, "allwinner,sun50i-a64-emmc")) {
saa.max_seg = 0x2000;
} else {
@ -853,8 +862,10 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd)
for (seg = 0; seg < cmd->c_dmamap->dm_nsegs; seg++) {
bus_addr_t paddr = cmd->c_dmamap->dm_segs[seg].ds_addr;
bus_size_t len = cmd->c_dmamap->dm_segs[seg].ds_len;
desc_paddr += sizeof(struct sximmc_idma_descriptor);
dma[seg].dma_buf_size = htole32(len);
dma[seg].dma_buf_addr = htole32(paddr);
dma[seg].dma_buf_addr = htole32(paddr >> sc->sc_idma_shift);
dma[seg].dma_config = htole32(SXIMMC_IDMA_CONFIG_CH |
SXIMMC_IDMA_CONFIG_OWN);
if (seg == 0) {
@ -870,9 +881,8 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd)
} else {
dma[seg].dma_config |=
htole32(SXIMMC_IDMA_CONFIG_DIC);
dma[seg].dma_next = htole32(
desc_paddr + ((seg + 1) *
sizeof(struct sximmc_idma_descriptor)));
dma[seg].dma_next =
htole32(desc_paddr >> sc->sc_idma_shift);
}
}
@ -897,7 +907,8 @@ sximmc_dma_prepare(struct sximmc_softc *sc, struct sdmmc_command *cmd)
else
val |= SXIMMC_IDST_TRANSMIT_INT;
MMC_WRITE(sc, SXIMMC_IDIE, val);
MMC_WRITE(sc, SXIMMC_DLBA, desc_paddr);
MMC_WRITE(sc, SXIMMC_DLBA,
sc->sc_idma_map->dm_segs[0].ds_addr >> sc->sc_idma_shift);
MMC_WRITE(sc, SXIMMC_FTRGLEVEL, sc->sc_dma_ftrglevel);
return 0;

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $OpenBSD: qwxreg.h,v 1.4 2024/01/30 15:32:04 stsp Exp $ */
/* $OpenBSD: qwxreg.h,v 1.5 2024/02/02 15:44:19 stsp Exp $ */
/*
* Copyright (c) 2021-2022, Qualcomm Innovation Center, Inc.
@ -10416,6 +10416,24 @@ enum rx_desc_sw_frame_grp_id {
RX_DESC_SW_FRAME_GRP_ID_PHY_ERR,
};
#define DP_MAX_NWIFI_HDR_LEN 30
#define DP_RX_MPDU_ERR_FCS BIT(0)
#define DP_RX_MPDU_ERR_DECRYPT BIT(1)
#define DP_RX_MPDU_ERR_TKIP_MIC BIT(2)
#define DP_RX_MPDU_ERR_AMSDU_ERR BIT(3)
#define DP_RX_MPDU_ERR_OVERFLOW BIT(4)
#define DP_RX_MPDU_ERR_MSDU_LEN BIT(5)
#define DP_RX_MPDU_ERR_MPDU_LEN BIT(6)
#define DP_RX_MPDU_ERR_UNENCRYPTED_FRAME BIT(7)
enum dp_rx_decap_type {
DP_RX_DECAP_TYPE_RAW,
DP_RX_DECAP_TYPE_NATIVE_WIFI,
DP_RX_DECAP_TYPE_ETHERNET2_DIX,
DP_RX_DECAP_TYPE_8023,
};
enum rx_desc_decap_type {
RX_DESC_DECAP_TYPE_RAW,
RX_DESC_DECAP_TYPE_NATIVE_WIFI,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: qwxvar.h,v 1.8 2024/01/30 15:32:04 stsp Exp $ */
/* $OpenBSD: qwxvar.h,v 1.9 2024/02/02 15:44:19 stsp Exp $ */
/*
* Copyright (c) 2018-2019 The Linux Foundation.
@ -221,21 +221,27 @@ struct ath11k_hw_ops {
struct hal_tcl_data_cmd *tcl_cmd);
bool (*rx_desc_get_first_msdu)(struct hal_rx_desc *desc);
bool (*rx_desc_get_last_msdu)(struct hal_rx_desc *desc);
#endif
uint8_t (*rx_desc_get_l3_pad_bytes)(struct hal_rx_desc *desc);
uint8_t *(*rx_desc_get_hdr_status)(struct hal_rx_desc *desc);
bool (*rx_desc_encrypt_valid)(struct hal_rx_desc *desc);
int (*rx_desc_encrypt_valid)(struct hal_rx_desc *desc);
uint32_t (*rx_desc_get_encrypt_type)(struct hal_rx_desc *desc);
uint8_t (*rx_desc_get_decap_type)(struct hal_rx_desc *desc);
#ifdef notyet
uint8_t (*rx_desc_get_mesh_ctl)(struct hal_rx_desc *desc);
bool (*rx_desc_get_ldpc_support)(struct hal_rx_desc *desc);
bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc);
bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc);
uint16_t (*rx_desc_get_mpdu_start_seq_no)(struct hal_rx_desc *desc);
#endif
uint16_t (*rx_desc_get_msdu_len)(struct hal_rx_desc *desc);
#ifdef notyet
uint8_t (*rx_desc_get_msdu_sgi)(struct hal_rx_desc *desc);
uint8_t (*rx_desc_get_msdu_rate_mcs)(struct hal_rx_desc *desc);
uint8_t (*rx_desc_get_msdu_rx_bw)(struct hal_rx_desc *desc);
#endif
uint32_t (*rx_desc_get_msdu_freq)(struct hal_rx_desc *desc);
#ifdef notyet
uint8_t (*rx_desc_get_msdu_pkt_type)(struct hal_rx_desc *desc);
uint8_t (*rx_desc_get_msdu_nss)(struct hal_rx_desc *desc);
uint8_t (*rx_desc_get_mpdu_tid)(struct hal_rx_desc *desc);
@ -245,7 +251,9 @@ struct ath11k_hw_ops {
uint32_t (*rx_desc_get_mpdu_start_tag)(struct hal_rx_desc *desc);
uint32_t (*rx_desc_get_mpdu_ppdu_id)(struct hal_rx_desc *desc);
void (*rx_desc_set_msdu_len)(struct hal_rx_desc *desc, uint16_t len);
#endif
struct rx_attention *(*rx_desc_get_attention)(struct hal_rx_desc *desc);
#ifdef notyet
uint8_t *(*rx_desc_get_msdu_payload)(struct hal_rx_desc *desc);
#endif
void (*reo_setup)(struct qwx_softc *);
@ -695,9 +703,10 @@ struct ce_attr {
#define CE_DESC_RING_ALIGN 8
struct qwx_rx_data {
struct mbuf *m;
bus_dmamap_t map;
struct qwx_rx_msdu {
TAILQ_ENTRY(qwx_rx_msdu) entry;
struct mbuf *m;
struct ieee80211_rxinfo rxi;
int is_first_msdu;
int is_last_msdu;
int is_continuation;
@ -714,6 +723,14 @@ struct qwx_rx_data {
uint16_t seq_no;
};
TAILQ_HEAD(qwx_rx_msdu_list, qwx_rx_msdu);
struct qwx_rx_data {
struct mbuf *m;
bus_dmamap_t map;
struct qwx_rx_msdu rx_msdu;
};
struct qwx_tx_data {
struct mbuf *m;
bus_dmamap_t map;

View File

@ -3989,16 +3989,13 @@ static int gfx_v10_0_init_microcode(struct amdgpu_device *adev)
if (!amdgpu_sriov_vf(adev)) {
snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_rlc.bin", ucode_prefix);
err = amdgpu_ucode_request(adev, &adev->gfx.rlc_fw, fw_name);
/* don't check this. There are apparently firmwares in the wild with
* incorrect size in the header
*/
if (err == -ENODEV)
goto out;
err = request_firmware(&adev->gfx.rlc_fw, fw_name, adev->dev);
if (err)
dev_dbg(adev->dev,
"gfx10: amdgpu_ucode_request() failed \"%s\"\n",
fw_name);
goto out;
/* don't validate this firmware. There are apparently firmwares
* in the wild with incorrect size in the header
*/
rlc_hdr = (const struct rlc_firmware_header_v2_0 *)adev->gfx.rlc_fw->data;
version_major = le16_to_cpu(rlc_hdr->header.header_version_major);
version_minor = le16_to_cpu(rlc_hdr->header.header_version_minor);
@ -6575,7 +6572,7 @@ static int gfx_v10_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
#ifdef __BIG_ENDIAN
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, ENDIAN_SWAP, 1);
#endif
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 1);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);

View File

@ -3807,7 +3807,7 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
(order_base_2(prop->queue_size / 4) - 1));
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, RPTR_BLOCK_SIZE,
(order_base_2(AMDGPU_GPU_PAGE_SIZE / 4) - 1));
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 0);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, UNORD_DISPATCH, 1);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
@ -6353,6 +6353,9 @@ static int gfx_v11_0_get_cu_info(struct amdgpu_device *adev,
mutex_lock(&adev->grbm_idx_mutex);
for (i = 0; i < adev->gfx.config.max_shader_engines; i++) {
for (j = 0; j < adev->gfx.config.max_sh_per_se; j++) {
bitmap = i * adev->gfx.config.max_sh_per_se + j;
if (!((gfx_v11_0_get_sa_active_bitmap(adev) >> bitmap) & 1))
continue;
mask = 1;
counter = 0;
gfx_v11_0_select_se_sh(adev, i, j, 0xffffffff, 0);

View File

@ -170,6 +170,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
m->cp_hqd_pq_control = 5 << CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE__SHIFT;
m->cp_hqd_pq_control |=
ffs(q->queue_size / sizeof(unsigned int)) - 1 - 1;
m->cp_hqd_pq_control |= CP_HQD_PQ_CONTROL__UNORD_DISPATCH_MASK;
pr_debug("cp_hqd_pq_control 0x%x\n", m->cp_hqd_pq_control);
m->cp_hqd_pq_base_lo = lower_32_bits((uint64_t)q->queue_address >> 8);

View File

@ -224,6 +224,7 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
m->cp_hqd_pq_control = 5 << CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE__SHIFT;
m->cp_hqd_pq_control |=
ffs(q->queue_size / sizeof(unsigned int)) - 1 - 1;
m->cp_hqd_pq_control |= CP_HQD_PQ_CONTROL__UNORD_DISPATCH_MASK;
pr_debug("cp_hqd_pq_control 0x%x\n", m->cp_hqd_pq_control);
m->cp_hqd_pq_base_lo = lower_32_bits((uint64_t)q->queue_address >> 8);

View File

@ -956,6 +956,11 @@ int dm_helper_dmub_aux_transfer_sync(
struct aux_payload *payload,
enum aux_return_code_type *operation_result)
{
if (!link->hpd_status) {
*operation_result = AUX_RET_ERROR_HPD_DISCON;
return -1;
}
return amdgpu_dm_process_dmub_aux_transfer_sync(ctx, link->link_index, payload,
operation_result);
}

View File

@ -131,30 +131,27 @@ static int dcn314_get_active_display_cnt_wa(
return display_count;
}
static void dcn314_disable_otg_wa(struct clk_mgr *clk_mgr_base, struct dc_state *context, bool disable)
static void dcn314_disable_otg_wa(struct clk_mgr *clk_mgr_base, struct dc_state *context,
bool safe_to_lower, bool disable)
{
struct dc *dc = clk_mgr_base->ctx->dc;
int i;
for (i = 0; i < dc->res_pool->pipe_count; ++i) {
struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
struct pipe_ctx *pipe = safe_to_lower
? &context->res_ctx.pipe_ctx[i]
: &dc->current_state->res_ctx.pipe_ctx[i];
if (pipe->top_pipe || pipe->prev_odm_pipe)
continue;
if (pipe->stream && (pipe->stream->dpms_off || dc_is_virtual_signal(pipe->stream->signal))) {
struct stream_encoder *stream_enc = pipe->stream_res.stream_enc;
if (disable) {
if (stream_enc && stream_enc->funcs->disable_fifo)
pipe->stream_res.stream_enc->funcs->disable_fifo(stream_enc);
if (pipe->stream_res.tg && pipe->stream_res.tg->funcs->immediate_disable_crtc)
pipe->stream_res.tg->funcs->immediate_disable_crtc(pipe->stream_res.tg);
pipe->stream_res.tg->funcs->immediate_disable_crtc(pipe->stream_res.tg);
reset_sync_context_for_pipe(dc, context, i);
} else {
pipe->stream_res.tg->funcs->enable_crtc(pipe->stream_res.tg);
if (stream_enc && stream_enc->funcs->enable_fifo)
pipe->stream_res.stream_enc->funcs->enable_fifo(stream_enc);
}
}
}
@ -252,11 +249,11 @@ void dcn314_update_clocks(struct clk_mgr *clk_mgr_base,
}
if (should_set_clock(safe_to_lower, new_clocks->dispclk_khz, clk_mgr_base->clks.dispclk_khz)) {
dcn314_disable_otg_wa(clk_mgr_base, context, true);
dcn314_disable_otg_wa(clk_mgr_base, context, safe_to_lower, true);
clk_mgr_base->clks.dispclk_khz = new_clocks->dispclk_khz;
dcn314_smu_set_dispclk(clk_mgr, clk_mgr_base->clks.dispclk_khz);
dcn314_disable_otg_wa(clk_mgr_base, context, false);
dcn314_disable_otg_wa(clk_mgr_base, context, safe_to_lower, false);
update_dispclk = true;
}

View File

@ -873,11 +873,15 @@ bool link_set_dsc_pps_packet(struct pipe_ctx *pipe_ctx, bool enable, bool immedi
{
struct display_stream_compressor *dsc = pipe_ctx->stream_res.dsc;
struct dc_stream_state *stream = pipe_ctx->stream;
DC_LOGGER_INIT(dsc->ctx->logger);
if (!pipe_ctx->stream->timing.flags.DSC || !dsc)
if (!pipe_ctx->stream->timing.flags.DSC)
return false;
if (!dsc)
return false;
DC_LOGGER_INIT(dsc->ctx->logger);
if (enable) {
struct dsc_config dsc_cfg;
uint8_t dsc_packed_pps[128];

View File

@ -205,7 +205,7 @@ enum dc_status core_link_read_dpcd(
uint32_t extended_size;
/* size of the remaining partitioned address space */
uint32_t size_left_to_read;
enum dc_status status;
enum dc_status status = DC_ERROR_UNEXPECTED;
/* size of the next partition to be read from */
uint32_t partition_size;
uint32_t data_index = 0;
@ -234,7 +234,7 @@ enum dc_status core_link_write_dpcd(
{
uint32_t partition_size;
uint32_t data_index = 0;
enum dc_status status;
enum dc_status status = DC_ERROR_UNEXPECTED;
while (size) {
partition_size = dpcd_get_next_partition_size(address, size);

View File

@ -920,8 +920,8 @@ bool edp_get_replay_state(const struct dc_link *link, uint64_t *state)
bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream)
{
/* To-do: Setup Replay */
struct dc *dc = link->ctx->dc;
struct dmub_replay *replay = dc->res_pool->replay;
struct dc *dc;
struct dmub_replay *replay;
int i;
unsigned int panel_inst;
struct replay_context replay_context = { 0 };
@ -937,6 +937,10 @@ bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream
if (!link)
return false;
dc = link->ctx->dc;
replay = dc->res_pool->replay;
if (!replay)
return false;
@ -965,8 +969,7 @@ bool edp_setup_replay(struct dc_link *link, const struct dc_stream_state *stream
replay_context.line_time_in_ns = lineTimeInNs;
if (replay)
link->replay_settings.replay_feature_enabled =
link->replay_settings.replay_feature_enabled =
replay->funcs->replay_copy_settings(replay, link, &replay_context, panel_inst);
if (link->replay_settings.replay_feature_enabled) {

View File

@ -24,6 +24,7 @@
#include <linux/firmware.h>
#include <linux/pci.h>
#include <linux/power_supply.h>
#include <linux/reboot.h>
#include "amdgpu.h"
@ -741,16 +742,8 @@ static int smu_late_init(void *handle)
* handle the switch automatically. Driver involvement
* is unnecessary.
*/
if (!smu->dc_controlled_by_gpio) {
ret = smu_set_power_source(smu,
adev->pm.ac_power ? SMU_POWER_SOURCE_AC :
SMU_POWER_SOURCE_DC);
if (ret) {
dev_err(adev->dev, "Failed to switch to %s mode!\n",
adev->pm.ac_power ? "AC" : "DC");
return ret;
}
}
adev->pm.ac_power = power_supply_is_system_supplied() > 0;
smu_set_ac_dc(smu);
if ((adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 1)) ||
(adev->ip_versions[MP1_HWIP][0] == IP_VERSION(13, 0, 3)))

View File

@ -1441,10 +1441,12 @@ static int smu_v11_0_irq_process(struct amdgpu_device *adev,
case 0x3:
dev_dbg(adev->dev, "Switched to AC mode!\n");
schedule_work(&smu->interrupt_work);
adev->pm.ac_power = true;
break;
case 0x4:
dev_dbg(adev->dev, "Switched to DC mode!\n");
schedule_work(&smu->interrupt_work);
adev->pm.ac_power = false;
break;
case 0x7:
/*

View File

@ -1377,10 +1377,12 @@ static int smu_v13_0_irq_process(struct amdgpu_device *adev,
case 0x3:
dev_dbg(adev->dev, "Switched to AC mode!\n");
smu_v13_0_ack_ac_dc_interrupt(smu);
adev->pm.ac_power = true;
break;
case 0x4:
dev_dbg(adev->dev, "Switched to DC mode!\n");
smu_v13_0_ack_ac_dc_interrupt(smu);
adev->pm.ac_power = false;
break;
case 0x7:
/*

View File

@ -241,7 +241,8 @@ drm_atomic_helper_damage_iter_init(struct drm_atomic_helper_damage_iter *iter,
iter->plane_src.x2 = (src.x2 >> 16) + !!(src.x2 & 0xFFFF);
iter->plane_src.y2 = (src.y2 >> 16) + !!(src.y2 & 0xFFFF);
if (!iter->clips || !drm_rect_equals(&state->src, &old_state->src)) {
if (!iter->clips || state->ignore_damage_clips ||
!drm_rect_equals(&state->src, &old_state->src)) {
iter->clips = NULL;
iter->num_clips = 0;
iter->full_update = true;

View File

@ -678,6 +678,19 @@ int drm_mode_getplane_res(struct drm_device *dev, void *data,
!file_priv->universal_planes)
continue;
/*
* If we're running on a virtualized driver then,
* unless userspace advertizes support for the
* virtualized cursor plane, disable cursor planes
* because they'll be broken due to missing cursor
* hotspot info.
*/
if (plane->type == DRM_PLANE_TYPE_CURSOR &&
drm_core_check_feature(dev, DRIVER_CURSOR_HOTSPOT) &&
file_priv->atomic &&
!file_priv->supports_virtualized_cursor_plane)
continue;
if (drm_lease_held(file_priv, plane->base.id)) {
if (count < plane_resp->count_planes &&
put_user(plane->base.id, plane_ptr + count))
@ -1387,6 +1400,7 @@ retry:
out:
if (fb)
drm_framebuffer_put(fb);
fb = NULL;
if (plane->old_fb)
drm_framebuffer_put(plane->old_fb);
plane->old_fb = NULL;

View File

@ -1155,6 +1155,7 @@ static void gen11_dsi_powerup_panel(struct intel_encoder *encoder)
}
intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_INIT_OTP);
intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
/* ensure all panel commands dispatched before enabling transcoder */
wait_for_cmds_dispatched_to_panel(encoder);
@ -1255,8 +1256,6 @@ static void gen11_dsi_enable(struct intel_atomic_state *state,
/* step6d: enable dsi transcoder */
gen11_dsi_enable_transcoder(encoder);
intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_DISPLAY_ON);
/* step7: enable backlight */
intel_backlight_enable(crtc_state, conn_state);
intel_dsi_vbt_exec_sequence(intel_dsi, MIPI_SEQ_BACKLIGHT_ON);

View File

@ -674,7 +674,9 @@ static void hsw_activate_psr1(struct intel_dp *intel_dp)
val |= EDP_PSR_IDLE_FRAMES(psr_compute_idle_frames(intel_dp));
val |= EDP_PSR_MAX_SLEEP_TIME(max_sleep_time);
if (DISPLAY_VER(dev_priv) < 20)
val |= EDP_PSR_MAX_SLEEP_TIME(max_sleep_time);
if (IS_HASWELL(dev_priv))
val |= EDP_PSR_MIN_LINK_ENTRY_TIME_8_LINES;
@ -1398,9 +1400,21 @@ static void intel_psr_enable_source(struct intel_dp *intel_dp,
* can rely on frontbuffer tracking.
*/
mask = EDP_PSR_DEBUG_MASK_MEMUP |
EDP_PSR_DEBUG_MASK_HPD |
EDP_PSR_DEBUG_MASK_LPSP |
EDP_PSR_DEBUG_MASK_MAX_SLEEP;
EDP_PSR_DEBUG_MASK_HPD;
/*
* For some unknown reason on HSW non-ULT (or at least on
* Dell Latitude E6540) external displays start to flicker
* when PSR is enabled on the eDP. SR/PC6 residency is much
* higher than should be possible with an external display.
* As a workaround leave LPSP unmasked to prevent PSR entry
* when external displays are active.
*/
if (DISPLAY_VER(dev_priv) >= 8 || IS_HASWELL_ULT(dev_priv))
mask |= EDP_PSR_DEBUG_MASK_LPSP;
if (DISPLAY_VER(dev_priv) < 20)
mask |= EDP_PSR_DEBUG_MASK_MAX_SLEEP;
/*
* No separate pipe reg write mask on hsw/bdw, so have to unmask all

View File

@ -112,6 +112,15 @@ enum drm_driver_feature {
* Driver supports user defined GPU VA bindings for GEM objects.
*/
DRIVER_GEM_GPUVA = BIT(8),
/**
* @DRIVER_CURSOR_HOTSPOT:
*
* Driver supports and requires cursor hotspot information in the
* cursor plane (e.g. cursor plane has to actually track the mouse
* cursor and the clients are required to set hotspot in order for
* the cursor planes to work correctly).
*/
DRIVER_CURSOR_HOTSPOT = BIT(9),
/* IMPORTANT: Below are all the legacy flags, add new ones above. */

View File

@ -231,6 +231,18 @@ struct drm_file {
*/
bool is_master;
/**
* @supports_virtualized_cursor_plane:
*
* This client is capable of handling the cursor plane with the
* restrictions imposed on it by the virtualized drivers.
*
* This implies that the cursor plane has to behave like a cursor
* i.e. track cursor movement. It also requires setting of the
* hotspot properties by the client on the cursor plane.
*/
bool supports_virtualized_cursor_plane;
/**
* @master:
*

View File

@ -190,6 +190,16 @@ struct drm_plane_state {
*/
struct drm_property_blob *fb_damage_clips;
/**
* @ignore_damage_clips:
*
* Set by drivers to indicate the drm_atomic_helper_damage_iter_init()
* helper that the @fb_damage_clips blob property should be ignored.
*
* See :ref:`damage_tracking_properties` for more information.
*/
bool ignore_damage_clips;
/**
* @src:
*

View File

@ -1,4 +1,4 @@
/* $OpenBSD: in_pcb.c,v 1.288 2024/01/31 12:27:57 bluhm Exp $ */
/* $OpenBSD: in_pcb.c,v 1.289 2024/02/02 15:39:23 bluhm Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
@ -911,7 +911,7 @@ in_pcbrtentry(struct inpcb *inp)
#ifdef INET6
if (ISSET(inp->inp_flags, INP_IPV6))
in6_pcbrtentry(inp);
return in6_pcbrtentry(inp);
#endif
ro = &inp->inp_route;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rde.c,v 1.620 2024/01/30 13:50:09 claudio Exp $ */
/* $OpenBSD: rde.c,v 1.622 2024/02/03 00:11:34 jsg Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -2484,7 +2484,7 @@ rde_update_err(struct rde_peer *peer, uint8_t error, uint8_t suberr,
fatal("%s %d imsg_add error", __func__, __LINE__);
if (opt != NULL)
if (ibuf_add_ibuf(wbuf, opt) == -1)
fatal("%s %d imsg_add error", __func__, __LINE__);
fatal("%s %d ibuf_add_ibuf error", __func__, __LINE__);
imsg_close(ibuf_se, wbuf);
peer->state = PEER_ERR;
}
@ -4244,8 +4244,7 @@ rde_peer_send_eor(struct rde_peer *peer, uint8_t aid)
if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
0, -1, &buf, 10) == -1)
fatal("%s %d imsg_compose error in peer_send_eor",
__func__, __LINE__);
fatal("%s %d imsg_compose error", __func__, __LINE__);
}
log_peer_info(&peer->conf, "sending %s EOR marker",
@ -4274,6 +4273,7 @@ rde_peer_send_rrefresh(struct rde_peer *peer, uint8_t aid, uint8_t subtype)
if (imsg_compose(ibuf_se, IMSG_REFRESH, peer->conf.id, 0, -1,
&rr, sizeof(rr)) == -1)
fatal("%s %d imsg_compose error", __func__, __LINE__);
log_peer_info(&peer->conf, "sending %s %s marker",
aid2str(aid), subtype == ROUTE_REFRESH_END_RR ? "EoRR" : "BoRR");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.80 2024/01/30 13:50:09 claudio Exp $ */
/* $OpenBSD: util.c,v 1.81 2024/02/02 16:14:51 claudio Exp $ */
/*
* Copyright (c) 2006 Claudio Jeker <claudio@openbsd.org>
@ -547,8 +547,12 @@ aspath_inflate(struct ibuf *in)
uint16_t short_as;
uint8_t seg_type, seg_len;
/* allocate enough space for the worst case */
if ((out = ibuf_open(ibuf_size(in) * 2)) == NULL)
/*
* Allocate enough space for the worst case.
* XXX add 1 byte for the empty ASPATH case since we can't
* allocate an ibuf of 0 length.
*/
if ((out = ibuf_open(ibuf_size(in) * 2 + 1)) == NULL)
return (NULL);
/* then copy the aspath */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mft.c,v 1.102 2024/01/31 06:57:21 tb Exp $ */
/* $OpenBSD: mft.c,v 1.103 2024/02/02 19:26:49 job Exp $ */
/*
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -301,16 +301,6 @@ mft_parse_econtent(const unsigned char *d, size_t dsz, struct parse *p)
if (p->res->seqnum == NULL)
goto out;
/*
* Timestamps: this and next update time.
* Validate that the current date falls into this interval.
* This is required by section 4.4, (3).
* If we're after the given date, then the MFT is stale.
* This is made super complicated because it uses OpenSSL's
* ASN1_GENERALIZEDTIME instead of ASN1_TIME, which we could
* compare against the current time trivially.
*/
if (!mft_parse_time(mft->thisUpdate, mft->nextUpdate, p))
goto out;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: parser.c,v 1.114 2024/02/01 09:50:15 tb Exp $ */
/* $OpenBSD: parser.c,v 1.126 2024/02/02 22:09:56 tb Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -169,6 +169,9 @@ proc_parser_mft_check(const char *fn, struct mft *p)
int rc = 1;
char *path;
if (p == NULL)
return 0;
for (i = 0; i < p->filesz; i++) {
struct mftfile *m = &p->files[i];
int try, fd = -1, noent = 0, valid = 0;
@ -251,44 +254,43 @@ parse_load_crl_from_mft(struct entity *entp, struct mft *mft, enum location loc,
}
/*
* Parse and validate a manifest file. Skip checking the fileandhash
* this is done in the post check. After this step we know the mft is
* valid and can be compared.
* Return the mft on success or NULL on failure.
* Parse and validate a manifest file.
* Don't check the fileandhash, this is done later on.
* Return the mft on success, or NULL on failure.
*/
static struct mft *
proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
struct crl **crl, char **crlfile, struct mft *cached_mft,
const char **errstr)
proc_parser_mft_pre(struct entity *entp, char *file, struct crl **crl,
char **crlfile, struct mft *cached_mft, const char **errstr)
{
struct mft *mft;
X509 *x509;
struct auth *a;
unsigned char *der;
size_t len;
time_t now;
int issued_cmp, seqnum_cmp;
*crl = NULL;
*crlfile = NULL;
*errstr = NULL;
/* XXX - pull this into proc_parser_mft. */
*file = parse_filepath(entp->repoid, entp->path, entp->file, loc);
if (*file == NULL)
if (file == NULL)
return NULL;
if (noop && loc == DIR_TEMP)
return NULL;
der = load_file(*file, &len);
der = load_file(file, &len);
if (der == NULL && errno != ENOENT)
warn("parse file %s", *file);
warn("parse file %s", file);
if ((mft = mft_parse(&x509, *file, entp->talid, der, len)) == NULL) {
if ((mft = mft_parse(&x509, file, entp->talid, der, len)) == NULL) {
free(der);
return NULL;
}
if (entp->path != NULL) {
if ((mft->path = strdup(entp->path)) == NULL)
err(1, NULL);
}
if (!EVP_Digest(der, len, mft->mfthash, NULL, EVP_sha256(), NULL))
errx(1, "EVP_Digest failed");
@ -298,8 +300,8 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
if (*crl == NULL)
*crl = parse_load_crl_from_mft(entp, mft, DIR_VALID, crlfile);
a = valid_ski_aki(*file, &auths, mft->ski, mft->aki, NULL);
if (!valid_x509(*file, ctx, x509, a, *crl, errstr))
a = valid_ski_aki(file, &auths, mft->ski, mft->aki, NULL);
if (!valid_x509(file, ctx, x509, a, *crl, errstr))
goto err;
X509_free(x509);
x509 = NULL;
@ -307,6 +309,21 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
mft->repoid = entp->repoid;
mft->talid = a->cert->talid;
now = get_current_time();
/* check that now is not before from */
if (now < mft->thisupdate) {
warnx("%s: manifest not yet valid %s", file,
time2str(mft->thisupdate));
mft->stale = 1;
}
/* check that now is not after until */
if (now > mft->nextupdate) {
warnx("%s: manifest expired on %s", file,
time2str(mft->nextupdate));
mft->stale = 1;
}
/* if there is nothing to compare to, return now */
if (cached_mft == NULL)
return mft;
@ -316,33 +333,33 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
*/
if ((issued_cmp = mft_compare_issued(mft, cached_mft)) < 0) {
warnx("%s: unexpected manifest issuance time (want >= %lld, "
"got %lld)", *file, (long long)cached_mft->thisupdate,
warnx("%s: unexpected manifest issuance date (want >= %lld, "
"got %lld)", file, (long long)cached_mft->thisupdate,
(long long)mft->thisupdate);
goto err;
}
if ((seqnum_cmp = mft_compare_seqnum(mft, cached_mft)) < 0) {
warnx("%s: unexpected manifest number (want >= #%s, got #%s)",
*file, cached_mft->seqnum, mft->seqnum);
file, cached_mft->seqnum, mft->seqnum);
goto err;
}
if (issued_cmp > 0 && seqnum_cmp == 0) {
warnx("%s#%s: manifest issued at %lld and %lld with same "
"sequence number", *file, cached_mft->seqnum,
(long long)mft->thisupdate,
(long long)cached_mft->thisupdate);
warnx("%s: manifest issued at %lld and %lld with same "
"manifest number #%s", file, (long long)mft->thisupdate,
(long long)cached_mft->thisupdate, cached_mft->seqnum);
goto err;
}
if (issued_cmp == 0 && seqnum_cmp > 0) {
warnx("%s#%s: reissued manifest same issuance time %lld as #%s",
*file, mft->seqnum, (long long)mft->thisupdate,
cached_mft->seqnum);
warnx("%s: #%s and #%s were issued at same issuance date %lld",
file, mft->seqnum, cached_mft->seqnum,
(long long)mft->thisupdate);
goto err;
}
if (issued_cmp == 0 && seqnum_cmp == 0 && memcmp(mft->mfthash,
cached_mft->mfthash, SHA256_DIGEST_LENGTH) != 0) {
warnx("%s: manifest misissuance, #%s was recycled",
*file, mft->seqnum);
warnx("%s: misissuance, issuance date %lld and manifest number "
"#%s were recycled", file, (long long)mft->thisupdate,
mft->seqnum);
goto err;
}
@ -358,52 +375,6 @@ proc_parser_mft_pre(struct entity *entp, enum location loc, char **file,
return NULL;
}
/*
* Do the end of manifest validation.
* Return the mft on success or NULL on failure.
*/
static struct mft *
proc_parser_mft_post(char *file, struct mft *mft, const char *path,
const char *errstr, int *warned)
{
/* check that now is not before from */
time_t now = get_current_time();
if (mft == NULL) {
if (errstr == NULL)
errstr = "no valid mft available";
if ((*warned)++ > 0)
return NULL;
warnx("%s: %s", file, errstr);
return NULL;
}
/* check that now is not before from */
if (now < mft->thisupdate) {
warnx("%s: mft not yet valid %s", file,
time2str(mft->thisupdate));
mft->stale = 1;
}
/* check that now is not after until */
if (now > mft->nextupdate) {
warnx("%s: mft expired on %s", file,
time2str(mft->nextupdate));
mft->stale = 1;
}
if (path != NULL)
if ((mft->path = strdup(path)) == NULL)
err(1, NULL);
if (!mft->stale)
if (!proc_parser_mft_check(file, mft)) {
mft_free(mft);
return NULL;
}
return mft;
}
/*
* Load the most recent MFT by opening both options and comparing the two.
*/
@ -412,49 +383,51 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile,
time_t *crlmtime)
{
struct mft *mft1 = NULL, *mft2 = NULL;
struct crl *crl, *crl1, *crl2;
char *file, *file1, *file2, *crl1file, *crl2file;
const char *err1, *err2;
int warned = 0;
struct crl *crl, *crl1 = NULL, *crl2 = NULL;
char *file, *file1 = NULL, *file2 = NULL;
char *crl1file = NULL, *crl2file = NULL;
const char *err1 = NULL, *err2 = NULL;
*mp = NULL;
*crlmtime = 0;
mft2 = proc_parser_mft_pre(entp, DIR_VALID, &file2, &crl2, &crl2file,
NULL, &err2);
mft1 = proc_parser_mft_pre(entp, DIR_TEMP, &file1, &crl1, &crl1file,
mft2, &err1);
file2 = parse_filepath(entp->repoid, entp->path, entp->file, DIR_VALID);
mft2 = proc_parser_mft_pre(entp, file2, &crl2, &crl2file, NULL, &err2);
/* overload error from temp file if it is set */
if (mft1 == NULL && mft2 == NULL)
if (err1 != NULL)
err2 = err1;
if (!noop && mft1 != NULL) {
*mp = proc_parser_mft_post(file1, mft1, entp->path, err1,
&warned);
if (*mp == NULL) {
mft1 = NULL;
if (mft2 != NULL)
warnx("%s: failed fetch, continuing with #%s"
" from cache", file2, mft2->seqnum);
}
if (!noop) {
file1 = parse_filepath(entp->repoid, entp->path, entp->file,
DIR_TEMP);
mft1 = proc_parser_mft_pre(entp, file1, &crl1, &crl1file, mft2,
&err1);
}
if (*mp != NULL) {
if (proc_parser_mft_check(file1, mft1)) {
mft_free(mft2);
crl_free(crl2);
free(crl2file);
free(file2);
*mp = mft1;
crl = crl1;
file = file1;
*crlfile = crl1file;
} else {
if (err2 == NULL)
err2 = err1;
*mp = proc_parser_mft_post(file2, mft2, entp->path, err2,
&warned);
if (mft1 != NULL && mft2 != NULL)
warnx("%s: failed fetch, continuing with #%s "
"from cache", file2, mft2->seqnum);
if (proc_parser_mft_check(file2, mft2)) {
*mp = mft2;
} else {
mft_free(mft2);
mft2 = NULL;
if (err2 == NULL)
err2 = err1;
if (err2 == NULL)
err2 = "no valid manifest available";
warnx("%s: %s", file2, err2);
}
mft_free(mft1);
crl_free(crl1);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: lka_session.c,v 1.98 2023/11/03 13:40:07 op Exp $ */
/* $OpenBSD: lka_session.c,v 1.100 2024/02/02 23:33:42 gilles Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@ -397,6 +397,7 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
}
xn->realuser = 1;
xn->realuser_uid = lk.userinfo.uid;
if (xn->sameuser && xn->parent->forwarded) {
log_trace(TRACE_EXPAND, "expand: lka_expand: same "
@ -405,6 +406,20 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
}
/* when alternate delivery user is provided,
* skip other users forward files.
*/
if (dsp->u.local.user) {
if (strcmp(dsp->u.local.user, xn->u.user) != 0) {
log_trace(TRACE_EXPAND, "expand: lka_expand: "
"alternate delivery user mismatch recipient "
"user, skip .forward, submitting");
lka_submit(lks, rule, xn);
break;
}
}
/* no aliases found, query forward file */
lks->rule = rule;
lks->node = xn;
@ -423,6 +438,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
case EXPAND_FILENAME:
if (xn->parent->realuser && xn->parent->realuser_uid == 0) {
log_trace(TRACE_EXPAND, "expand: filename not allowed in root's forward");
lks->error = LKA_TEMPFAIL;
break;
}
dsp = dict_xget(env->sc_dispatchers, rule->dispatcher);
if (dsp->u.local.forward_only) {
log_trace(TRACE_EXPAND, "expand: filename matched on forward-only rule");
@ -451,6 +472,12 @@ lka_expand(struct lka_session *lks, struct rule *rule, struct expandnode *xn)
break;
case EXPAND_FILTER:
if (xn->parent->realuser && xn->parent->realuser_uid == 0) {
log_trace(TRACE_EXPAND, "expand: filter not allowed in root's forward");
lks->error = LKA_TEMPFAIL;
break;
}
dsp = dict_xget(env->sc_dispatchers, rule->dispatcher);
if (dsp->u.local.forward_only) {
log_trace(TRACE_EXPAND, "expand: filter matched on forward-only rule");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.296 2023/12/03 11:52:16 op Exp $ */
/* $OpenBSD: parse.y,v 1.297 2024/02/02 20:54:27 millert Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@ -697,12 +697,10 @@ MBOX {
| LMTP STRING {
asprintf(&dsp->u.local.command,
"/usr/libexec/mail.lmtp -d %s -u", $2);
dsp->u.local.user = SMTPD_USER;
} dispatcher_local_options
| LMTP STRING RCPT_TO {
asprintf(&dsp->u.local.command,
"/usr/libexec/mail.lmtp -d %s -r", $2);
dsp->u.local.user = SMTPD_USER;
} dispatcher_local_options
| MDA STRING {
asprintf(&dsp->u.local.command,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: smtpd.c,v 1.347 2024/01/20 09:01:03 claudio Exp $ */
/* $OpenBSD: smtpd.c,v 1.348 2024/02/02 22:02:12 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@ -1425,16 +1425,9 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver)
pw_dir = deliver->userinfo.directory;
}
if (pw_uid == 0 && deliver->mda_exec[0]) {
pw_name = deliver->userinfo.username;
pw_uid = deliver->userinfo.uid;
pw_gid = deliver->userinfo.gid;
pw_dir = deliver->userinfo.directory;
}
if (pw_uid == 0 && !dsp->u.local.is_mbox) {
(void)snprintf(ebuf, sizeof ebuf, "not allowed to deliver to: %s",
deliver->userinfo.username);
if (pw_uid == 0 && (!dsp->u.local.is_mbox || deliver->mda_exec[0])) {
(void)snprintf(ebuf, sizeof ebuf, "MDA not allowed to deliver to: %s",
deliver->userinfo.username);
m_create(p_dispatcher, IMSG_MDA_DONE, 0, 0, -1);
m_add_id(p_dispatcher, id);
m_add_int(p_dispatcher, MDA_PERMFAIL);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: smtpd.h,v 1.680 2024/01/03 08:11:15 op Exp $ */
/* $OpenBSD: smtpd.h,v 1.681 2024/02/02 22:02:12 gilles Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@ -428,6 +428,7 @@ struct expandnode {
enum expand_type type;
int sameuser;
int realuser;
uid_t realuser_uid;
int forwarded;
struct rule *rule;
struct expandnode *parent;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: print-snmp.c,v 1.28 2021/10/23 10:47:50 martijn Exp $ */
/* $OpenBSD: print-snmp.c,v 1.29 2024/02/03 00:20:21 jsg Exp $ */
/*
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
@ -746,7 +746,7 @@ asn1_print(struct be *elem)
Class[CONTEXT].Id[elem->id], elem->asnlen);
break;
case BE_VB:
if (elem->id > sizeof(ContextVarbind)/sizeof(ContextVarbind[0]))
if (elem->id >= sizeof(ContextVarbind)/sizeof(ContextVarbind[0]))
break;
printf("%s", ContextVarbind[elem->id]);
break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vioblk.c,v 1.9 2023/09/26 01:53:54 dv Exp $ */
/* $OpenBSD: vioblk.c,v 1.10 2024/02/03 00:28:07 jsg Exp $ */
/*
* Copyright (c) 2023 Dave Voutila <dv@openbsd.org>
@ -67,7 +67,7 @@ __dead void
vioblk_main(int fd, int fd_vmm)
{
struct virtio_dev dev;
struct vioblk_dev *vioblk;
struct vioblk_dev *vioblk = NULL;
struct viodev_msg msg;
struct vmd_vm vm;
struct vm_create_params *vcp;
@ -210,7 +210,7 @@ vioblk_main(int fd, int fd_vmm)
/* Clean shutdown. */
close_fd(dev.sync_fd);
close_fd(dev.async_fd);
for (i = 0; i < (int)sizeof(vioblk->disk_fd); i++)
for (i = 0; i < vioblk->ndisk_fd; i++)
close_fd(vioblk->disk_fd[i]);
_exit(0);
/* NOTREACHED */
@ -227,8 +227,10 @@ fail:
close_fd(dev.sync_fd);
close_fd(dev.async_fd);
for (i = 0; i < (int)sizeof(vioblk->disk_fd); i++)
close_fd(vioblk->disk_fd[i]);
if (vioblk != NULL) {
for (i = 0; i < vioblk->ndisk_fd; i++)
close_fd(vioblk->disk_fd[i]);
}
_exit(ret);
/* NOTREACHED */
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vm_agentx.c,v 1.1 2022/09/13 10:28:19 martijn Exp $ */
/* $OpenBSD: vm_agentx.c,v 1.2 2024/02/02 14:58:02 dv Exp $ */
/*
* Copyright (c) 2022 Martijn van Duren <martijn@openbsd.org>
@ -106,7 +106,7 @@ vm_agentx(struct privsep *ps, struct privsep_proc *p)
* group permissions.
*/
if ((grp = getgrnam(AGENTX_GROUP)) == NULL)
fatal("getgrnam");
fatal("failed to get group: %s", AGENTX_GROUP);
ps->ps_pw->pw_gid = grp->gr_gid;
proc_run(ps, p, procs, nitems(procs), vm_agentx_run, NULL);