From 9d8ac7f158cc93fecbe68fd7ffee4c9fe33a9095 Mon Sep 17 00:00:00 2001 From: purplerain Date: Mon, 15 Apr 2024 03:08:26 +0000 Subject: [PATCH] sync with OpenBSD -current --- lib/libc/gen/scandir.c | 2 +- lib/libcrypto/ec/ec_ameth.c | 6 +- lib/libcrypto/evp/evp.h | 22 +- lib/libcrypto/man/X509_LOOKUP_new.3 | 89 +------- .../lib/libc/malloc/malloc_errs/malloc_errs.c | 14 +- share/man/man1/update-plist.1 | 8 +- share/man/man5/python-module.5 | 6 +- sys/arch/amd64/amd64/cpu.c | 14 +- sys/arch/amd64/amd64/mds.S | 9 +- sys/arch/amd64/include/cpu.h | 4 +- sys/arch/amd64/include/fpu.h | 4 +- sys/arch/amd64/stand/libsa/biosdev.c | 5 +- sys/arch/i386/stand/libsa/biosdev.c | 5 +- sys/dev/ic/ciss.c | 5 +- sys/dev/ic/imxiic.c | 5 +- sys/dev/ic/rt2661.c | 5 +- sys/dev/ic/rt2860.c | 17 +- sys/dev/pci/auglx.c | 8 +- sys/dev/pci/drm/amd/amdkfd/kfd_chardev.c | 4 +- .../drm/amd/display/modules/inc/mod_stats.h | 4 +- sys/dev/pci/drm/drm_modeset_helper.c | 19 +- sys/dev/pci/drm/drm_probe_helper.c | 21 +- sys/dev/pci/drm/ttm/ttm_bo.c | 7 +- sys/dev/pci/if_bge.c | 5 +- sys/dev/pci/if_ipw.c | 5 +- sys/dev/sbus/bpp.c | 5 +- sys/dev/usb/if_mtw.c | 5 +- sys/dev/usb/if_rum.c | 5 +- sys/dev/usb/if_run.c | 20 +- sys/msdosfs/msdosfs_conv.c | 14 +- sys/net/if_bridge.c | 4 +- sys/net80211/ieee80211_crypto.c | 5 +- sys/net80211/ieee80211_output.c | 8 +- sys/netinet/in_proto.c | 6 +- sys/netinet/ip_input.c | 102 ++++++--- sys/netinet/ip_var.h | 9 +- sys/netinet6/ip6_input.c | 21 +- sys/sys/mbuf.h | 5 +- sys/sys/protosw.h | 3 +- usr.bin/less/ch.c | 7 +- usr.bin/less/command.c | 5 - usr.bin/less/edit.c | 55 +---- usr.bin/less/filename.c | 204 ++---------------- usr.bin/less/funcs.h | 2 - usr.bin/less/less.1 | 172 +-------------- usr.bin/less/less.h | 1 - usr.bin/less/less.hlp | 2 - usr.bin/less/main.c | 4 - usr.bin/less/opttbl.c | 4 +- 49 files changed, 304 insertions(+), 657 deletions(-) diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 9782a3d91..f767ca503 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scandir.c,v 1.21 2019/06/28 13:32:41 deraadt Exp $ */ +/* $OpenBSD: scandir.c,v 1.22 2024/04/14 11:21:08 florian Exp $ */ /* * Copyright (c) 1983, 1993 * The Regents of the University of California. All rights reserved. diff --git a/lib/libcrypto/ec/ec_ameth.c b/lib/libcrypto/ec/ec_ameth.c index ebedab332..a73add0c2 100644 --- a/lib/libcrypto/ec/ec_ameth.c +++ b/lib/libcrypto/ec/ec_ameth.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_ameth.c,v 1.52 2024/04/13 14:02:51 tb Exp $ */ +/* $OpenBSD: ec_ameth.c,v 1.53 2024/04/14 15:41:09 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -640,7 +640,7 @@ ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) return -1; if (!X509_ALGOR_set0_by_nid(alg2, snid, V_ASN1_UNDEF, NULL)) - return -1; + return -1; } return 1; @@ -660,7 +660,7 @@ ec_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) return -1; if (!X509_ALGOR_set0_by_nid(alg2, snid, V_ASN1_UNDEF, NULL)) - return -1; + return -1; } return 1; diff --git a/lib/libcrypto/evp/evp.h b/lib/libcrypto/evp/evp.h index 26695dc3d..5059c0aff 100644 --- a/lib/libcrypto/evp/evp.h +++ b/lib/libcrypto/evp/evp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: evp.h,v 1.133 2024/04/10 15:00:38 beck Exp $ */ +/* $OpenBSD: evp.h,v 1.134 2024/04/14 14:14:14 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -330,11 +330,6 @@ typedef int EVP_PBE_KEYGEN(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, (char *)(eckey)) #endif -#ifndef OPENSSL_NO_GOST -#define EVP_PKEY_assign_GOST(pkey,gostkey) EVP_PKEY_assign((pkey),EVP_PKEY_GOSTR01,\ - (char *)(gostkey)) -#endif - /* Add some extra combinations */ #define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) #define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) @@ -602,12 +597,6 @@ const EVP_MD *EVP_ripemd160(void); #ifndef OPENSSL_NO_WHIRLPOOL const EVP_MD *EVP_whirlpool(void); #endif -#ifndef OPENSSL_NO_GOST -const EVP_MD *EVP_gostr341194(void); -const EVP_MD *EVP_gost2814789imit(void); -const EVP_MD *EVP_streebog256(void); -const EVP_MD *EVP_streebog512(void); -#endif const EVP_CIPHER *EVP_enc_null(void); /* does nothing :-) */ #ifndef OPENSSL_NO_DES const EVP_CIPHER *EVP_des_ecb(void); @@ -735,12 +724,6 @@ const EVP_CIPHER *EVP_camellia_256_ofb(void); const EVP_CIPHER *EVP_chacha20(void); #endif -#ifndef OPENSSL_NO_GOST -const EVP_CIPHER *EVP_gost2814789_ecb(void); -const EVP_CIPHER *EVP_gost2814789_cfb64(void); -const EVP_CIPHER *EVP_gost2814789_cnt(void); -#endif - #ifndef OPENSSL_NO_SM4 const EVP_CIPHER *EVP_sm4_ecb(void); const EVP_CIPHER *EVP_sm4_cbc(void); @@ -820,9 +803,6 @@ struct ec_key_st *EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey); struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, struct ec_key_st *key); #endif -#ifndef OPENSSL_NO_GOST -struct gost_key_st; -#endif EVP_PKEY *EVP_PKEY_new(void); void EVP_PKEY_free(EVP_PKEY *pkey); diff --git a/lib/libcrypto/man/X509_LOOKUP_new.3 b/lib/libcrypto/man/X509_LOOKUP_new.3 index f368cbb60..964594cde 100644 --- a/lib/libcrypto/man/X509_LOOKUP_new.3 +++ b/lib/libcrypto/man/X509_LOOKUP_new.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: X509_LOOKUP_new.3,v 1.9 2021/11/12 14:05:28 schwarze Exp $ +.\" $OpenBSD: X509_LOOKUP_new.3,v 1.10 2024/04/14 10:56:18 tb Exp $ .\" .\" Copyright (c) 2021 Ingo Schwarze .\" @@ -14,22 +14,15 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 12 2021 $ +.Dd $Mdocdate: April 14 2024 $ .Dt X509_LOOKUP_NEW 3 .Os .Sh NAME -.Nm X509_LOOKUP_new , .Nm X509_LOOKUP_free , .Nm X509_LOOKUP_ctrl , .Nm X509_LOOKUP_add_dir , .Nm X509_LOOKUP_load_file , .Nm X509_LOOKUP_add_mem , -.Nm X509_LOOKUP_by_subject , -.Nm X509_LOOKUP_init , -.Nm X509_LOOKUP_shutdown , -.Nm X509_LOOKUP_by_issuer_serial , -.Nm X509_LOOKUP_by_fingerprint , -.Nm X509_LOOKUP_by_alias , .Nm X509_get_default_cert_dir , .Nm X509_get_default_cert_file , .Nm X509_get_default_cert_dir_env , @@ -40,8 +33,6 @@ .Nd certificate lookup object .Sh SYNOPSIS .In openssl/x509_vfy.h -.Ft X509_LOOKUP * -.Fn X509_LOOKUP_new "X509_LOOKUP_METHOD *method" .Ft void .Fn X509_LOOKUP_free "X509_LOOKUP *lookup" .Ft int @@ -70,41 +61,6 @@ .Fa "const struct iovec *source" .Fa "long type" .Fc -.Ft int -.Fo X509_LOOKUP_by_subject -.Fa "X509_LOOKUP *lookup" -.Fa "X509_LOOKUP_TYPE type" -.Fa "X509_NAME *name" -.Fa "X509_OBJECT *object" -.Fc -.Ft int -.Fn X509_LOOKUP_init "X509_LOOKUP *lookup" -.Ft int -.Fn X509_LOOKUP_shutdown "X509_LOOKUP *lookup" -.Ft int -.Fo X509_LOOKUP_by_issuer_serial -.Fa "X509_LOOKUP *lookup" -.Fa "X509_LOOKUP_TYPE type" -.Fa "X509_NAME *name" -.Fa "ASN1_INTEGER *serial" -.Fa "X509_OBJECT *object" -.Fc -.Ft int -.Fo X509_LOOKUP_by_fingerprint -.Fa "X509_LOOKUP *lookup" -.Fa "X509_LOOKUP_TYPE type" -.Fa "const unsigned char *bytes" -.Fa "int length" -.Fa "X509_OBJECT *object" -.Fc -.Ft int -.Fo X509_LOOKUP_by_alias -.Fa "X509_LOOKUP *lookup" -.Fa "X509_LOOKUP_TYPE type" -.Fa "const char *string" -.Fa "int length" -.Fa "X509_OBJECT *object" -.Fc .In openssl/x509.h .Ft const char * .Fn X509_get_default_cert_dir void @@ -115,21 +71,11 @@ .Ft const char * .Fn X509_get_default_cert_file_env void .Sh DESCRIPTION -.Fn X509_LOOKUP_new -allocates a new, empty -.Vt X509_LOOKUP -object and associates it with the -.Fa method -which is a static object returned from either -.Xr X509_LOOKUP_hash_dir 3 -or -.Xr X509_LOOKUP_file 3 -or -.Xr X509_LOOKUP_mem 3 . -.Pp .Fn X509_LOOKUP_free +is a deprecated function that releases the memory used by .Fa lookup . +It is provided for compatibility only. If .Fa lookup is a @@ -332,21 +278,7 @@ and the files are read with In case of success, the first match is returned in the .Pf * Fa object provided by the caller, overwriting any previous content. -.Pp -With LibreSSL, -.Fn X509_LOOKUP_init , -.Fn X509_LOOKUP_shutdown , -.Fn X509_LOOKUP_by_issuer_serial , -.Fn X509_LOOKUP_by_fingerprint , -and -.Fn X509_LOOKUP_by_alias -have no effect. .Sh RETURN VALUES -.Fn X509_LOOKUP_new -returns the new object or -.Dv NULL -if memory allocation fails. -.Pp .Fn X509_LOOKUP_ctrl returns 1 for success or 0 for failure. With library implementations other than LibreSSL, @@ -374,19 +306,6 @@ if no match is found, or if memory allocation fails. With library implementations other than LibreSSL, it might also return negative values for internal errors. .Pp -.Fn X509_LOOKUP_init -and -.Fn X509_LOOKUP_shutdown -are supposed to return 1 for success and 0 for failure. -With LibreSSL, they always return 1. -.Pp -With LibreSSL, -.Fn X509_LOOKUP_by_issuer_serial , -.Fn X509_LOOKUP_by_fingerprint , -and -.Fn X509_LOOKUP_by_alias -always return 0. -.Pp .Fn X509_get_default_cert_dir returns a pointer to the constant string .Qq /etc/ssl/certs , diff --git a/regress/lib/libc/malloc/malloc_errs/malloc_errs.c b/regress/lib/libc/malloc/malloc_errs/malloc_errs.c index c71198086..486c247f0 100644 --- a/regress/lib/libc/malloc/malloc_errs/malloc_errs.c +++ b/regress/lib/libc/malloc/malloc_errs/malloc_errs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc_errs.c,v 1.4 2023/10/22 12:20:07 otto Exp $ */ +/* $OpenBSD: malloc_errs.c,v 1.5 2024/04/14 17:47:41 otto Exp $ */ /* * Copyright (c) 2023 Otto Moerbeek * @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -231,7 +232,16 @@ void t22(void) { int i, j; - unsigned char *p = malloc(32); + unsigned char *p; + while (1) { + uintptr_t address; + p = malloc(32); + address = (uintptr_t)(void *)p; + /* we don't want to have a chunk on the last slot of a page */ + if (address / getpagesize() == (address + 32) / getpagesize()) + break; + free(p); + } p[32] = 0; for (i = 0; i < 10000; i++) p = malloc(32); diff --git a/share/man/man1/update-plist.1 b/share/man/man1/update-plist.1 index 40e91efca..21d8f9a76 100644 --- a/share/man/man1/update-plist.1 +++ b/share/man/man1/update-plist.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: update-plist.1,v 1.9 2021/05/28 18:45:09 tb Exp $ +.\" $OpenBSD: update-plist.1,v 1.10 2024/04/14 17:24:15 phessler Exp $ .\" .\" Copyright (c) 2018 Marc Espie .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 28 2021 $ +.Dd $Mdocdate: April 14 2024 $ .Dt UPDATE-PLIST 1 .Os .Sh NAME @@ -304,8 +304,8 @@ will first write files as .Pa .new , then it will display which files are new and which files have changed. If old packing-lists already exist, it will move old packing lists into -.Pa .orig -unless these already exist, then move the new files into position. +.Pa .orig , +then move the new files into position. .Sh SEE ALSO .Xr pkg_add 1 , .Xr pkg_create 1 , diff --git a/share/man/man5/python-module.5 b/share/man/man5/python-module.5 index 67d8435b5..39546b30e 100644 --- a/share/man/man5/python-module.5 +++ b/share/man/man5/python-module.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: python-module.5,v 1.9 2023/12/22 12:51:53 sthen Exp $ +.\" $OpenBSD: python-module.5,v 1.10 2024/04/14 12:09:28 sthen Exp $ .\" .\" Copyright (c) 2008 Marc Espie .\" @@ -24,7 +24,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: December 22 2023 $ +.Dd $Mdocdate: April 14 2024 $ .Dt PYTHON-MODULE 5 .Os .Sh NAME @@ -114,7 +114,7 @@ If the port provides a file, check the "build-backend" line in the [build-system] section. .Nm currently supports flit_core, hatchling, hatch-vcs, jupyter_packaging, -poetry-core, setuptools and setuptools_scm. +maturin, poetry-core, setuptools and setuptools_scm. If no .Pa pyproject.toml is provided then it probably uses setuptools. diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index 45ccefd49..1cff7a51d 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.185 2024/04/03 02:01:21 guenther Exp $ */ +/* $OpenBSD: cpu.c,v 1.186 2024/04/14 09:59:04 kettenis Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -294,6 +294,7 @@ replacemds(void) static int replacedone = 0; extern long mds_handler_bdw, mds_handler_ivb, mds_handler_skl; extern long mds_handler_skl_sse, mds_handler_skl_avx; + extern long mds_handler_skl_avx512; extern long mds_handler_silvermont, mds_handler_knights; struct cpu_info *ci = &cpu_info_primary; CPU_INFO_ITERATOR cii; @@ -302,9 +303,9 @@ replacemds(void) int use_verw = 0, s; uint32_t cap = 0; - /* ci_mds_tmp must be 32byte aligned for AVX instructions */ + /* ci_mds_tmp must be 64-byte aligned for AVX-512 instructions */ CTASSERT((offsetof(struct cpu_info, ci_mds_tmp) - - offsetof(struct cpu_info, ci_PAGEALIGN)) % 32 == 0); + offsetof(struct cpu_info, ci_PAGEALIGN)) % 64 == 0); if (replacedone) return; @@ -358,8 +359,10 @@ replacemds(void) * Skylake, KabyLake, CoffeeLake, WhiskeyLake, * CascadeLake */ - /* XXX mds_handler_skl_avx512 */ - if (xgetbv(0) & XFEATURE_AVX) { + if (xgetbv(0) & XFEATURE_AVX512) { + handler = &mds_handler_skl_avx512; + type = "Skylake AVX-512"; + } else if (xgetbv(0) & XFEATURE_AVX) { handler = &mds_handler_skl_avx; type = "Skylake AVX"; } else { @@ -803,6 +806,7 @@ cpu_init(struct cpu_info *ci) xsave_mask = XFEATURE_X87 | XFEATURE_SSE; CPUID_LEAF(0xd, 0, eax, ebx, ecx, edx); xsave_mask |= eax & XFEATURE_AVX; + xsave_mask |= eax & XFEATURE_AVX512; xsetbv(0, xsave_mask); CPUID_LEAF(0xd, 0, eax, ebx, ecx, edx); if (CPU_IS_PRIMARY(ci)) { diff --git a/sys/arch/amd64/amd64/mds.S b/sys/arch/amd64/amd64/mds.S index e4967fbff..630b7c170 100644 --- a/sys/arch/amd64/amd64/mds.S +++ b/sys/arch/amd64/amd64/mds.S @@ -1,4 +1,4 @@ -/* $OpenBSD: mds.S,v 1.4 2023/04/22 18:27:28 guenther Exp $ */ +/* $OpenBSD: mds.S,v 1.5 2024/04/14 09:59:04 kettenis Exp $ */ /* * Copyright (c) 2019 Philip Guenther * @@ -77,6 +77,8 @@ END(mds_handler_bdw) ENTRY(mds_handler_skl) xorl %ecx,%ecx xgetbv + testb $XFEATURE_AVX512,%al + jne mds_handler_skl_avx512 testb $XFEATURE_AVX,%al jne mds_handler_skl_avx jmp mds_handler_skl_sse @@ -136,14 +138,12 @@ ENTRY(mds_handler_skl_avx) lfence END(mds_handler_skl_avx) -/* we don't support AVX512 yet */ -#if 0 ENTRY(mds_handler_skl_avx512) RETGUARD_SETUP(mds_handler_skl_avx512, r11) movq CPUVAR(MDS_BUF),%rax leaq 64(%rax),%rdi vmovdqa64 %zmm0,CPUVAR(MDS_TMP) - vpxor %zmm0,%zmm0,%zmm0 + vpxorq %zmm0,%zmm0,%zmm0 lfence vorpd (%rax),%zmm0,%zmm0 @@ -164,7 +164,6 @@ ENTRY(mds_handler_skl_avx512) retq lfence END(mds_handler_skl_avx512) -#endif ENTRY(mds_handler_silvermont) RETGUARD_SETUP(mds_handler_silvermont, r11) diff --git a/sys/arch/amd64/include/cpu.h b/sys/arch/amd64/include/cpu.h index 84a86b229..7bd9a54fa 100644 --- a/sys/arch/amd64/include/cpu.h +++ b/sys/arch/amd64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.164 2024/04/03 02:01:21 guenther Exp $ */ +/* $OpenBSD: cpu.h,v 1.165 2024/04/14 09:59:04 kettenis Exp $ */ /* $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $ */ /*- @@ -132,7 +132,7 @@ struct cpu_info { u_int64_t ci_user_cr3; /* [o] U-K page table */ /* bits for mitigating Micro-architectural Data Sampling */ - char ci_mds_tmp[32]; /* [o] 32byte aligned */ + char ci_mds_tmp[64]; /* [o] 64-byte aligned */ void *ci_mds_buf; /* [I] */ struct proc *ci_curproc; /* [o] */ diff --git a/sys/arch/amd64/include/fpu.h b/sys/arch/amd64/include/fpu.h index 2a024f2dc..f468815ff 100644 --- a/sys/arch/amd64/include/fpu.h +++ b/sys/arch/amd64/include/fpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fpu.h,v 1.19 2023/07/10 03:32:10 guenther Exp $ */ +/* $OpenBSD: fpu.h,v 1.20 2024/04/14 09:59:04 kettenis Exp $ */ /* $NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $ */ #ifndef _MACHINE_FPU_H_ @@ -40,7 +40,7 @@ struct savefpu { struct fxsave64 fp_fxsave; /* see above */ struct xstate_hdr fp_xstate; u_int64_t fp_ymm[16][2]; - u_int64_t fp_cet_u[2]; + u_int8_t fp_components[1856]; /* enough for AVX-512 */ }; /* diff --git a/sys/arch/amd64/stand/libsa/biosdev.c b/sys/arch/amd64/stand/libsa/biosdev.c index 98a67db68..a0557f3bd 100644 --- a/sys/arch/amd64/stand/libsa/biosdev.c +++ b/sys/arch/amd64/stand/libsa/biosdev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: biosdev.c,v 1.36 2023/04/25 10:06:12 kn Exp $ */ +/* $OpenBSD: biosdev.c,v 1.37 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -724,7 +724,8 @@ biosdisk_errno(u_int error) if (error == 0) return 0; - for (p = tab; p->error && p->error != error; p++); + for (p = tab; p->error && p->error != error; p++) + ; return p->errno; } diff --git a/sys/arch/i386/stand/libsa/biosdev.c b/sys/arch/i386/stand/libsa/biosdev.c index 752987800..587624562 100644 --- a/sys/arch/i386/stand/libsa/biosdev.c +++ b/sys/arch/i386/stand/libsa/biosdev.c @@ -1,4 +1,4 @@ -/* $OpenBSD: biosdev.c,v 1.101 2023/04/25 14:48:17 kn Exp $ */ +/* $OpenBSD: biosdev.c,v 1.102 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -723,7 +723,8 @@ biosdisk_errno(u_int error) if (error == 0) return 0; - for (p = tab; p->error && p->error != error; p++); + for (p = tab; p->error && p->error != error; p++) + ; return p->errno; } diff --git a/sys/dev/ic/ciss.c b/sys/dev/ic/ciss.c index 092d403b7..706872604 100644 --- a/sys/dev/ic/ciss.c +++ b/sys/dev/ic/ciss.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ciss.c,v 1.91 2022/04/16 19:19:59 naddy Exp $ */ +/* $OpenBSD: ciss.c,v 1.92 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 2005,2006 Michael Shalayeff @@ -217,7 +217,8 @@ ciss_attach(struct ciss_softc *sc) sc->maxsg = MAXPHYS / PAGE_SIZE; i = sizeof(struct ciss_ccb) + sizeof(ccb->ccb_cmd.sgl[0]) * (sc->maxsg - 1); - for (sc->ccblen = 0x10; sc->ccblen < i; sc->ccblen <<= 1); + for (sc->ccblen = 0x10; sc->ccblen < i; sc->ccblen <<= 1) + ; total = sc->ccblen * sc->maxcmd; if ((error = bus_dmamem_alloc(sc->dmat, total, PAGE_SIZE, 0, diff --git a/sys/dev/ic/imxiic.c b/sys/dev/ic/imxiic.c index 3957c2544..0ba646cea 100644 --- a/sys/dev/ic/imxiic.c +++ b/sys/dev/ic/imxiic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imxiic.c,v 1.1 2020/11/17 14:30:13 patrick Exp $ */ +/* $OpenBSD: imxiic.c,v 1.2 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 2013 Patrick Wildt * @@ -119,7 +119,8 @@ imxiic_setspeed(struct imxiic_softc *sc, u_int speed) else if (div > sc->sc_clk_div[sc->sc_clk_ndiv - 1].div) i = sc->sc_clk_ndiv - 1; else - for (i = 0; sc->sc_clk_div[i].div < div; i++); + for (i = 0; sc->sc_clk_div[i].div < div; i++) + ; sc->frequency = sc->sc_clk_div[i].val; } diff --git a/sys/dev/ic/rt2661.c b/sys/dev/ic/rt2661.c index aabaa8952..2bb6a2d99 100644 --- a/sys/dev/ic/rt2661.c +++ b/sys/dev/ic/rt2661.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rt2661.c,v 1.99 2022/04/21 21:03:02 stsp Exp $ */ +/* $OpenBSD: rt2661.c,v 1.100 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2006 @@ -2274,7 +2274,8 @@ rt2661_set_chan(struct rt2661_softc *sc, struct ieee80211_channel *c) rfprog = (sc->rfprog == 0) ? rt2661_rf5225_1 : rt2661_rf5225_2; /* find the settings for this channel (we know it exists) */ - for (i = 0; rfprog[i].chan != chan; i++); + for (i = 0; rfprog[i].chan != chan; i++) + ; power = sc->txpow[i]; if (power < 0) { diff --git a/sys/dev/ic/rt2860.c b/sys/dev/ic/rt2860.c index f4d1cfa14..853e0492a 100644 --- a/sys/dev/ic/rt2860.c +++ b/sys/dev/ic/rt2860.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rt2860.c,v 1.102 2022/04/21 21:03:02 stsp Exp $ */ +/* $OpenBSD: rt2860.c,v 1.103 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2007-2010 Damien Bergamini @@ -2225,7 +2225,8 @@ rt2860_set_chan(struct rt2860_softc *sc, u_int chan) u_int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rfprog[i].chan != chan; i++); + for (i = 0; rfprog[i].chan != chan; i++) + ; r2 = rfprog[i].r2; if (sc->ntxchains == 1) @@ -2281,7 +2282,8 @@ rt3090_set_chan(struct rt2860_softc *sc, u_int chan) KASSERT(chan >= 1 && chan <= 14); /* RT3090 is 2GHz only */ /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -2346,7 +2348,8 @@ rt5390_set_chan(struct rt2860_softc *sc, u_int chan) KASSERT(chan >= 1 && chan <= 14); /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -4054,10 +4057,12 @@ rt2860_calib(struct rt2860_softc *sc) if (bbp49 < tssi[0]) { /* lower than reference */ /* use higher Tx power than default */ - for (d = 0; d > -4 && bbp49 <= tssi[d - 1]; d--); + for (d = 0; d > -4 && bbp49 <= tssi[d - 1]; d--) + ; } else if (bbp49 > tssi[0]) { /* greater than reference */ /* use lower Tx power than default */ - for (d = 0; d < +4 && bbp49 >= tssi[d + 1]; d++); + for (d = 0; d < +4 && bbp49 >= tssi[d + 1]; d++) + ; } else { /* use default Tx power */ d = 0; diff --git a/sys/dev/pci/auglx.c b/sys/dev/pci/auglx.c index 3d35b9526..41d26779a 100644 --- a/sys/dev/pci/auglx.c +++ b/sys/dev/pci/auglx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: auglx.c,v 1.23 2022/10/26 20:19:08 kn Exp $ */ +/* $OpenBSD: auglx.c,v 1.24 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 2008 Marc Balmer @@ -669,7 +669,8 @@ auglx_trigger_output(void *v, void *start, void *end, int blksize, DPRINTF(AUGLX_DBG_DMA, ("%s: trigger_output, %p 0x%08x bytes, " "blksize 0x%04x\n", sc->sc_dev.dv_xname, start, size, blksize)); - for (p = sc->sc_dmas; p && p->addr != start; p = p->next); + for (p = sc->sc_dmas; p && p->addr != start; p = p->next) + ; if (!p) { DPRINTF(AUGLX_DBG_DMA, ("%s dma reg not found\n", sc->sc_dev.dv_xname)); @@ -730,7 +731,8 @@ auglx_trigger_input(void *v, void *start, void *end, int blksize, DPRINTF(AUGLX_DBG_DMA, ("%s: trigger_input, %p 0x%08x bytes, " "blksize 0x%04x\n", sc->sc_dev.dv_xname, start, size, blksize)); - for (p = sc->sc_dmas; p && p->addr != start; p = p->next); + for (p = sc->sc_dmas; p && p->addr != start; p = p->next) + ; if (!p) { DPRINTF(AUGLX_DBG_DMA, ("%s dma reg not found\n", sc->sc_dev.dv_xname)); diff --git a/sys/dev/pci/drm/amd/amdkfd/kfd_chardev.c b/sys/dev/pci/drm/amd/amdkfd/kfd_chardev.c index 29594b064..4fbdc942c 100644 --- a/sys/dev/pci/drm/amd/amdkfd/kfd_chardev.c +++ b/sys/dev/pci/drm/amd/amdkfd/kfd_chardev.c @@ -778,8 +778,8 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp, * nodes, but not more than args->num_of_nodes as that is * the amount of memory allocated by user */ - pa = kzalloc((sizeof(struct kfd_process_device_apertures) * - args->num_of_nodes), GFP_KERNEL); + pa = kcalloc(args->num_of_nodes, sizeof(struct kfd_process_device_apertures), + GFP_KERNEL); if (!pa) return -ENOMEM; diff --git a/sys/dev/pci/drm/amd/display/modules/inc/mod_stats.h b/sys/dev/pci/drm/amd/display/modules/inc/mod_stats.h index 4220fd8fd..54cd86060 100644 --- a/sys/dev/pci/drm/amd/display/modules/inc/mod_stats.h +++ b/sys/dev/pci/drm/amd/display/modules/inc/mod_stats.h @@ -57,10 +57,10 @@ void mod_stats_update_event(struct mod_stats *mod_stats, unsigned int length); void mod_stats_update_flip(struct mod_stats *mod_stats, - unsigned long timestamp_in_ns); + unsigned long long timestamp_in_ns); void mod_stats_update_vupdate(struct mod_stats *mod_stats, - unsigned long timestamp_in_ns); + unsigned long long timestamp_in_ns); void mod_stats_update_freesync(struct mod_stats *mod_stats, unsigned int v_total_min, diff --git a/sys/dev/pci/drm/drm_modeset_helper.c b/sys/dev/pci/drm/drm_modeset_helper.c index f858dfedf..2c582020c 100644 --- a/sys/dev/pci/drm/drm_modeset_helper.c +++ b/sys/dev/pci/drm/drm_modeset_helper.c @@ -193,13 +193,22 @@ int drm_mode_config_helper_suspend(struct drm_device *dev) if (!dev) return 0; + /* + * Don't disable polling if it was never initialized + */ + if (dev->mode_config.poll_enabled) + drm_kms_helper_poll_disable(dev); - drm_kms_helper_poll_disable(dev); drm_fb_helper_set_suspend_unlocked(dev->fb_helper, 1); state = drm_atomic_helper_suspend(dev); if (IS_ERR(state)) { drm_fb_helper_set_suspend_unlocked(dev->fb_helper, 0); - drm_kms_helper_poll_enable(dev); + /* + * Don't enable polling if it was never initialized + */ + if (dev->mode_config.poll_enabled) + drm_kms_helper_poll_enable(dev); + return PTR_ERR(state); } @@ -239,7 +248,11 @@ int drm_mode_config_helper_resume(struct drm_device *dev) dev->mode_config.suspend_state = NULL; drm_fb_helper_set_suspend_unlocked(dev->fb_helper, 0); - drm_kms_helper_poll_enable(dev); + /* + * Don't enable polling if it is not initialized + */ + if (dev->mode_config.poll_enabled) + drm_kms_helper_poll_enable(dev); return ret; } diff --git a/sys/dev/pci/drm/drm_probe_helper.c b/sys/dev/pci/drm/drm_probe_helper.c index 169df0488..da3d8e3ee 100644 --- a/sys/dev/pci/drm/drm_probe_helper.c +++ b/sys/dev/pci/drm/drm_probe_helper.c @@ -293,14 +293,17 @@ static void reschedule_output_poll_work(struct drm_device *dev) * Drivers can call this helper from their device resume implementation. It is * not an error to call this even when output polling isn't enabled. * + * If device polling was never initialized before, this call will trigger a + * warning and return. + * * Note that calls to enable and disable polling must be strictly ordered, which * is automatically the case when they're only call from suspend/resume * callbacks. */ void drm_kms_helper_poll_enable(struct drm_device *dev) { - if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll || - dev->mode_config.poll_running) + if (drm_WARN_ON_ONCE(dev, !dev->mode_config.poll_enabled) || + !drm_kms_helper_poll || dev->mode_config.poll_running) return; if (drm_kms_helper_enable_hpd(dev) || @@ -626,8 +629,12 @@ retry: 0); } - /* Re-enable polling in case the global poll config changed. */ - drm_kms_helper_poll_enable(dev); + /* + * Re-enable polling in case the global poll config changed but polling + * is still initialized. + */ + if (dev->mode_config.poll_enabled) + drm_kms_helper_poll_enable(dev); if (connector->status == connector_status_disconnected) { DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n", @@ -881,12 +888,18 @@ EXPORT_SYMBOL(drm_kms_helper_is_poll_worker); * not an error to call this even when output polling isn't enabled or already * disabled. Polling is re-enabled by calling drm_kms_helper_poll_enable(). * + * If however, the polling was never initialized, this call will trigger a + * warning and return + * * Note that calls to enable and disable polling must be strictly ordered, which * is automatically the case when they're only call from suspend/resume * callbacks. */ void drm_kms_helper_poll_disable(struct drm_device *dev) { + if (drm_WARN_ON(dev, !dev->mode_config.poll_enabled)) + return; + if (dev->mode_config.poll_running) drm_kms_helper_disable_hpd(dev); diff --git a/sys/dev/pci/drm/ttm/ttm_bo.c b/sys/dev/pci/drm/ttm/ttm_bo.c index ad9b8cf8f..16f91c29d 100644 --- a/sys/dev/pci/drm/ttm/ttm_bo.c +++ b/sys/dev/pci/drm/ttm/ttm_bo.c @@ -764,7 +764,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo, * This function may sleep while waiting for space to become available. * Returns: * -EBUSY: No space available (only if no_wait == 1). - * -ENOMEM: Could not allocate memory for the buffer object, either due to + * -ENOSPC: Could not allocate space for the buffer object, either due to * fragmentation or concurrent allocators. * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. */ @@ -824,7 +824,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo, goto error; } - ret = -ENOMEM; + ret = -ENOSPC; if (!type_found) { pr_err(TTM_PFX "No compatible memory type found\n"); ret = -EINVAL; @@ -910,6 +910,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo, return -EINVAL; ret = ttm_bo_move_buffer(bo, placement, ctx); + /* For backward compatibility with userspace */ + if (ret == -ENOSPC) + return -ENOMEM; if (ret) return ret; diff --git a/sys/dev/pci/if_bge.c b/sys/dev/pci/if_bge.c index 2707da19a..877e5c9b6 100644 --- a/sys/dev/pci/if_bge.c +++ b/sys/dev/pci/if_bge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bge.c,v 1.403 2024/02/11 06:40:46 jmc Exp $ */ +/* $OpenBSD: if_bge.c,v 1.404 2024/04/14 03:26:25 jsg Exp $ */ /* * Copyright (c) 2001 Wind River Systems @@ -4079,7 +4079,8 @@ bge_cksum_pad(struct mbuf *m) * Walk packet chain to find last mbuf. We will either * pad there, or append a new mbuf and pad it. */ - for (last = m; last->m_next != NULL; last = last->m_next); + for (last = m; last->m_next != NULL; last = last->m_next) + ; if (m_trailingspace(last) < padlen) { /* Allocate new empty mbuf, pad it. Compact later. */ struct mbuf *n; diff --git a/sys/dev/pci/if_ipw.c b/sys/dev/pci/if_ipw.c index 9f40c08fb..7d44a58f8 100644 --- a/sys/dev/pci/if_ipw.c +++ b/sys/dev/pci/if_ipw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_ipw.c,v 1.133 2023/03/08 04:43:08 guenther Exp $ */ +/* $OpenBSD: if_ipw.c,v 1.134 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2004-2008 @@ -653,7 +653,8 @@ ipw_media_status(struct ifnet *ifp, struct ifmediareq *imr) val &= 0xf; /* convert rate to 802.11 rate */ - for (i = 0; i < nitems(rates) && rates[i].val != val; i++); + for (i = 0; i < nitems(rates) && rates[i].val != val; i++) + ; rate = (i < nitems(rates)) ? rates[i].rate : 0; imr->ifm_active |= IFM_IEEE80211_11B; diff --git a/sys/dev/sbus/bpp.c b/sys/dev/sbus/bpp.c index c2934b374..08d2b3d03 100644 --- a/sys/dev/sbus/bpp.c +++ b/sys/dev/sbus/bpp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpp.c,v 1.6 2019/12/31 10:05:33 mpi Exp $ */ +/* $OpenBSD: bpp.c,v 1.7 2024/04/14 03:23:13 jsg Exp $ */ /* $NetBSD: bpp.c,v 1.25 2005/12/11 12:23:44 christos Exp $ */ /*- @@ -318,7 +318,8 @@ bppwrite(dev_t dev, struct uio *uio, int flags) if (bppdebug) { size_t i; printf("bpp: writing %ld : ", len); - for (i=0; i * Copyright (c) 2013-2014 Kevin Lo @@ -2549,7 +2549,8 @@ mt7601_set_chan(struct mtw_softc *sc, u_int chan) int i; /* find the settings for this channel */ - for (i = 0; mt7601_rf_chan[i].chan != chan; i++); + for (i = 0; mt7601_rf_chan[i].chan != chan; i++) + ; mtw_rf_write(sc, 0, 17, mt7601_rf_chan[i].r17); mtw_rf_write(sc, 0, 18, mt7601_rf_chan[i].r18); diff --git a/sys/dev/usb/if_rum.c b/sys/dev/usb/if_rum.c index 9f8ce6a6c..fe08e053b 100644 --- a/sys/dev/usb/if_rum.c +++ b/sys/dev/usb/if_rum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_rum.c,v 1.127 2022/04/21 21:03:03 stsp Exp $ */ +/* $OpenBSD: if_rum.c,v 1.128 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2005-2007 Damien Bergamini @@ -1654,7 +1654,8 @@ rum_set_chan(struct rum_softc *sc, struct ieee80211_channel *c) sc->rf_rev == RT2573_RF_2527) ? rum_rf5225 : rum_rf5226; /* find the settings for this channel (we know it exists) */ - for (i = 0; rfprog[i].chan != chan; i++); + for (i = 0; rfprog[i].chan != chan; i++) + ; power = sc->txpow[i]; if (power < 0) { diff --git a/sys/dev/usb/if_run.c b/sys/dev/usb/if_run.c index bd113dc2c..88fc1db2c 100644 --- a/sys/dev/usb/if_run.c +++ b/sys/dev/usb/if_run.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_run.c,v 1.138 2023/03/08 04:43:08 guenther Exp $ */ +/* $OpenBSD: if_run.c,v 1.139 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2008-2010 Damien Bergamini @@ -2906,7 +2906,8 @@ run_rt2870_set_chan(struct run_softc *sc, u_int chan) int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rfprog[i].chan != chan; i++); + for (i = 0; rfprog[i].chan != chan; i++) + ; r2 = rfprog[i].r2; if (sc->ntxchains == 1) @@ -2960,7 +2961,8 @@ run_rt3070_set_chan(struct run_softc *sc, u_int chan) int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -3026,7 +3028,8 @@ run_rt3572_set_chan(struct run_softc *sc, u_int chan) int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -3175,7 +3178,8 @@ run_rt3593_set_chan(struct run_softc *sc, u_int chan) int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -3335,7 +3339,8 @@ run_rt5390_set_chan(struct run_softc *sc, u_int chan) int i; /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; @@ -3451,7 +3456,8 @@ run_rt5592_set_chan(struct run_softc *sc, u_int chan) rt5592_freqs_40mhz : rt5592_freqs_20mhz; /* find the settings for this channel (we know it exists) */ - for (i = 0; rt2860_rf2850[i].chan != chan; i++, freqs++); + for (i = 0; rt2860_rf2850[i].chan != chan; i++, freqs++) + ; /* use Tx power values from EEPROM */ txpow1 = sc->txpow1[i]; diff --git a/sys/msdosfs/msdosfs_conv.c b/sys/msdosfs/msdosfs_conv.c index 11f263ee3..3927cf026 100644 --- a/sys/msdosfs/msdosfs_conv.c +++ b/sys/msdosfs/msdosfs_conv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msdosfs_conv.c,v 1.20 2019/09/04 14:40:22 cheloha Exp $ */ +/* $OpenBSD: msdosfs_conv.c,v 1.21 2024/04/14 03:26:25 jsg Exp $ */ /* $NetBSD: msdosfs_conv.c,v 1.24 1997/10/17 11:23:54 ws Exp $ */ /*- @@ -491,7 +491,8 @@ unix2dosfn(u_char *un, u_char dn[11], int unlen, u_int gen) conv = 3; dp--; } else { - for (dp = cp; *--dp == ' ' || *dp == '.';); + for (dp = cp; *--dp == ' ' || *dp == '.';) + ; dp++; } @@ -540,7 +541,8 @@ unix2dosfn(u_char *un, u_char dn[11], int unlen, u_int gen) *--cp = gen % 10 + '0'; if (gen) return 0; - for (i = 8; dn[--i] == ' ';); + for (i = 8; dn[--i] == ' ';) + ; if (gentext + sizeof(gentext) - cp + 1 > 8 - i) i = 8 - (gentext + sizeof(gentext) - cp + 1); dn[i++] = '~'; @@ -563,7 +565,8 @@ unix2winfn(u_char *un, int unlen, struct winentry *wep, int cnt, int chksum) /* * Drop trailing blanks and dots */ - for (cp = un + unlen; *--cp == ' ' || *cp == '.'; unlen--); + for (cp = un + unlen; *--cp == ' ' || *cp == '.'; unlen--) + ; un += (cnt - 1) * WIN_CHARS; unlen -= (cnt - 1) * WIN_CHARS; @@ -571,7 +574,8 @@ unix2winfn(u_char *un, int unlen, struct winentry *wep, int cnt, int chksum) /* * Initialize winentry to some useful default */ - for (cp = (u_int8_t *)wep, i = sizeof(*wep); --i >= 0; *cp++ = 0xff); + for (cp = (u_int8_t *)wep, i = sizeof(*wep); --i >= 0; *cp++ = 0xff) + ; wep->weCnt = cnt; wep->weAttributes = ATTR_WIN95; wep->weReserved1 = 0; diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 51c65e8fa..154f7de78 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.369 2024/02/13 12:22:09 bluhm Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.370 2024/04/14 20:46:27 bluhm Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -1600,7 +1600,7 @@ bridge_ipsec(struct ifnet *ifp, struct ether_header *eh, int hassnap, off); tdb_unref(tdb); if (prot != IPPROTO_DONE) - ip_deliver(&m, &hlen, prot, af); + ip_deliver(&m, &hlen, prot, af, 0); return (1); } else { tdb_unref(tdb); diff --git a/sys/net80211/ieee80211_crypto.c b/sys/net80211/ieee80211_crypto.c index f13b535c7..8873924c2 100644 --- a/sys/net80211/ieee80211_crypto.c +++ b/sys/net80211/ieee80211_crypto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_crypto.c,v 1.78 2021/05/11 08:46:31 stsp Exp $ */ +/* $OpenBSD: ieee80211_crypto.c,v 1.79 2024/04/14 03:26:25 jsg Exp $ */ /*- * Copyright (c) 2008 Damien Bergamini @@ -538,7 +538,8 @@ ieee80211_eapol_key_encrypt(struct ieee80211com *ic, /* set IV to the lower 16 octets of our global key counter */ memcpy(key->iv, ic->ic_globalcnt + 16, 16); /* increment our global key counter (256-bit, big-endian) */ - for (n = 31; n >= 0 && ++ic->ic_globalcnt[n] == 0; n--); + for (n = 31; n >= 0 && ++ic->ic_globalcnt[n] == 0; n--) + ; /* concatenate the EAPOL-Key IV field and the KEK */ memcpy(keybuf, key->iv, EAPOL_KEY_IV_LEN); diff --git a/sys/net80211/ieee80211_output.c b/sys/net80211/ieee80211_output.c index a89ac8c91..a6161bf8e 100644 --- a/sys/net80211/ieee80211_output.c +++ b/sys/net80211/ieee80211_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_output.c,v 1.137 2022/03/14 15:07:24 stsp Exp $ */ +/* $OpenBSD: ieee80211_output.c,v 1.138 2024/04/14 03:26:25 jsg Exp $ */ /* $NetBSD: ieee80211_output.c,v 1.13 2004/05/31 11:02:55 dyoung Exp $ */ /*- @@ -798,14 +798,16 @@ ieee80211_add_tim(u_int8_t *frm, struct ieee80211com *ic) u_int i, offset = 0, len; /* find first non-zero octet in the virtual bit map */ - for (i = 0; i < ic->ic_tim_len && ic->ic_tim_bitmap[i] == 0; i++); + for (i = 0; i < ic->ic_tim_len && ic->ic_tim_bitmap[i] == 0; i++) + ; /* clear the lsb as it is reserved for the broadcast indication bit */ if (i < ic->ic_tim_len) offset = i & ~1; /* find last non-zero octet in the virtual bit map */ - for (i = ic->ic_tim_len - 1; i > 0 && ic->ic_tim_bitmap[i] == 0; i--); + for (i = ic->ic_tim_len - 1; i > 0 && ic->ic_tim_bitmap[i] == 0; i--) + ; len = i - offset + 1; diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index 9748baff7..a7ba54e52 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in_proto.c,v 1.103 2024/01/11 14:15:12 bluhm Exp $ */ +/* $OpenBSD: in_proto.c,v 1.104 2024/04/14 20:46:27 bluhm Exp $ */ /* $NetBSD: in_proto.c,v 1.14 1996/02/18 18:58:32 christos Exp $ */ /* @@ -210,7 +210,7 @@ const struct protosw inetsw[] = { .pr_type = SOCK_RAW, .pr_domain = &inetdomain, .pr_protocol = IPPROTO_RAW, - .pr_flags = PR_ATOMIC|PR_ADDR, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPINPUT, .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreqs = &rip_usrreqs, @@ -377,7 +377,7 @@ const struct protosw inetsw[] = { /* raw wildcard */ .pr_type = SOCK_RAW, .pr_domain = &inetdomain, - .pr_flags = PR_ATOMIC|PR_ADDR, + .pr_flags = PR_ATOMIC|PR_ADDR|PR_MPINPUT, .pr_input = rip_input, .pr_ctloutput = rip_ctloutput, .pr_usrreqs = &rip_usrreqs, diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 9c273238f..25f9cc5eb 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.391 2024/02/28 10:57:20 bluhm Exp $ */ +/* $OpenBSD: ip_input.c,v 1.392 2024/04/14 20:46:27 bluhm Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -245,6 +245,30 @@ ip_ours(struct mbuf **mp, int *offp, int nxt, int af) if (af != AF_UNSPEC) return nxt; + nxt = ip_deliver(mp, offp, nxt, AF_INET, 1); + if (nxt == IPPROTO_DONE) + return IPPROTO_DONE; + + /* save values for later, use after dequeue */ + if (*offp != sizeof(struct ip)) { + struct m_tag *mtag; + struct ipoffnxt *ion; + + /* mbuf tags are expensive, but only used for header options */ + mtag = m_tag_get(PACKET_TAG_IP_OFFNXT, sizeof(*ion), + M_NOWAIT); + if (mtag == NULL) { + ipstat_inc(ips_idropped); + m_freemp(mp); + return IPPROTO_DONE; + } + ion = (struct ipoffnxt *)(mtag + 1); + ion->ion_off = *offp; + ion->ion_nxt = nxt; + + m_tag_prepend(*mp, mtag); + } + niq_enqueue(&ipintrq, *mp); *mp = NULL; return IPPROTO_DONE; @@ -260,18 +284,31 @@ ipintr(void) struct mbuf *m; while ((m = niq_dequeue(&ipintrq)) != NULL) { - struct ip *ip; + struct m_tag *mtag; int off, nxt; #ifdef DIAGNOSTIC if ((m->m_flags & M_PKTHDR) == 0) panic("ipintr no HDR"); #endif - ip = mtod(m, struct ip *); - off = ip->ip_hl << 2; - nxt = ip->ip_p; + mtag = m_tag_find(m, PACKET_TAG_IP_OFFNXT, NULL); + if (mtag != NULL) { + struct ipoffnxt *ion; - nxt = ip_deliver(&m, &off, nxt, AF_INET); + ion = (struct ipoffnxt *)(mtag + 1); + off = ion->ion_off; + nxt = ion->ion_nxt; + + m_tag_delete(m, mtag); + } else { + struct ip *ip; + + ip = mtod(m, struct ip *); + off = ip->ip_hl << 2; + nxt = ip->ip_p; + } + + nxt = ip_deliver(&m, &off, nxt, AF_INET, 0); KASSERT(nxt == IPPROTO_DONE); } } @@ -675,15 +712,11 @@ ip_fragcheck(struct mbuf **mp, int *offp) #endif int -ip_deliver(struct mbuf **mp, int *offp, int nxt, int af) +ip_deliver(struct mbuf **mp, int *offp, int nxt, int af, int shared) { - const struct protosw *psw; - int naf = af; #ifdef INET6 int nest = 0; -#endif /* INET6 */ - - NET_ASSERT_LOCKED_EXCLUSIVE(); +#endif /* * Tell launch routine the next header @@ -691,13 +724,41 @@ ip_deliver(struct mbuf **mp, int *offp, int nxt, int af) IPSTAT_INC(delivered); while (nxt != IPPROTO_DONE) { + const struct protosw *psw; + int naf; + + switch (af) { + case AF_INET: + psw = &inetsw[ip_protox[nxt]]; + break; +#ifdef INET6 + case AF_INET6: + psw = &inet6sw[ip6_protox[nxt]]; + break; +#endif + } + if (shared && !ISSET(psw->pr_flags, PR_MPINPUT)) { + /* delivery not finished, decrement counter, queue */ + switch (af) { + case AF_INET: + counters_dec(ipcounters, ips_delivered); + break; +#ifdef INET6 + case AF_INET6: + counters_dec(ip6counters, ip6s_delivered); + break; +#endif + } + break; + } + #ifdef INET6 if (af == AF_INET6 && ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { ip6stat_inc(ip6s_toomanyhdr); goto bad; } -#endif /* INET6 */ +#endif /* * protection against faulty packet - there should be @@ -716,7 +777,7 @@ ip_deliver(struct mbuf **mp, int *offp, int nxt, int af) } } /* Otherwise, just fall through and deliver the packet */ -#endif /* IPSEC */ +#endif switch (nxt) { case IPPROTO_IPV4: @@ -728,17 +789,10 @@ ip_deliver(struct mbuf **mp, int *offp, int nxt, int af) naf = AF_INET6; ip6stat_inc(ip6s_delivered); break; -#endif /* INET6 */ - } - switch (af) { - case AF_INET: - psw = &inetsw[ip_protox[nxt]]; +#endif + default: + naf = af; break; -#ifdef INET6 - case AF_INET6: - psw = &inet6sw[ip6_protox[nxt]]; - break; -#endif /* INET6 */ } nxt = (*psw->pr_input)(mp, offp, nxt, af); af = naf; diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index 2c0d45379..c5b928475 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_var.h,v 1.114 2024/03/05 09:45:13 bluhm Exp $ */ +/* $OpenBSD: ip_var.h,v 1.115 2024/04/14 20:46:27 bluhm Exp $ */ /* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */ /* @@ -198,6 +198,11 @@ struct ipq { struct in_addr ipq_src, ipq_dst; }; +struct ipoffnxt { + int ion_off; + int ion_nxt; +}; + /* flags passed to ip_output */ #define IP_FORWARDING 0x1 /* most of ip header exists */ #define IP_RAWOUTPUT 0x2 /* raw ip header exists */ @@ -254,7 +259,7 @@ int ip_sysctl(int *, u_int, void *, size_t *, void *, size_t); void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, struct mbuf *); int ip_input_if(struct mbuf **, int *, int, int, struct ifnet *); -int ip_deliver(struct mbuf **, int *, int, int); +int ip_deliver(struct mbuf **, int *, int, int, int); void ip_forward(struct mbuf *, struct ifnet *, struct rtentry *, int); int rip_ctloutput(int, struct socket *, int, int, struct mbuf *); void rip_init(void); diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 112fe6037..5f4e991e0 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_input.c,v 1.259 2024/02/28 10:57:20 bluhm Exp $ */ +/* $OpenBSD: ip6_input.c,v 1.260 2024/04/14 20:46:27 bluhm Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -166,11 +166,6 @@ ip6_init(void) #endif } -struct ip6_offnxt { - int ion_off; - int ion_nxt; -}; - /* * Enqueue packet for local delivery. Queuing is used as a boundary * between the network layer (input/forward path) running with @@ -190,10 +185,14 @@ ip6_ours(struct mbuf **mp, int *offp, int nxt, int af) if (af != AF_UNSPEC) return nxt; + nxt = ip_deliver(mp, offp, nxt, AF_INET6, 1); + if (nxt == IPPROTO_DONE) + return IPPROTO_DONE; + /* save values for later, use after dequeue */ if (*offp != sizeof(struct ip6_hdr)) { struct m_tag *mtag; - struct ip6_offnxt *ion; + struct ipoffnxt *ion; /* mbuf tags are expensive, but only used for header options */ mtag = m_tag_get(PACKET_TAG_IP6_OFFNXT, sizeof(*ion), @@ -203,7 +202,7 @@ ip6_ours(struct mbuf **mp, int *offp, int nxt, int af) m_freemp(mp); return IPPROTO_DONE; } - ion = (struct ip6_offnxt *)(mtag + 1); + ion = (struct ipoffnxt *)(mtag + 1); ion->ion_off = *offp; ion->ion_nxt = nxt; @@ -234,9 +233,9 @@ ip6intr(void) #endif mtag = m_tag_find(m, PACKET_TAG_IP6_OFFNXT, NULL); if (mtag != NULL) { - struct ip6_offnxt *ion; + struct ipoffnxt *ion; - ion = (struct ip6_offnxt *)(mtag + 1); + ion = (struct ipoffnxt *)(mtag + 1); off = ion->ion_off; nxt = ion->ion_nxt; @@ -248,7 +247,7 @@ ip6intr(void) off = sizeof(struct ip6_hdr); nxt = ip6->ip6_nxt; } - nxt = ip_deliver(&m, &off, nxt, AF_INET6); + nxt = ip_deliver(&m, &off, nxt, AF_INET6, 0); KASSERT(nxt == IPPROTO_DONE); } } diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 866a65b1d..b458e0e89 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.262 2024/02/21 13:42:06 bluhm Exp $ */ +/* $OpenBSD: mbuf.h,v 1.263 2024/04/14 20:46:27 bluhm Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -471,6 +471,8 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); #define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */ #define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */ #define PACKET_TAG_IPSEC_FLOWINFO 0x0004 /* IPsec flowinfo */ +#define PACKET_TAG_IP_OFFNXT 0x0010 /* IPv4 offset and next proto */ +#define PACKET_TAG_IP6_OFFNXT 0x0020 /* IPv6 offset and next proto */ #define PACKET_TAG_WIREGUARD 0x0040 /* WireGuard data */ #define PACKET_TAG_GRE 0x0080 /* GRE processing done */ #define PACKET_TAG_DLT 0x0100 /* data link layer type */ @@ -479,7 +481,6 @@ struct m_tag *m_tag_next(struct mbuf *, struct m_tag *); #define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */ #define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */ #define PACKET_TAG_CARP_BAL_IP 0x4000 /* carp(4) ip balanced marker */ -#define PACKET_TAG_IP6_OFFNXT 0x8000 /* IPv6 offset and next proto */ #define MTAG_BITS \ ("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_FLOWINFO" \ diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 582f5ad7e..7fae350d4 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -1,4 +1,4 @@ -/* $OpenBSD: protosw.h,v 1.65 2024/02/03 22:50:09 mvs Exp $ */ +/* $OpenBSD: protosw.h,v 1.66 2024/04/14 20:46:27 bluhm Exp $ */ /* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd Exp $ */ /*- @@ -132,6 +132,7 @@ struct protosw { #define PR_ABRTACPTDIS 0x0020 /* abort on accept(2) to disconnected socket */ #define PR_SPLICE 0x0040 /* socket splicing is possible */ +#define PR_MPINPUT 0x0080 /* input runs with shared netlock */ /* * The arguments to usrreq are: diff --git a/usr.bin/less/ch.c b/usr.bin/less/ch.c index d7c0aa34e..8ca21eadc 100644 --- a/usr.bin/less/ch.c +++ b/usr.bin/less/ch.c @@ -778,7 +778,7 @@ ch_close(void) if (thisfile == NULL) return; - if (ch_flags & (CH_CANSEEK|CH_POPENED|CH_HELPFILE)) { + if (ch_flags & (CH_CANSEEK|CH_HELPFILE)) { /* * We can seek or re-open, so we don't need to keep buffers. */ @@ -790,11 +790,8 @@ ch_close(void) /* * We don't need to keep the file descriptor open * (because we can re-open it.) - * But don't really close it if it was opened via popen(), - * because pclose() wants to close it. */ - if (!(ch_flags & CH_POPENED)) - close(ch_file); + close(ch_file); ch_file = -1; } else { keepstate = TRUE; diff --git a/usr.bin/less/command.c b/usr.bin/less/command.c index 4fc19d949..d9464a32f 100644 --- a/usr.bin/less/command.c +++ b/usr.bin/less/command.c @@ -35,7 +35,6 @@ extern int hshift; extern int show_attn; extern off_t highest_hilite; extern char *every_first_cmd; -extern char *curr_altfilename; extern char version[]; extern struct scrpos initial_scrpos; extern IFILE curr_ifile; @@ -1412,10 +1411,6 @@ again: error("Cannot edit standard input", NULL); break; } - if (curr_altfilename != NULL) { - error("WARNING: This file was viewed via " - "LESSOPEN", NULL); - } /* * Expand the editor prototype string * and pass it to the system to execute. diff --git a/usr.bin/less/edit.c b/usr.bin/less/edit.c index eff4d28dc..15a5be67e 100644 --- a/usr.bin/less/edit.c +++ b/usr.bin/less/edit.c @@ -35,9 +35,6 @@ extern char *namelogfile; dev_t curr_dev; ino_t curr_ino; -char *curr_altfilename = NULL; -static void *curr_altpipe; - /* * Textlist functions deal with a list of words separated by spaces. @@ -146,16 +143,6 @@ close_file(void) * Close the file descriptor, unless it is a pipe. */ ch_close(); - /* - * If we opened a file using an alternate name, - * do special stuff to close it. - */ - if (curr_altfilename != NULL) { - close_altfile(curr_altfilename, get_filename(curr_ifile), - curr_altpipe); - free(curr_altfilename); - curr_altfilename = NULL; - } curr_ifile = NULL; curr_ino = curr_dev = 0; } @@ -185,10 +172,7 @@ edit_ifile(IFILE ifile) int no_display; int chflags; char *filename; - char *open_filename; char *qopen_filename; - char *alt_filename; - void *alt_pipe; IFILE was_curr_ifile; PARG parg; @@ -200,11 +184,9 @@ edit_ifile(IFILE ifile) } /* - * We must close the currently open file now. - * This is necessary to make the open_altfile/close_altfile pairs - * nest properly (or rather to avoid nesting at all). - * {{ Some stupid implementations of popen() mess up if you do: - * fA = popen("A"); fB = popen("B"); pclose(fA); pclose(fB); }} + * We close the currently open file now. This was done before + * to avoid linked popen/pclose pairs from LESSOPEN, but there + * may other code that has come to rely on this restriction. */ end_logfile(); was_curr_ifile = save_curr_ifile(); @@ -233,47 +215,28 @@ edit_ifile(IFILE ifile) } filename = estrdup(get_filename(ifile)); - /* - * See if LESSOPEN specifies an "alternate" file to open. - */ - alt_pipe = NULL; - alt_filename = open_altfile(filename, &f, &alt_pipe); - open_filename = (alt_filename != NULL) ? alt_filename : filename; - qopen_filename = shell_unquote(open_filename); + qopen_filename = shell_unquote(filename); chflags = 0; - if (strcmp(open_filename, helpfile()) == 0) + if (strcmp(filename, helpfile()) == 0) chflags |= CH_HELPFILE; - if (alt_pipe != NULL) { - /* - * The alternate "file" is actually a pipe. - * f has already been set to the file descriptor of the pipe - * in the call to open_altfile above. - * Keep the file descriptor open because it was opened - * via popen(), and pclose() wants to close it. - */ - chflags |= CH_POPENED; - } else if (strcmp(open_filename, "-") == 0) { + if (strcmp(filename, "-") == 0) { /* * Use standard input. * Keep the file descriptor open because we can't reopen it. */ f = fd0; chflags |= CH_KEEPOPEN; - } else if (strcmp(open_filename, FAKE_EMPTYFILE) == 0) { + } else if (strcmp(filename, FAKE_EMPTYFILE) == 0) { f = -1; chflags |= CH_NODATA; - } else if ((parg.p_string = bad_file(open_filename)) != NULL) { + } else if ((parg.p_string = bad_file(filename)) != NULL) { /* * It looks like a bad file. Don't try to open it. */ error("%s", &parg); free(parg.p_string); err1: - if (alt_filename != NULL) { - close_altfile(alt_filename, filename, alt_pipe); - free(alt_filename); - } del_ifile(ifile); free(qopen_filename); free(filename); @@ -323,8 +286,6 @@ err1: unsave_ifile(was_curr_ifile); } curr_ifile = ifile; - curr_altfilename = alt_filename; - curr_altpipe = alt_pipe; set_open(curr_ifile); /* File has been opened */ get_pos(curr_ifile, &initial_scrpos); new_file = TRUE; diff --git a/usr.bin/less/filename.c b/usr.bin/less/filename.c index 8b2dd9a02..0aaecac61 100644 --- a/usr.bin/less/filename.c +++ b/usr.bin/less/filename.c @@ -26,7 +26,6 @@ extern int force_open; extern int secure; -extern int use_lessopen; extern int ctldisp; extern int utf_mode; extern IFILE curr_ifile; @@ -106,6 +105,15 @@ metachar(char c) return (strchr(metachars(), c) != NULL); } +/* + * Must use quotes rather than escape characters for this meta character. + */ +static int +must_quote(char c) +{ + return (c == '\n'); +} + /* * Insert a backslash before each metacharacter in a string. */ @@ -136,6 +144,9 @@ shell_quote(const char *s) * doesn't support escape chars. Use quotes. */ use_quotes = 1; + } else if (must_quote(*p)) { + /* Opening quote + character + closing quote. */ + len += 3; } else { /* * Allow space for the escape char. @@ -155,14 +166,19 @@ shell_quote(const char *s) } else { newstr = r = ecalloc(len, sizeof (char)); while (*s != '\0') { - if (metachar(*s)) { - /* - * Add the escape char. - */ + if (!metachar(*s)) { + *r++ = *s++; + } else if (must_quote(*s)) { + /* Surround the character with quotes. */ + *r++ = openquote; + *r++ = *s++; + *r++ = closequote; + } else { + /* Escape the character. */ (void) strlcpy(r, esc, newstr + len - p); r += esclen; + *r++ = *s++; } - *r++ = *s++; } *r = '\0'; } @@ -501,182 +517,6 @@ lglob(char *filename) return (gfilename); } -/* - * Expand LESSOPEN or LESSCLOSE. Returns a newly allocated string - * on success, NULL otherwise. - */ -static char * -expand_pct_s(const char *fmt, ...) -{ - int n; - int len; - char *r, *d; - const char *f[3]; /* max expansions + 1 for NULL */ - va_list ap; - - va_start(ap, fmt); - for (n = 0; n < ((sizeof (f)/sizeof (f[0])) - 1); n++) { - f[n] = (const char *)va_arg(ap, const char *); - if (f[n] == NULL) { - break; - } - } - va_end(ap); - f[n] = NULL; /* terminate list */ - - len = strlen(fmt) + 1; - for (n = 0; f[n] != NULL; n++) { - len += strlen(f[n]); /* technically could -2 for "%s" */ - } - r = ecalloc(len, sizeof (char)); - - for (n = 0, d = r; *fmt != 0; ) { - if (*fmt != '%') { - *d++ = *fmt++; - continue; - } - fmt++; - /* Permit embedded "%%" */ - switch (*fmt) { - case '%': - *d++ = '%'; - fmt++; - break; - case 's': - if (f[n] == NULL) { - va_end(ap); - free(r); - return (NULL); - } - (void) strlcpy(d, f[n++], r + len - d); - fmt++; - d += strlen(d); - break; - default: - va_end(ap); - free(r); - return (NULL); - } - } - *d = '\0'; - return (r); -} - -/* - * See if we should open a "replacement file" - * instead of the file we're about to open. - */ -char * -open_altfile(char *filename, int *pf, void **pfd) -{ - char *lessopen; - char *cmd; - FILE *fd; - int returnfd = 0; - - if (!use_lessopen || secure) - return (NULL); - ch_ungetchar(-1); - if ((lessopen = lgetenv("LESSOPEN")) == NULL) - return (NULL); - while (*lessopen == '|') { - /* - * If LESSOPEN starts with a |, it indicates - * a "pipe preprocessor". - */ - lessopen++; - returnfd++; - } - if (*lessopen == '-') { - /* - * Lessopen preprocessor will accept "-" as a filename. - */ - lessopen++; - } else { - if (strcmp(filename, "-") == 0) - return (NULL); - } - - if ((cmd = expand_pct_s(lessopen, filename, NULL)) == NULL) { - error("Invalid LESSOPEN variable", NULL); - return (NULL); - } - fd = shellcmd(cmd); - free(cmd); - if (fd == NULL) { - /* - * Cannot create the pipe. - */ - return (NULL); - } - if (returnfd) { - int f; - char c; - - /* - * Read one char to see if the pipe will produce any data. - * If it does, push the char back on the pipe. - */ - f = fileno(fd); - if (read(f, &c, 1) != 1) { - /* - * Pipe is empty. - * If more than 1 pipe char was specified, - * the exit status tells whether the file itself - * is empty, or if there is no alt file. - * If only one pipe char, just assume no alt file. - */ - int status = pclose(fd); - if (returnfd > 1 && status == 0) { - *pfd = NULL; - *pf = -1; - return (estrdup(FAKE_EMPTYFILE)); - } - return (NULL); - } - ch_ungetchar(c); - *pfd = (void *) fd; - *pf = f; - return (estrdup("-")); - } - cmd = readfd(fd); - pclose(fd); - if (*cmd == '\0') - /* - * Pipe is empty. This means there is no alt file. - */ - return (NULL); - return (cmd); -} - -/* - * Close a replacement file. - */ -void -close_altfile(char *altfilename, char *filename, void *pipefd) -{ - char *lessclose; - FILE *fd; - char *cmd; - - if (secure) - return; - if (pipefd != NULL) { - pclose((FILE *)pipefd); - } - if ((lessclose = lgetenv("LESSCLOSE")) == NULL) - return; - cmd = expand_pct_s(lessclose, filename, altfilename, NULL); - if (cmd == NULL) { - error("Invalid LESSCLOSE variable", NULL); - return; - } - fd = shellcmd(cmd); - free(cmd); - if (fd != NULL) - (void) pclose(fd); -} - /* * Is the specified file a directory? */ diff --git a/usr.bin/less/funcs.h b/usr.bin/less/funcs.h index 2e707c3f6..ec86a3102 100644 --- a/usr.bin/less/funcs.h +++ b/usr.bin/less/funcs.h @@ -122,8 +122,6 @@ char *fexpand(char *); char *fcomplete(char *); int bin_file(int f); char *lglob(char *); -char *open_altfile(char *, int *, void **); -void close_altfile(char *, char *, void *); int is_dir(char *); char *bad_file(char *); off_t filesize(int); diff --git a/usr.bin/less/less.1 b/usr.bin/less/less.1 index 10811edcd..fca7496f2 100644 --- a/usr.bin/less/less.1 +++ b/usr.bin/less/less.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: less.1,v 1.59 2021/12/10 17:26:54 schwarze Exp $ +.\" $OpenBSD: less.1,v 1.60 2024/04/14 18:11:54 guenther Exp $ .\" .\" Copyright (C) 1984-2012 Mark Nudelman .\" @@ -23,7 +23,7 @@ .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: December 10 2021 $ +.Dd $Mdocdate: April 14 2024 $ .Dt LESS 1 .Os .Sh NAME @@ -304,16 +304,6 @@ environment variable is set, or if a lesskey file is found in a standard place (see .Sx KEY BINDINGS ) , it is also used as a lesskey file. -.It Fl L | -no-lessopen -Ignore the -.Ev LESSOPEN -environment variable (see the -.Sx INPUT PREPROCESSOR -section below). -This option can be set from within -.Nm less , -but it will apply only to files opened subsequently, not to the -file which is currently open. .It Fl M | -LONG-PROMPT Causes .Nm @@ -1258,160 +1248,6 @@ On .Ox , the system-wide lesskey file is .Pa /etc/sysless . -.Sh INPUT PREPROCESSOR -You may define an "input preprocessor" for -.Nm less . -Before -.Nm less -opens a file, it first gives your input preprocessor a chance to modify the -way the contents of the file are displayed. -An input preprocessor is simply an executable program (or shell script), -which writes the contents of the file to a different file, -called the replacement file. -The contents of the replacement file are then displayed -in place of the contents of the original file. -However, it will appear to the user as if the original file is opened; -that is, -.Nm less -will display the original filename as the name of the current file. -.Pp -An input preprocessor receives one command line argument, the original filename, -as entered by the user. -It should create the replacement file, and when finished -print the name of the replacement file to its standard output. -If the input preprocessor does not output a replacement filename, -.Nm -uses the original file, as normal. -The input preprocessor is not called when viewing standard input. -To set up an input preprocessor, set the -.Ev LESSOPEN -environment variable to a command line which will invoke your -input preprocessor. -This command line should include one occurrence of the string "%s", -which will be replaced by the filename -when the input preprocessor command is invoked. -.Pp -When -.Nm -closes a file opened in such a way, it will call another program, -called the input postprocessor, -which may perform any desired clean-up action (such as deleting the -replacement file created by -.Ev LESSOPEN ) . -This program receives two command line arguments, the original filename -as entered by the user, and the name of the replacement file. -To set up an input postprocessor, set the -.Ev LESSCLOSE -environment variable to a command line which will invoke your -input postprocessor. -It may include two occurrences of the string "%s"; -the first is replaced with the original name of the file and the second -with the name of the replacement file, which was output by -.Ev LESSOPEN . -.Pp -For example, these two scripts will allow you -to keep files in compressed format, but still let -.Nm -view them directly: -.Pp -lessopen.sh: -.Bd -literal -offset indent -#! /bin/sh -case "$1" in -*.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null - if [ -s /tmp/less.$$ ]; then - echo /tmp/less.$$ - else - rm -f /tmp/less.$$ - fi - ;; -esac -.Ed -.Pp -lessclose.sh: -.Bd -literal -offset indent -#! /bin/sh -rm $2 -.Ed -.Pp -To use these scripts, put them both where they can be executed and -set LESSOPEN="lessopen.sh\ %s", and LESSCLOSE="lessclose.sh\ %s\ %s". -More complex LESSOPEN and LESSCLOSE scripts may be written -to accept other types of compressed files, and so on. -.Pp -It is also possible to set up an input preprocessor to -pipe the file data directly to -.Nm less , -rather than putting the data into a replacement file. -This avoids the need to decompress the entire file before starting to view it. -An input preprocessor that works this way is called an input pipe. -An input pipe, instead of writing the name of a replacement file on -its standard output, -writes the entire contents of the replacement file on its standard output. -If the input pipe does not write any characters on its standard output, -then there is no replacement file and -.Nm -uses the original file, as normal. -To use an input pipe, make the first character in the -.Ev LESSOPEN -environment variable a vertical bar (|) to signify that the -input preprocessor is an input pipe. -.Pp -For example, this script will work like the previous example scripts: -.Pp -lesspipe.sh: -.Bd -literal -offset indent -#! /bin/sh -case "$1" in -*.Z) uncompress -c $1 2>/dev/null -*) exit 1 - ;; -esac -exit $? -.Ed -.Pp -To use this script, put it where it can be executed and set -LESSOPEN="|lesspipe.sh %s". -.Pp -Note that a preprocessor cannot output an empty file, since that -is interpreted as meaning there is no replacement, and -the original file is used. -To avoid this, if -.Ev LESSOPEN -starts with two vertical bars, -the exit status of the script becomes meaningful. -If the exit status is zero, the output is considered to be -replacement text, even if it empty. -If the exit status is nonzero, any output is ignored and the -original file is used. -For compatibility with previous versions of -.Nm less , -if -.Ev LESSOPEN -starts with only one vertical bar, the exit status -of the preprocessor is ignored. -.Pp -When an input pipe is used, a LESSCLOSE postprocessor can be used, -but it is usually not necessary since there is no replacement file to clean up. -In this case, the replacement file name passed to the LESSCLOSE -postprocessor is "-". -.Pp -For compatibility with previous versions of -.Nm less , -the input preprocessor or pipe is not used if -.Nm -is viewing standard input. -However, if the first character of LESSOPEN is a dash (-), -the input preprocessor is used on standard input as well as other files. -In this case, the dash is not considered to be part of -the preprocessor command. -If standard input is being viewed, the input preprocessor is passed -a file name consisting of a single dash. -Similarly, if the first two characters of LESSOPEN are vertical bar and dash -(|-) or two vertical bars and a dash (||-), -the input pipe is used on standard input as well as other files. -Again, in this case the dash is not considered to be part of -the input pipe command. .Sh NATIONAL CHARACTER SETS There are three types of characters in the input file: .Bl -tag -width "control characters" @@ -1843,8 +1679,6 @@ end character in an ANSI color escape sequence (default "0123456789;[?!"'#%()*+\ "). .It Ev LESSBINFMT Format for displaying non-printable, non-control characters. -.It Ev LESSCLOSE -Command line to invoke the (optional) input-postprocessor. .It Ev LESSEDIT Editor prototype string (used for the v command). See discussion under @@ -1874,8 +1708,6 @@ Prefix which will add before each metacharacter in a command sent to the shell. If LESSMETAESCAPE is an empty string, commands containing metacharacters will not be passed to the shell. -.It Ev LESSOPEN -Command line to invoke the (optional) input-preprocessor. .It Ev LESSSECURE Runs less in "secure" mode. See discussion under diff --git a/usr.bin/less/less.h b/usr.bin/less/less.h index 259ade82e..012c0b6ab 100644 --- a/usr.bin/less/less.h +++ b/usr.bin/less/less.h @@ -165,7 +165,6 @@ extern int abort_sigs(void); /* filestate flags */ #define CH_CANSEEK 001 #define CH_KEEPOPEN 002 -#define CH_POPENED 004 #define CH_HELPFILE 010 #define CH_NODATA 020 /* Special case for zero length files */ diff --git a/usr.bin/less/less.hlp b/usr.bin/less/less.hlp index 2bc53df37..8bcae610d 100644 --- a/usr.bin/less/less.hlp +++ b/usr.bin/less/less.hlp @@ -149,8 +149,6 @@ Use a lesskey file. -K --quit-on-intr Exit less in response to ctrl-C. - -L ........ --no-lessopen - Ignore the LESSOPEN environment variable. -m -M .... --long-prompt --LONG-PROMPT Set prompt style. -n -N .... --line-numbers --LINE-NUMBERS diff --git a/usr.bin/less/main.c b/usr.bin/less/main.c index a29999e02..926d1d4b1 100644 --- a/usr.bin/less/main.c +++ b/usr.bin/less/main.c @@ -53,7 +53,6 @@ extern int quit_if_one_screen; extern int quit_at_eof; extern int pr_type; extern int hilite_search; -extern int use_lessopen; extern int no_init; extern int top_scroll; extern int errmsgs; @@ -131,9 +130,6 @@ main(int argc, char *argv[]) /* do not highlight search terms */ hilite_search = OPT_OFF; - /* do not use LESSOPEN */ - use_lessopen = OPT_OFF; - /* do not set init strings to terminal */ no_init = OPT_ON; diff --git a/usr.bin/less/opttbl.c b/usr.bin/less/opttbl.c index 483f4c166..301976e36 100644 --- a/usr.bin/less/opttbl.c +++ b/usr.bin/less/opttbl.c @@ -236,8 +236,8 @@ static struct loption option[] = { { 'L', &L__optname, BOOL, OPT_ON, &use_lessopen, NULL, { - "Don't use the LESSOPEN filter", - "Use the LESSOPEN filter", + "(ignored)", + "(ignored)", NULL } },