Projects
openEuler:Mainline
util-linux
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 3
View file
_service:tar_scm:util-linux.spec
Changed
@@ -3,7 +3,7 @@ Name: util-linux Version: 2.37.2 -Release: 17 +Release: 19 Summary: A random collection of Linux utilities License: GPLv2 and GPLv2+ and LGPLv2+ and BSD with advertising and Public Domain URL: https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git @@ -25,54 +25,85 @@ Patch6004: fix-size-use-for-stdin.patch Patch6005: segmentation-fault-on-invalid-unicode-input-passed-to-s-option.patch Patch6006: backport-fix-by-ignoring-EINVAL-on-remount-of-proc.patch -Patch6007: backport-su-bash-completion-offer-usernames-rather-than-files.patch -Patch6008: backport-Fix-memory-leaks-in-the-chcpu.patch -Patch6009: backport-logger-fix-prio-prefix-doesn-t-use-priority-default.patch -Patch6010: backport-vipw-flush-stdout-before-getting-answer.patch -Patch6011: backport-login-Restore-tty-size-after-calling-vhangup.patch -Patch6012: backport-Forward-value-of-sector_size-instead-of-its-address.patch -Patch6013: backport-libfdisk-dereference-of-possibly-NULL-gcc-analyzer.patch -Patch6014: backport-libfdisk-check-calloc-return-gcc-analyzer.patch -Patch6015: backport-mcookie-fix-infinite-loop-when-use-f.patch -Patch6016: backport-sfdisk-write-empty-label-also-when-only-ignored-part.patch -Patch6017: backport-fstat-dir-itself.patch -Patch6018: backport-libblkid-src-topology-dm-close-redundant-write-file-.patch -Patch6019: backport-libblkid-topology-init-variables-for-DM.patch -Patch6020: backport-sfdisk-fix-typo-in-move-data-when-check-partition-size.patch -Patch6021: backport-losetup-fix-memory-leak-asan.patch -Patch6022: backport-partx-remove-memory-leak-to-make-scanners-happy-coverity-scan.patch -Patch6023: backport-lib-path-make-ul_path_read_buffer-more-robust-coverity-scan.patch -Patch6024: backport-libmount-fix-possible-memory-leak-in-mnt_optstr_fix_secontext-coverity-scan.patch -Patch6025: backport-libblkid-probe-fix-size-and-offset-overflows-fuzzing.patch -Patch6026: backport-lslogins-improve-prefixes-interpretation.patch -Patch6027: backport-lsns-fix-the-memory-leak.patch -Patch6028: backport-libblkid-check-fsync-return-code.patch -Patch6029: backport-libblkid-mac-make-sure-block-size-is-large-enough-fuzzing.patch -Patch6030: backport-libblkid-bsd-fix-buffer-pointer-use-fuzzing.patch -Patch6031: backport-libblkid-hfs-fix-label-use-fuzzing.patch -Patch6032: backport-Maybe-there-is-a-little-mistake-in-do_taskset-functi.patch -Patch6033: backport-lsblk-fix-endless-loop-if-device-specified-more-than-once.patch -Patch6034: backport-libblkid-avoid-buffer-overflow-in-ocfs-superblock-parsing.patch -Patch6035: backport-fsck-Processes-may-kill-other-processes.patch -Patch6036: backport-fdisk-fix-output-option-parsing.patch -Patch6037: backport-libblkid-exfat-fix-divide-by-zero-coverity-scan.patch -Patch6038: backport-llib-pty-session-split-PTY-and-signalfd-setup.patch -Patch6039: backport-script-fix-use-of-utempter.patch -Patch6040: backport-logger-always-update-header-when-read-from-stdin.patch -Patch6041: backport-libblkid-use-checksum-for-jmicron.patch -Patch6042: backport-libblkid-cleanup-indentation.patch -Patch6043: backport-libblkid-fix-jmicron-checksum-and-LE-to-CPU.patch -Patch6044: backport-libblkid-fix-misaligned-address-in-probe_exfat.patch -Patch6045: backport-ldattach-fix-intro-command-and-pause.patch -Patch6046: backport-iso9660.h-use-more-correct-function-types.patch -Patch6047: backport-iso9660.h-avoid-undefined-signed-integer-shift.patch -Patch6048: backport-ipc_msg_get_limits-always-initialize-memory.patch -Patch6049: backport-wdctl-mark-flags-field-as-unsigned-long.patch -Patch6050: backport-login-never-send-signals-to-init.patch -Patch6051: backport-mkswap-do-not-use-uninitialized-stack-value.patch -Patch6052: backport-lib-pager-fix-signal-safety-issues.patch -Patch6053: backport-libblkid-nvidia_raid-verify-superblock-size.patch -Patch6054: backport-libblkid-nvidia_raid-validate-checksum.patch +Patch6007: backport-flush-stdout-before-reading-stdin-and-fix-uninitialized-variable.patch +Patch6008: backport-fflush-stdout-before-reading-from-stdin.patch +Patch6009: backport-CVE-2022-0563.patch +Patch6010: backport-su-bash-completion-offer-usernames-rather-than-files.patch +Patch6011: backport-Fix-memory-leaks-in-the-chcpu.patch +Patch6012: backport-logger-fix-prio-prefix-doesn-t-use-priority-default.patch +Patch6013: backport-vipw-flush-stdout-before-getting-answer.patch +Patch6014: backport-login-Restore-tty-size-after-calling-vhangup.patch +Patch6015: backport-Forward-value-of-sector_size-instead-of-its-address.patch +Patch6016: backport-libfdisk-dereference-of-possibly-NULL-gcc-analyzer.patch +Patch6017: backport-libfdisk-check-calloc-return-gcc-analyzer.patch +Patch6018: backport-mcookie-fix-infinite-loop-when-use-f.patch +Patch6019: backport-sfdisk-write-empty-label-also-when-only-ignored-part.patch +Patch6020: backport-fstat-dir-itself.patch +Patch6021: backport-sfdisk-fix-typo-in-move-data-when-check-partition-size.patch +Patch6022: backport-sysfs-fallback-for-partitions-not-including-parent-name.patch +Patch6023: backport-libmount-all-continue-although-proc-is-not-mounted.patch +Patch6024: backport-libblkid-don-t-mark-cache-as-probed-if-sys-not-available.patch +Patch6025: backport-lib-path-make-path-use-more-robust-coverity-scan.patch +Patch6026: backport-Fix-integer-overflow-for-alpha-like-linux.patch +Patch6027: backport-last-don-t-assume-zero-terminate-strings.patch +Patch6028: backport-script-fix-passing-args-to-execlp.patch +Patch6029: backport-scriptlive-fix-argv-0-for-execlp.patch +Patch6030: backport-losetup-fix-memory-leak-asan.patch +Patch6031: backport-partx-remove-memory-leak-to-make-scanners-happy-coverity-scan.patch +Patch6032: backport-lib-path-make-ul_path_read_buffer-more-robust-coverity-scan.patch +Patch6033: backport-libblkid-make-blkid_free_probe-more-robust.patch +Patch6034: backport-libmount-fix-possible-memory-leak-in-mnt_optstr_fix_secontext-coverity-scan.patch +Patch6035: backport-lslocks-fix-maj-min-scanf.patch +Patch6036: backport-column-don-t-require-column-name-for-JSON.patch +Patch6037: backport-libblkid-check-fsync-return-code.patch +Patch6038: backport-lib-strutils-improve-strtoul_or_err-for-negative-numbers.patch +Patch6039: backport-dmesg-fix-since-and-until.patch +Patch6040: backport-lib-allow-safe_getenv-to-work-for-non-root-users.patch +Patch6041: backport-Maybe-there-is-a-little-mistake-in-do_taskset-functi.patch +Patch6042: backport-loopdev-set-block_size-when-using-LOOP_CONFIGURE.patch +Patch6043: backport-libblkid-probe-fix-size-and-offset-overflows-fuzzing.patch +Patch6044: backport-libblkid-bsd-fix-buffer-pointer-use-fuzzing.patch +Patch6045: backport-libblkid-mac-make-sure-block-size-is-large-enough-fuzzing.patch +Patch6046: backport-libblkid-hfs-fix-label-use-fuzzing.patch +Patch6047: backport-libblkid-hfs-fix-make-sure-buffer-is-large-enough.patch +Patch6048: backport-lslogins-fix-free-invalid-pointer.patch +Patch6049: backport-lsns-fix-the-memory-leak.patch +Patch6050: backport-libblkid-src-topology-dm-close-redundant-write-file-.patch +Patch6051: backport-libblkid-topology-init-variables-for-DM.patch +Patch6052: backport-lslogins-improve-prefixes-interpretation.patch +Patch6053: backport-lsblk-fix-endless-loop-if-device-specified-more-than-once.patch +Patch6054: backport-libblkid-avoid-buffer-overflow-in-ocfs-superblock-parsing.patch +Patch6055: backport-fsck-Processes-may-kill-other-processes.patch +Patch6056: backport-fdisk-fix-output-option-parsing.patch +Patch6057: backport-libblkid-exfat-fix-divide-by-zero-coverity-scan.patch +Patch6058: backport-llib-pty-session-split-PTY-and-signalfd-setup.patch +Patch6059: backport-script-fix-use-of-utempter.patch +Patch6060: backport-logger-always-update-header-when-read-from-stdin.patch +Patch6061: backport-libblkid-use-checksum-for-jmicron.patch +Patch6062: backport-libblkid-cleanup-indentation.patch +Patch6063: backport-libblkid-fix-jmicron-checksum-and-LE-to-CPU.patch +Patch6064: backport-libblkid-fix-misaligned-address-in-probe_exfat.patch +Patch6065: backport-ldattach-fix-intro-command-and-pause.patch +Patch6066: backport-iso9660.h-use-more-correct-function-types.patch +Patch6067: backport-iso9660.h-avoid-undefined-signed-integer-shift.patch +Patch6068: backport-ipc_msg_get_limits-always-initialize-memory.patch +Patch6069: backport-wdctl-mark-flags-field-as-unsigned-long.patch +Patch6070: backport-login-never-send-signals-to-init.patch +Patch6071: backport-mkswap-do-not-use-uninitialized-stack-value.patch +Patch6072: backport-lib-pager-fix-signal-safety-issues.patch +Patch6073: backport-libblkid-nvidia_raid-verify-superblock-size.patch +Patch6074: backport-libblkid-nvidia_raid-validate-checksum.patch +Patch6075: backport-libfdisk-Fix-randomly-generated-GPT-UUID-s.patch +Patch6076: backport-write-correctly-handle-wide-characters.patch +Patch6077: backport-wall-convert-homebrew-buffering-to-open_memstream.patch +Patch6078: backport-wall-use-fputs_careful.patch +Patch6079: backport-hexdump-parse-handle-truncated-format-pattern.patch +Patch6080: backport-libblkid-copy-BLKID_PARTS_FORCE_GPT-to-whole-disk-pr.patch +Patch6081: backport-lscpu-fix-p-output-all-caches-delimiter.patch +Patch6082: backport-add-return-in-supam_conv-function.patch +Patch6083: backport-wrap-return-in-else-directive-to-avoid-dead-code.patch +Patch6084: backport-sulogin-ignore-none-existing-console-devices.patch +Patch6085: backport-sulogin-fix-KDGKBMODE-ifdef.patch Patch9000: Add-check-to-resolve-uname26-version-test-failed.patch Patch9001: SKIPPED-no-root-permissions-test.patch @@ -81,7 +112,7 @@ %endif BuildRequires: audit-libs-devel >= 1.0.6 gettext-devel libselinux-devel ncurses-devel pam-devel zlib-devel popt-devel -BuildRequires: libutempter-devel systemd-devel systemd libuser-devel libcap-ng-devel python3-devel gcc +BuildRequires: libutempter-devel systemd-devel systemd libuser-devel libcap-ng-devel python3-devel gcc autoconf automake Requires(post): coreutils Requires: pam >= 1.1.3-7, /etc/pam.d/system-auth audit-libs >= 1.0.6 @@ -202,6 +233,7 @@ %build %define _build_arg0__ CFLAGS="-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 $RPM_OPT_FLAGS" SUID_CFLAGS="-fpie" %define _build_arg1__ SUID_LDFLAGS="-pie -Wl,-z,relro -Wl,-z,now" DAEMON_CFLAGS="$SUID_CFLAGS" DAEMON_LDFLAGS="$SUID_LDFLAGS" +autoreconf unset LINGUAS || : # del support enable-raw https://github.com/torvalds/linux/commit/603e4922f1c81fc2ed3a87b4f91a8d3aafc7e093 @@ -443,6 +475,49 @@ %{_mandir}/man8/{swapoff.8*,swapon.8*,switch_root.8*,umount.8*,wdctl.8.gz,wipefs.8*,zramctl.8*} %changelog +* Mon Jun 5 2023 zhangyao <zhangyao108@huawei.com> - 2.37.2-19 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:sync community patches + addbackport-libfdisk-Fix-randomly-generated-GPT-UUID-s.patch + backport-write-correctly-handle-wide-characters.patch + backport-wall-convert-homebrew-buffering-to-open_memstream.patch + backport-wall-use-fputs_careful.patch + backport-hexdump-parse-handle-truncated-format-pattern.patch + backport-libblkid-copy-BLKID_PARTS_FORCE_GPT-to-whole-disk-pr.patch + backport-lscpu-fix-p-output-all-caches-delimiter.patch + backport-add-return-in-supam_conv-function.patch + backport-wrap-return-in-else-directive-to-avoid-dead-code.patch + backport-sulogin-ignore-none-existing-console-devices.patch + backport-sulogin-fix-KDGKBMODE-ifdef.patch + +* Fri May 12 2023 zhangyao <zhangyao108@huawei.com> - 2.37.2-18 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Sync community patches + addbackport-CVE-2022-0563.patch + backport-Fix-integer-overflow-for-alpha-like-linux.patch + backport-column-don-t-require-column-name-for-JSON.patch + backport-dmesg-fix-since-and-until.patch + backport-fflush-stdout-before-reading-from-stdin.patch + backport-flush-stdout-before-reading-stdin-and-fix-uninitialized-variable.patch + backport-last-don-t-assume-zero-terminate-strings.patch + backport-lib-allow-safe_getenv-to-work-for-non-root-users.patch + backport-lib-path-make-path-use-more-robust-coverity-scan.patch + backport-lib-strutils-improve-strtoul_or_err-for-negative-numbers.patch + backport-libblkid-don-t-mark-cache-as-probed-if-sys-not-available.patch + backport-libblkid-hfs-fix-make-sure-buffer-is-large-enough.patch + backport-libblkid-make-blkid_free_probe-more-robust.patch + backport-libmount-all-continue-although-proc-is-not-mounted.patch
View file
_service:tar_scm:backport-CVE-2022-0563.patch
Added
@@ -0,0 +1,169 @@ +From faa5a3a83ad0cb5e2c303edbfd8cd823c9d94c17 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Thu, 10 Feb 2022 12:03:17 +0100 +Subject: PATCH chsh, chfn: remove readline support CVE-2022-0563 + +The readline library uses INPUTRC= environment variable to get a path +to the library config file. When the library cannot parse the +specified file, it prints an error message containing data from the +file. + +Unfortunately, the library does not use secure_getenv() (or a similar +concept) to avoid vulnerabilities that could occur if set-user-ID or +set-group-ID programs. + +Reported-by: Rory Mackie <rory.mackie@trailofbits.com> +Signed-off-by: Karel Zak <kzak@redhat.com> + +--- + login-utils/Makemodule.am | 2 +- + login-utils/chfn.c | 16 ++++---------- + login-utils/chsh.c | 45 ++++----------------------------------- + 3 files changed, 9 insertions(+), 54 deletions(-) + +diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am +index 75c0a67..2d0547a 100644 +--- a/login-utils/Makemodule.am ++++ b/login-utils/Makemodule.am +@@ -109,7 +109,7 @@ chfn_chsh_sources = \ + login-utils/ch-common.c + chfn_chsh_cflags = $(SUID_CFLAGS) $(AM_CFLAGS) + chfn_chsh_ldflags = $(SUID_LDFLAGS) $(AM_LDFLAGS) +-chfn_chsh_ldadd = libcommon.la $(READLINE_LIBS) ++chfn_chsh_ldadd = libcommon.la + + if CHFN_CHSH_PASSWORD + chfn_chsh_ldadd += -lpam +diff --git a/login-utils/chfn.c b/login-utils/chfn.c +index ece5cdc..8f00d15 100644 +--- a/login-utils/chfn.c ++++ b/login-utils/chfn.c +@@ -56,11 +56,6 @@ + # include "auth.h" + #endif + +-#ifdef HAVE_LIBREADLINE +-# define _FUNCTION_DEF +-# include <readline/readline.h> +-#endif +- + struct finfo { + char *full_name; + char *office; +@@ -228,24 +223,21 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question, + { + int len; + char *buf = NULL; /* leave initialized to NULL or getline segfaults */ +-#ifndef HAVE_LIBREADLINE + size_t dummy = 0; +-#endif + + if (!def_val) + def_val = ""; ++ + while (true) { + printf("%s %s:", question, def_val); + __fpurge(stdin); +-#ifdef HAVE_LIBREADLINE +- rl_bind_key('\t', rl_insert); +- if ((buf = readline(" ")) == NULL) +-#else ++ + putchar(' '); + fflush(stdout); ++ + if (getline(&buf, &dummy, stdin) < 0) +-#endif + errx(EXIT_FAILURE, _("Aborted.")); ++ + /* remove white spaces from string end */ + ltrim_whitespace((unsigned char *) buf); + len = rtrim_whitespace((unsigned char *) buf); +diff --git a/login-utils/chsh.c b/login-utils/chsh.c +index 3b446be..b7e7017 100644 +--- a/login-utils/chsh.c ++++ b/login-utils/chsh.c +@@ -50,7 +50,6 @@ + # include "selinux-utils.h" + #endif + +- + #ifdef HAVE_LIBUSER + # include <libuser/user.h> + # include "libuser.h" +@@ -58,11 +57,6 @@ + # include "auth.h" + #endif + +-#ifdef HAVE_LIBREADLINE +-# define _FUNCTION_DEF +-# include <readline/readline.h> +-#endif +- + struct sinfo { + char *username; + char *shell; +@@ -121,33 +115,6 @@ static void print_shells(void) + endusershell(); + } + +-#ifdef HAVE_LIBREADLINE +-static char *shell_name_generator(const char *text, int state) +-{ +- static size_t len; +- char *s; +- +- if (!state) { +- setusershell(); +- len = strlen(text); +- } +- +- while ((s = getusershell())) { +- if (strncmp(s, text, len) == 0) +- return xstrdup(s); +- } +- return NULL; +-} +- +-static char **shell_name_completion(const char *text, +- int start __attribute__((__unused__)), +- int end __attribute__((__unused__))) +-{ +- rl_attempted_completion_over = 1; +- return rl_completion_matches(text, shell_name_generator); +-} +-#endif +- + /* + * parse_argv () -- + * parse the command line arguments, and fill in "pinfo" with any +@@ -198,22 +165,18 @@ static char *ask_new_shell(char *question, char *oldshell) + { + int len; + char *ans = NULL; +-#ifdef HAVE_LIBREADLINE +- rl_attempted_completion_function = shell_name_completion; +-#else + size_t dummy = 0; +-#endif ++ + if (!oldshell) + oldshell = ""; + printf("%s %s:", question, oldshell); +-#ifdef HAVE_LIBREADLINE +- if ((ans = readline(" ")) == NULL) +-#else ++ + putchar(' '); + fflush(stdout); ++ + if (getline(&ans, &dummy, stdin) < 0) +-#endif + return NULL; ++ + /* remove the newline at the end of ans. */ + ltrim_whitespace((unsigned char *) ans); + len = rtrim_whitespace((unsigned char *) ans); +-- +2.27.0 +
View file
_service:tar_scm:backport-Fix-integer-overflow-for-alpha-like-linux.patch
Added
@@ -0,0 +1,22 @@ +From db5aa5e5d8932c73f1b9f01fe567fa343898b825 Mon Sep 17 00:00:00 2001 +From: chanthmiao <chanthmiao@outlook.com> +Date: Sun, 5 Dec 2021 16:58:17 +0800 +Subject: PATCH Fix integer overflow for alpha like linux + +--- + sys-utils/swapon.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c +index ed6be244ec..76c5cac51b 100644 +--- a/sys-utils/swapon.c ++++ b/sys-utils/swapon.c +@@ -543,7 +543,7 @@ static int swapon_checks(const struct swapon_ctl *ctl, struct swap_device *dev) + + /* test for holes by LBT */ + if (S_ISREG(st.st_mode)) { +- if (st.st_blocks * 512 < st.st_size) { ++ if (st.st_blocks * 512L < st.st_size) { + warnx(_("%s: skipping - it appears to have holes."), + dev->path); + goto err;
View file
_service:tar_scm:backport-add-return-in-supam_conv-function.patch
Added
@@ -0,0 +1,28 @@ +From 1ade162b7773ffd3a1c83ad9f4ce529ac69d619c Mon Sep 17 00:00:00 2001 +From: Stefan Radu <stefan270101@gmail.com> +Date: Tue, 25 Apr 2023 15:00:36 +0300 +Subject: PATCH add return in supam_conv function + +Added return statement to ensure that all execution paths end with a +return statement. + +Signed-off-by: Stefan Radu <stefan270101@gmail.com> +--- + login-utils/su-common.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/login-utils/su-common.c b/login-utils/su-common.c +index 4b284995e..67c4fa271 100644 +--- a/login-utils/su-common.c ++++ b/login-utils/su-common.c +@@ -344,6 +344,7 @@ static int supam_conv( int num_msg, + #elif defined(HAVE_SECURITY_OPENPAM_H) + return openpam_ttyconv(num_msg, msg, resp, data); + #endif ++ return PAM_CONV_ERR; + } + + static void supam_cleanup(struct su_context *su, int retcode) +-- +2.27.0 +
View file
_service:tar_scm:backport-column-don-t-require-column-name-for-JSON.patch
Added
@@ -0,0 +1,103 @@ +From fd75b96898c455c35c045bc59a2a4a546e79f223 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Wed, 23 Mar 2022 12:50:07 +0100 +Subject: PATCH column: don't require column name for JSON + +The "--table-hide -" hides all unnamed columns, but this does not work +for JSON output. This patch fixes this issue. + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + text-utils/column.c | 37 +++++++++++++++++++++++++++++++++---- + 1 file changed, 33 insertions(+), 4 deletions(-) + +diff --git a/text-utils/column.c b/text-utils/column.c +index f9878e4..0fc4708 100644 +--- a/text-utils/column.c ++++ b/text-utils/column.c +@@ -96,6 +96,7 @@ struct column_control { + unsigned int greedy :1, + json :1, + header_repeat :1, ++ hide_unnamed :1, + keep_empty_lines :1, /* --keep-empty-lines */ + tab_noheadings :1; + }; +@@ -196,7 +197,10 @@ static char **split_or_error(const char *str, const char *errmsg) + if (!res) { + if (errno == ENOMEM) + err_oom(); +- errx(EXIT_FAILURE, "%s: '%s'", errmsg, str); ++ if (errmsg) ++ errx(EXIT_FAILURE, "%s: '%s'", errmsg, str); ++ else ++ return NULL; + } + return res; + } +@@ -275,6 +279,29 @@ static int column_set_flag(struct libscols_column *cl, int fl) + return scols_column_set_flags(cl, cur | fl); + } + ++static int has_unnamed(const char *list) ++{ ++ char **all, **one; ++ ++ if (!list) ++ return 0; ++ if (strcmp(list, "-") == 0) ++ return 1; ++ if (!strchr(list, ',')) ++ return 0; ++ ++ all = split_or_error(list, NULL); ++ if (all) { ++ STRV_FOREACH(one, all) { ++ if (strcmp(*one, "-") == 0) ++ return 1; ++ } ++ strv_free(all); ++ } ++ ++ return 0; ++} ++ + static void apply_columnflag_from_list(struct column_control *ctl, const char *list, + int flag, const char *errmsg) + { +@@ -300,7 +327,7 @@ static void apply_columnflag_from_list(struct column_control *ctl, const char *l + + /* apply to columns specified by name */ + STRV_FOREACH(one, all) { +- if (flag == SCOLS_FL_HIDDEN && strcmp(*one, "-") == 0) { ++ if (strcmp(*one, "-") == 0) { + unnamed = 1; + continue; + } +@@ -461,12 +488,13 @@ static int add_line_to_table(struct column_control *ctl, wchar_t *wcs0) + if (!wcdata) + break; + if (scols_table_get_ncols(ctl->tab) < n + 1) { +- if (scols_table_is_json(ctl->tab)) ++ if (scols_table_is_json(ctl->tab) && !ctl->hide_unnamed) + errx(EXIT_FAILURE, _("line %zu: for JSON the name of the " + "column %zu is required"), + scols_table_get_nlines(ctl->tab) + 1, + n + 1); +- scols_table_new_column(ctl->tab, NULL, 0, 0); ++ scols_table_new_column(ctl->tab, NULL, 0, ++ ctl->hide_unnamed ? SCOLS_FL_HIDDEN : 0); + } + if (!ln) { + ln = scols_table_new_line(ctl->tab, NULL); +@@ -774,6 +802,7 @@ int main(int argc, char **argv) + break; + case 'H': + ctl.tab_colhide = optarg; ++ ctl.hide_unnamed = has_unnamed(ctl.tab_colhide); + break; + case 'i': + ctl.tree_id = optarg; +-- +2.27.0 +
View file
_service:tar_scm:backport-dmesg-fix-since-and-until.patch
Added
@@ -0,0 +1,30 @@ +From c9667633f1f6b7a84116f2af067d1d15c72e6382 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Wed, 20 Apr 2022 14:42:32 +0200 +Subject: PATCH dmesg: fix --since and --until + +Now --since and --until requires any time field in the output (e.g. +--ctime,-T), it means "dmesg --since '1 day ago'" doesn't work, but +"dmesg -T --since '1 day ago'" works as expected. + +Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2076829 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + sys-utils/dmesg.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c +index 7cca88f2bb..017936255f 100644 +--- a/sys-utils/dmesg.c ++++ b/sys-utils/dmesg.c +@@ -1592,7 +1592,9 @@ int main(int argc, char *argv) + + if ((is_timefmt(&ctl, RELTIME) || + is_timefmt(&ctl, CTIME) || +- is_timefmt(&ctl, ISO8601))) { ++ is_timefmt(&ctl, ISO8601)) || ++ ctl.since || ++ ctl.until) { + if (dmesg_get_boot_time(&ctl.boot_time) != 0) + ctl.time_fmt = DMESG_TIMEFTM_NONE; + else
View file
_service:tar_scm:backport-fflush-stdout-before-reading-from-stdin.patch
Added
@@ -0,0 +1,28 @@ +From 0a08200bd5664d1849e477f7f776ab4d13bb8422 Mon Sep 17 00:00:00 2001 +From: Lorenzo Beretta <vc.net.loreb@gmail.com> +Date: Mon, 25 Oct 2021 15:28:02 +0200 +Subject: PATCH chsh: fflush stdout before reading from stdin + +Same problem as described in https://github.com/karelzak/util-linux/pull/1481 + +Signed-off-by: Lorenzo Beretta <vc.net.loreb@gmail.com> + +--- + login-utils/chsh.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/login-utils/chsh.c b/login-utils/chsh.c +index 3497120..3b446be 100644 +--- a/login-utils/chsh.c ++++ b/login-utils/chsh.c +@@ -210,6 +210,7 @@ static char *ask_new_shell(char *question, char *oldshell) + if ((ans = readline(" ")) == NULL) + #else + putchar(' '); ++ fflush(stdout); + if (getline(&ans, &dummy, stdin) < 0) + #endif + return NULL; +-- +2.27.0 +
View file
_service:tar_scm:backport-flush-stdout-before-reading-stdin-and-fix-uninitialized-variable.patch
Added
@@ -0,0 +1,38 @@ +From 05907d0d9e7c85f33e168feab1eb36b464425054 Mon Sep 17 00:00:00 2001 +From: Lorenzo Beretta <vc.net.loreb@gmail.com> +Date: Mon, 25 Oct 2021 14:06:00 +0200 +Subject: PATCH chfn: flush stdout before reading stdin and fix uninitialized + variable + +Same problem as described in https://github.com/karelzak/util-linux/pull/1481 + +Signed-off-by: Lorenzo Beretta <vc.net.loreb@gmail.com> + +--- + login-utils/chfn.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/login-utils/chfn.c b/login-utils/chfn.c +index 2508e14..ece5cdc 100644 +--- a/login-utils/chfn.c ++++ b/login-utils/chfn.c +@@ -227,7 +227,7 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question, + char *def_val) + { + int len; +- char *buf; ++ char *buf = NULL; /* leave initialized to NULL or getline segfaults */ + #ifndef HAVE_LIBREADLINE + size_t dummy = 0; + #endif +@@ -242,6 +242,7 @@ static char *ask_new_field(struct chfn_control *ctl, const char *question, + if ((buf = readline(" ")) == NULL) + #else + putchar(' '); ++ fflush(stdout); + if (getline(&buf, &dummy, stdin) < 0) + #endif + errx(EXIT_FAILURE, _("Aborted.")); +-- +2.27.0 +
View file
_service:tar_scm:backport-hexdump-parse-handle-truncated-format-pattern.patch
Added
@@ -0,0 +1,45 @@ +From e9aa06bad334b3a90ebe883dfc19b1e165a7c6cf Mon Sep 17 00:00:00 2001 +From: Ronan Pigott <ronan@rjp.ie> +Date: Thu, 23 Mar 2023 15:18:00 -0700 +Subject: PATCH hexdump-parse: handle truncated format pattern + +If the fmt being parsed by block_size is exactly '%', *++fmt is the +terminator and strchr will return a valid pointer to the terminator of +spec rather than NULL, the while condition will pass and subsequent +strchr will read past the end of fmt until a spec character is found +again + +ASAN aborts with the following error on the first buffer overread: + +AddressSanitizer: heap-buffer-overflow on address 0x602000000212 at pc 0x55bf1c4b2d78 bp 0x7ffe33c8cff0 sp 0x7ffe33c8cfe0 +READ of size 1 at 0x602000000212 thread T0 + #0 0x55bf1c4b2d77 in block_size ../text-utils/hexdump-parse.c:207 + #1 0x55bf1c4ad36f in main ../text-utils/hexdump.c:214 + #2 0x7f15f063c78f (/usr/lib/libc.so.6+0x2378f) + #3 0x7f15f063c849 in __libc_start_main (/usr/lib/libc.so.6+0x23849) + #4 0x55bf1c4ac6c4 in _start (../build/hexdump+0x86c4) +--- + text-utils/hexdump-parse.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/text-utils/hexdump-parse.c b/text-utils/hexdump-parse.c +index 0ceff8f21..272bb24e3 100644 +--- a/text-utils/hexdump-parse.c ++++ b/text-utils/hexdump-parse.c +@@ -204,10 +204,12 @@ int block_size(struct hexdump_fs *fs) + * skip any special chars -- save precision in + * case it's a %s format. + */ +- while (strchr(spec + 1, *++fmt)) ++ while (strchr(spec + 1, *++fmt) && *fmt != '\0') + ; + if (*fmt == '.' && isdigit(*++fmt)) + fmt = next_number(fmt, &prec); ++ if (*fmt == '\0') ++ badfmt(fu->fmt); + if (first_letter(fmt, "diouxX")) + bcnt += 4; + else if (first_letter(fmt, "efgEG")) +-- +2.27.0 +
View file
_service:tar_scm:backport-last-don-t-assume-zero-terminate-strings.patch
Added
@@ -0,0 +1,35 @@ +From 6cd0043221b31a344db8f5dcb82822a2519a2e74 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Mon, 7 Feb 2022 13:34:43 +0100 +Subject: PATCH last: don't assume zero terminate strings + +Detected by fuzzer and AddressSanitizer. The utmp strings do not +have to be zero terminated. + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + login-utils/last.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/login-utils/last.c b/login-utils/last.c +index c7aec4c116..84629278e5 100644 +--- a/login-utils/last.c ++++ b/login-utils/last.c +@@ -757,7 +757,7 @@ static void process_wtmp_file(const struct last_control *ctl, + else { + if (ut.ut_type != DEAD_PROCESS && + ut.ut_user0 && ut.ut_line0 && +- strcmp(ut.ut_user, "LOGIN") != 0) ++ strncmp(ut.ut_user, "LOGIN", 5) != 0) + ut.ut_type = USER_PROCESS; + /* + * Even worse, applications that write ghost +@@ -770,7 +770,7 @@ static void process_wtmp_file(const struct last_control *ctl, + /* + * Clock changes. + */ +- if (strcmp(ut.ut_user, "date") == 0) { ++ if (strncmp(ut.ut_user, "date", 4) == 0) { + if (ut.ut_line0 == '|') + ut.ut_type = OLD_TIME; + if (ut.ut_line0 == '{')
View file
_service:tar_scm:backport-lib-allow-safe_getenv-to-work-for-non-root-users.patch
Added
@@ -0,0 +1,30 @@ +From 16a2e0603f15c4a8f4517264930c7bdea5885bae Mon Sep 17 00:00:00 2001 +From: Mike Gilbert <floppym@gentoo.org> +Date: Tue, 26 Apr 2022 13:58:12 -0400 +Subject: PATCH lib: allow safe_getenv to work for non-root users + +This allows users to override settings like BLKID_FILE, as is done in +the e2fsprogs test suite. + +Bug: https://bugs.gentoo.org/839825 +Fixes: 035507c84b53bceb143d0923e65916cbf90979c7 +Signed-off-by: Mike Gilbert <floppym@gentoo.org> +--- + lib/env.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/lib/env.c b/lib/env.c +index a3dd335bfe..37125f4d5a 100644 +--- a/lib/env.c ++++ b/lib/env.c +@@ -161,9 +161,7 @@ void sanitize_env(void) + + char *safe_getenv(const char *arg) + { +- uid_t ruid = getuid(); +- +- if (ruid != 0 || (ruid != geteuid()) || (getgid() != getegid())) ++ if ((getuid() != geteuid()) || (getgid() != getegid())) + return NULL; + #ifdef HAVE_PRCTL + if (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0)
View file
_service:tar_scm:backport-lib-path-make-path-use-more-robust-coverity-scan.patch
Added
@@ -0,0 +1,57 @@ +From 41a27709e9028940578a5cdae17292e432fa23fa Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Mon, 29 Nov 2021 13:25:16 +0100 +Subject: PATCH lib/path: make path use more robust coverity scan + +*** CID 374365: Null pointer dereferences (FORWARD_NULL) +/lib/path.c: 364 in ul_path_stat() + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + lib/path.c | 5 ++++- + lib/sysfs.c | 2 +- + 2 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/lib/path.c b/lib/path.c +index 0d357966f3..8a2b882fe4 100644 +--- a/lib/path.c ++++ b/lib/path.c +@@ -344,7 +344,7 @@ int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *pa + int rc; + + if (!pc) { +- rc = stat(path, sb); ++ rc = path ? stat(path, sb) : -EINVAL; + DBG(CXT, ul_debug("stat '%s' no context, rc=%d", path, rc)); + } else { + int dir = ul_path_get_dirfd(pc); +@@ -359,6 +359,7 @@ int ul_path_stat(struct path_cxt *pc, struct stat *sb, int flags, const char *pa + rc = fstat(dir, sb); /* dir itself */ + + if (rc && errno == ENOENT ++ && path + && pc->redirect_on_enoent + && pc->redirect_on_enoent(pc, path, &dir) == 0) + rc = fstatat(dir, path, sb, 0); +@@ -372,6 +373,8 @@ int ul_path_open(struct path_cxt *pc, int flags, const char *path) + { + int fd; + ++ if (!path) ++ return -EINVAL; + if (!pc) { + fd = open(path, flags); + DBG(CXT, ul_debug("opening '%s' no context", path)); +diff --git a/lib/sysfs.c b/lib/sysfs.c +index d8206be7ab..84af4fe3cb 100644 +--- a/lib/sysfs.c ++++ b/lib/sysfs.c +@@ -165,7 +165,7 @@ static int sysfs_blkdev_enoent_redirect(struct path_cxt *pc, const char *path, i + { + struct sysfs_blkdev *blk = ul_path_get_dialect(pc); + +- if (blk && blk->parent && strncmp(path, "queue/", 6) == 0) { ++ if (blk && blk->parent && path && strncmp(path, "queue/", 6) == 0) { + *dirfd = ul_path_get_dirfd(blk->parent); + if (*dirfd >= 0) { + DBG(CXT, ul_debugobj(pc, "%s redirected to parent", path));
View file
_service:tar_scm:backport-lib-strutils-improve-strtoul_or_err-for-negative-numbers.patch
Added
@@ -0,0 +1,90 @@ +From 3b888573661d43ea069e98a083bd10e33a2ece69 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Tue, 19 Apr 2022 11:38:57 +0200 +Subject: PATCH lib/strutils: improve strtoul_or_err() for negative numbers + +Let's use the same code for strtoul_or_err() and strtol_or_err() as we +already use for strtoxXX_or_err() functions. It resolves issue with +negative numbers. + +This problem has been discovered by "./eject -x -1 -v" where -x is +based on strtoul_or_err(), but accepts negative number (-1). + +Reported-by: Enze Li <lienze@kylinos.cn> +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + include/strutils.h | 4 ++-- + lib/strutils.c | 42 ------------------------------------------ + 2 files changed, 2 insertions(+), 44 deletions(-) + +diff --git a/include/strutils.h b/include/strutils.h +index a84d295..2849ef3 100644 +--- a/include/strutils.h ++++ b/include/strutils.h +@@ -42,8 +42,8 @@ extern uint64_t str2unum_or_err(const char *str, int base, const char *errmesg, + extern double strtod_or_err(const char *str, const char *errmesg); + extern long double strtold_or_err(const char *str, const char *errmesg); + +-extern long strtol_or_err(const char *str, const char *errmesg); +-extern unsigned long strtoul_or_err(const char *str, const char *errmesg); ++#define strtol_or_err(_s, _e) (long) str2num_or_err(_s, 10, _e, LONG_MIN, LONG_MAX) ++#define strtoul_or_err(_s, _e) (unsigned long) str2unum_or_err(_s, 10, _e, ULONG_MAX) + + extern void strtotimeval_or_err(const char *str, struct timeval *tv, + const char *errmesg); +diff --git a/lib/strutils.c b/lib/strutils.c +index 096aaf5..4117e03 100644 +--- a/lib/strutils.c ++++ b/lib/strutils.c +@@ -471,48 +471,6 @@ err: + errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); + } + +-long strtol_or_err(const char *str, const char *errmesg) +-{ +- long num; +- char *end = NULL; +- +- errno = 0; +- if (str == NULL || *str == '\0') +- goto err; +- num = strtol(str, &end, 10); +- +- if (errno || str == end || (end && *end)) +- goto err; +- +- return num; +-err: +- if (errno == ERANGE) +- err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); +- +- errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); +-} +- +-unsigned long strtoul_or_err(const char *str, const char *errmesg) +-{ +- unsigned long num; +- char *end = NULL; +- +- errno = 0; +- if (str == NULL || *str == '\0') +- goto err; +- num = strtoul(str, &end, 10); +- +- if (errno || str == end || (end && *end)) +- goto err; +- +- return num; +-err: +- if (errno == ERANGE) +- err(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); +- +- errx(STRTOXX_EXIT_CODE, "%s: '%s'", errmesg, str); +-} +- + uintmax_t strtosize_or_err(const char *str, const char *errmesg) + { + uintmax_t num; +-- +2.27.0 +
View file
_service:tar_scm:backport-libblkid-copy-BLKID_PARTS_FORCE_GPT-to-whole-disk-pr.patch
Added
@@ -0,0 +1,70 @@ +From 22769acf56daf6683d635fe92e06ceb52e0433ff Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Tue, 4 Apr 2023 11:04:51 +0200 +Subject: PATCH libblkid: copy BLKID_PARTS_FORCE_GPT to whole-disk prober + +Addresses: https://github.com/util-linux/util-linux/discussions/2146 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libblkid/src/blkidP.h | 3 +++ + libblkid/src/partitions/partitions.c | 5 +++++ + libblkid/src/probe.c | 6 ++++++ + 3 files changed, 14 insertions(+) + +diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h +index 5d2a02055..007cc357b 100644 +--- a/libblkid/src/blkidP.h ++++ b/libblkid/src/blkidP.h +@@ -544,6 +544,9 @@ extern int blkid_probe_get_hint(blkid_probe pr, const char *name, uint64_t *valu + __attribute__((nonnull(1,2))) + __attribute__((warn_unused_result)); + ++extern int blkid_probe_get_partitions_flags(blkid_probe pr) ++ __attribute__((nonnull)); ++ + /* filter bitmap macros */ + #define blkid_bmp_wordsize (8 * sizeof(unsigned long)) + #define blkid_bmp_idx_bit(item) (1UL << ((item) % blkid_bmp_wordsize)) +diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c +index ae63a38cc..1c344fd30 100644 +--- a/libblkid/src/partitions/partitions.c ++++ b/libblkid/src/partitions/partitions.c +@@ -234,6 +234,11 @@ int blkid_probe_set_partitions_flags(blkid_probe pr, int flags) + return 0; + } + ++int blkid_probe_get_partitions_flags(blkid_probe pr) ++{ ++ return pr->chainsBLKID_CHAIN_PARTS.flags; ++} ++ + /** + * blkid_probe_reset_partitions_filter: + * @pr: prober +diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c +index 35de30334..b4299493f 100644 +--- a/libblkid/src/probe.c ++++ b/libblkid/src/probe.c +@@ -1930,6 +1930,7 @@ blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr) + if (!pr->disk_probe) { + /* Open a new disk prober */ + char *disk_path = blkid_devno_to_devname(disk); ++ int flags; + + if (!disk_path) + return NULL; +@@ -1942,6 +1943,11 @@ blkid_probe blkid_probe_get_wholedisk_probe(blkid_probe pr) + + if (!pr->disk_probe) + return NULL; /* ENOMEM? */ ++ ++ flags = blkid_probe_get_partitions_flags(pr); ++ if (flags & BLKID_PARTS_FORCE_GPT) ++ blkid_probe_set_partitions_flags(pr->disk_probe, ++ BLKID_PARTS_FORCE_GPT); + } + + return pr->disk_probe; +-- +2.27.0 +
View file
_service:tar_scm:backport-libblkid-don-t-mark-cache-as-probed-if-sys-not-available.patch
Added
@@ -0,0 +1,140 @@ +From 84d38ae3eca523ef990cb848563cc63de25266e6 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Fri, 19 Nov 2021 14:19:03 +0100 +Subject: PATCH libblkid: don't mark cache as "probed" if /sys not available + +For "mount --all" we need to read the cache more than once in a short +time. The library checks the delay between probes, and if the delay is +too short, it does not read devices. This is a problem on boot when there +are no /sys, and the cache is empty. In this case, we need to check +for /sys until it's available constantly. + +https://github.com/util-linux/util-linux/issues/1492 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libblkid/src/devname.c | 26 +++++++++++++++++--------- + libblkid/src/resolve.c | 2 +- + libblkid/src/tag.c | 8 +++++--- + 3 files changed, 23 insertions(+), 13 deletions(-) + +diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c +index c541d30..80574f3 100644 +--- a/libblkid/src/devname.c ++++ b/libblkid/src/devname.c +@@ -456,6 +456,8 @@ sysfs_probe_all(blkid_cache cache, int only_if_new, int only_removable) + if (!sysfs) + return -BLKID_ERR_SYSFS; + ++ DBG(DEVNAME, ul_debug(" probe /sys/block")); ++ + /* scan /sys/block */ + while ((dev = xreaddir(sysfs))) { + DIR *dir = NULL; +@@ -560,14 +562,18 @@ sysfs_probe_all(blkid_cache cache, int only_if_new, int only_removable) + /* + * Read the device data for all available block devices in the system. + */ +-static int probe_all(blkid_cache cache, int only_if_new) ++static int probe_all(blkid_cache cache, int only_if_new, int update_interval) + { ++ int rc; ++ + if (!cache) + return -BLKID_ERR_PARAM; + + if (cache->bic_flags & BLKID_BIC_FL_PROBED && +- time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL) ++ time(NULL) - cache->bic_time < BLKID_PROBE_INTERVAL) { ++ DBG(PROBE, ul_debug("don't re-probe delay < %d", BLKID_PROBE_INTERVAL)); + return 0; ++ } + + blkid_read_cache(cache); + +@@ -577,7 +583,13 @@ static int probe_all(blkid_cache cache, int only_if_new) + #endif + ubi_probe_all(cache, only_if_new); + +- sysfs_probe_all(cache, only_if_new, 0); ++ rc = sysfs_probe_all(cache, only_if_new, 0); ++ ++ /* Don't mark the change as "probed" if /sys not avalable */ ++ if (update_interval && rc == 0) { ++ cache->bic_time = time(NULL); ++ cache->bic_flags |= BLKID_BIC_FL_PROBED; ++ } + + blkid_flush_cache(cache); + return 0; +@@ -596,11 +608,7 @@ int blkid_probe_all(blkid_cache cache) + int ret; + + DBG(PROBE, ul_debug("Begin blkid_probe_all()")); +- ret = probe_all(cache, 0); +- if (ret == 0) { +- cache->bic_time = time(NULL); +- cache->bic_flags |= BLKID_BIC_FL_PROBED; +- } ++ ret = probe_all(cache, 0, 1); + DBG(PROBE, ul_debug("End blkid_probe_all() rc=%d", ret)); + return ret; + } +@@ -618,7 +626,7 @@ int blkid_probe_all_new(blkid_cache cache) + int ret; + + DBG(PROBE, ul_debug("Begin blkid_probe_all_new()")); +- ret = probe_all(cache, 1); ++ ret = probe_all(cache, 1, 0); + DBG(PROBE, ul_debug("End blkid_probe_all_new() rc=%d", ret)); + return ret; + } +diff --git a/libblkid/src/resolve.c b/libblkid/src/resolve.c +index 641b022..16653fa 100644 +--- a/libblkid/src/resolve.c ++++ b/libblkid/src/resolve.c +@@ -32,7 +32,7 @@ char *blkid_get_tag_value(blkid_cache cache, const char *tagname, + blkid_cache c = cache; + char *ret = NULL; + +- DBG(TAG, ul_debug("looking for %s on %s", tagname, devname)); ++ DBG(TAG, ul_debug("looking for tag %s on %s device", tagname, devname)); + + if (!devname) + return NULL; +diff --git a/libblkid/src/tag.c b/libblkid/src/tag.c +index 390a648..1783365 100644 +--- a/libblkid/src/tag.c ++++ b/libblkid/src/tag.c +@@ -326,14 +326,14 @@ blkid_dev blkid_find_dev_with_tag(blkid_cache cache, + blkid_dev dev; + int pri; + struct list_head *p; +- int probe_new = 0; ++ int probe_new = 0, probe_all = 0; + + if (!cache || !type || !value) + return NULL; + + blkid_read_cache(cache); + +- DBG(TAG, ul_debug("looking for %s=%s in cache", type, value)); ++ DBG(TAG, ul_debug("looking for tag %s=%s in cache", type, value)); + + try_again: + pri = -1; +@@ -366,9 +366,11 @@ try_again: + goto try_again; + } + +- if (!dev && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) { ++ if (!dev && !probe_all ++ && !(cache->bic_flags & BLKID_BIC_FL_PROBED)) { + if (blkid_probe_all(cache) < 0) + return NULL; ++ probe_all++; + goto try_again; + } + return dev; +-- +2.27.0 +
View file
_service:tar_scm:backport-libblkid-hfs-fix-make-sure-buffer-is-large-enough.patch
Added
@@ -0,0 +1,24 @@ +From 7ebfe9b411c12223a2500ca62d6be37c48e2d83d Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Thu, 2 Jun 2022 16:02:54 +0200 +Subject: PATCH libblkid: (hfs) fix make sure buffer is large enough + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libblkid/src/superblocks/ntfs.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/libblkid/src/superblocks/ntfs.c b/libblkid/src/superblocks/ntfs.c +index 9f1927cf74..b5799c3e33 100644 +--- a/libblkid/src/superblocks/ntfs.c ++++ b/libblkid/src/superblocks/ntfs.c +@@ -158,6 +158,9 @@ static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_ + sectors_per_cluster, nr_clusters, + off)); + ++ if (mft_record_size < 4) ++ return 1; ++ + buf_mft = blkid_probe_get_buffer(pr, off, mft_record_size); + if (!buf_mft) + return errno ? -errno : 1;
View file
_service:tar_scm:backport-libblkid-make-blkid_free_probe-more-robust.patch
Added
@@ -0,0 +1,22 @@ +From 5caa4117b40ea9babf4aee6e8786fb70507ee1b8 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Thu, 17 Mar 2022 12:41:48 +0100 +Subject: PATCH libblkid: make blkid_free_probe() more robust + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libblkid/src/probe.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c +index 2e0e08ac1d..31706240fc 100644 +--- a/libblkid/src/probe.c ++++ b/libblkid/src/probe.c +@@ -251,6 +251,7 @@ void blkid_free_probe(blkid_probe pr) + if (ch->driver->free_data) + ch->driver->free_data(pr, ch->data); + free(ch->fltr); ++ ch->fltr = NULL; + } + + if ((pr->flags & BLKID_FL_PRIVATE_FD) && pr->fd >= 0)
View file
_service:tar_scm:backport-libfdisk-Fix-randomly-generated-GPT-UUID-s.patch
Added
@@ -0,0 +1,62 @@ +From dd405ea745e451fb0cf32e9dedd94d69850fe333 Mon Sep 17 00:00:00 2001 +From: Toomas Losin <tlo@lenrek.net> +Date: Sun, 5 Mar 2023 15:57:55 -0800 +Subject: PATCH libfdisk: Fix randomly generated GPT UUID's + +Fdisk commands that create random GPT UUID's result in values that are +not UEFI-compliant being written to disk: The "g" command creates a +new GPT whose in-core DiskGUID value is entirely big-endian; the "n" +command creates a GPT partition whose in-core UniquePartitionGUID +value is entirely big-endian. Those big-endian values are written to +disk by the "w" command rather than the mix of little- and big-endian +spec'd by UEFI. + +This was caused by a libfdisk patch in 2017 that was addressing +warnings about "taking address of packed member". Reading gpt.c finds +two instances of dead code which suggests that perhaps there was some +confusion between a struct and a pointer to a struct. The intent must +have been to convert the randomly generated big-endian RFC 4122 UUID +values to UEFI's mixed-endian but the confusion(?) resulted in some +dead code and non-conversion of the UUID's. + +This patch corrects the breakage while still avoiding "taking address +of packed member" warnings. The "w" command will once again write +UEFI-compliant values to disk. + +Fixes: 92e486f80ef8 ("libfdisk: fix guid usage of packed struct gpt_entry") +Signed-off-by: Toomas Losin <tlo@lenrek.net> +--- + libfdisk/src/gpt.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c +index d7b3e1c70..c3c0347cb 100644 +--- a/libfdisk/src/gpt.c ++++ b/libfdisk/src/gpt.c +@@ -878,9 +878,9 @@ static int gpt_mknew_header(struct fdisk_context *cxt, + if (!has_id) { + struct gpt_guid guid; + +- uuid_generate_random((unsigned char *) &header->disk_guid); +- guid = header->disk_guid; ++ uuid_generate_random((unsigned char *) &guid); + swap_efi_guid(&guid); ++ header->disk_guid = guid; + } + return 0; + } +@@ -2621,9 +2621,9 @@ static int gpt_add_partition( + */ + struct gpt_guid guid; + +- uuid_generate_random((unsigned char *) &e->partition_guid); +- guid = e->partition_guid; ++ uuid_generate_random((unsigned char *) &guid); + swap_efi_guid(&guid); ++ e->partition_guid = guid; + } + + if (pa && pa->name && *pa->name) +-- +2.27.0 +
View file
_service:tar_scm:backport-libmount-all-continue-although-proc-is-not-mounted.patch
Added
@@ -0,0 +1,113 @@ +From b8f2fce2a20944cd8b1a7e91dfa04f9725ec3eb8 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Thu, 18 Nov 2021 11:47:08 +0100 +Subject: PATCH libmount: (--all) continue although /proc is not mounted + +Now 'mount --all' ends with error if /proc is not mounted and there is +some other entry before /proc in fstab. This commit improves this +situation and ignores all mount table related errors if the table is +empty. + +This is important for situation when there is for example "/" as the +first line in fstab. + +Addresses: https://github.com/util-linux/util-linux/issues/1492 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + libmount/src/context.c | 25 +++++++++++++++++-------- + libmount/src/context_mount.c | 9 ++++++++- + sys-utils/mount.8.adoc | 2 ++ + 3 files changed, 27 insertions(+), 9 deletions(-) + +diff --git a/libmount/src/context.c b/libmount/src/context.c +index 3b32224..bd215c0 100644 +--- a/libmount/src/context.c ++++ b/libmount/src/context.c +@@ -1298,6 +1298,16 @@ int mnt_context_get_mtab(struct libmnt_context *cxt, struct libmnt_table **tb) + cxt->table_fltrcb_data); + + mnt_table_set_cache(cxt->mtab, mnt_context_get_cache(cxt)); ++ } ++ ++ /* Read the table; it's empty, because this first mnt_context_get_mtab() ++ * call, or because /proc was not accessible in previous calls */ ++ if (mnt_table_is_empty(cxt->mtab)) { ++ if (!ns_old) { ++ ns_old = mnt_context_switch_target_ns(cxt); ++ if (!ns_old) ++ return -MNT_ERR_NAMESPACE; ++ } + + /* + * Note that mtab_path is NULL if mtab is useless or unsupported +@@ -2874,7 +2884,7 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt, + struct libmnt_fs *fs, int *mounted) + { + struct libmnt_table *mtab, *orig; +- int rc; ++ int rc = 0; + struct libmnt_ns *ns_old; + + if (!cxt || !fs || !mounted) +@@ -2893,18 +2903,17 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt, + cxt->mtab = NULL; + } + *mounted = 0; +- return 0; /* /proc not mounted */ +- } ++ rc = 0; /* /proc not mounted */ + +- if (rc) +- return rc; +- +- *mounted = __mnt_table_is_fs_mounted(mtab, fs, ++ } else if (rc == 0) { ++ *mounted = __mnt_table_is_fs_mounted(mtab, fs, + mnt_context_get_target_prefix(cxt)); + ++ } ++ + if (!mnt_context_switch_ns(cxt, ns_old)) + return -MNT_ERR_NAMESPACE; +- return 0; ++ return rc; + } + + static int mnt_context_add_child(struct libmnt_context *cxt, pid_t pid) +diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c +index 55ebf79..f9bedd2 100644 +--- a/libmount/src/context_mount.c ++++ b/libmount/src/context_mount.c +@@ -1397,8 +1397,15 @@ int mnt_context_next_mount(struct libmnt_context *cxt, + + /* ignore already mounted filesystems */ + rc = mnt_context_is_fs_mounted(cxt, *fs, &mounted); +- if (rc) ++ if (rc) { ++ if (mnt_table_is_empty(cxt->mtab)) { ++ DBG(CXT, ul_debugobj(cxt, "next-mount: no mount table rc=%d, ignore", rc)); ++ rc = 0; ++ if (ignored) ++ *ignored = 1; ++ } + return rc; ++ } + if (mounted) { + if (ignored) + *ignored = 2; +diff --git a/sys-utils/mount.8.adoc b/sys-utils/mount.8.adoc +index 6e72d48..e8f0c36 100644 +--- a/sys-utils/mount.8.adoc ++++ b/sys-utils/mount.8.adoc +@@ -301,6 +301,8 @@ Command-line options available for the *mount* command are: + *-a*, *--all*:: + Mount all filesystems (of the given types) mentioned in _fstab_ (except for those whose line contains the *noauto* keyword). The filesystems are mounted following their order in _fstab_. The *mount* command compares filesystem source, target (and fs root for bind mount or btrfs) to detect already mounted filesystems. The kernel table with already mounted filesystems is cached during *mount --all*. This means that all duplicated _fstab_ entries will be mounted. + + ++The correct functionality depends on /proc (to detect already mounted filesystems) and on /sys (to evaluate filesystem tags like UUID= or LABEL=). It's strongly recommended to mount /proc and /sys filesystems before *mount -a* is executed, or keep /proc and /sys at the beginning of fstab. +++ + The option *--all* is possible to use for remount operation too. In this case all filters (*-t* and *-O*) are applied to the table of already mounted filesystems. + + + Since version 2.35 is possible to use the command line option *-o* to alter mount options from _fstab_ (see also *--options-mode*). +-- +2.27.0 +
View file
_service:tar_scm:backport-loopdev-set-block_size-when-using-LOOP_CONFIGURE.patch
Added
@@ -0,0 +1,46 @@ +From 854abba0dd9b45b4f40a9c934694b3f14052eceb Mon Sep 17 00:00:00 2001 +From: Hideki EIRAKU <hdk@igel.co.jp> +Date: Wed, 25 May 2022 12:23:16 +0900 +Subject: PATCH loopdev: set block_size when using LOOP_CONFIGURE + +LOOP_CONFIGURE ioctl was introduced by commit +d5fd456c88aba4fcf77d35fe38024a8d5c814686. Since the previous +implementation set partscan flag but did not set block_size with the +LOOP_CONFIGURE ioctl, an issue fixed by commit +422f0e9f206a145c59a71333dad20d38cbbfc0c4 was reappeared. Setting +block_size in the LOOP_CONFIGURE ioctl parameter fixes the issue. + +Signed-off-by: Hideki EIRAKU <hdk@igel.co.jp> +--- + lib/loopdev.c | 8 +++----- + 1 file changed, 3 insertions(+), 5 deletions(-) + +diff --git a/lib/loopdev.c b/lib/loopdev.c +index d9ea1d4..0afe300 100644 +--- a/lib/loopdev.c ++++ b/lib/loopdev.c +@@ -1357,6 +1357,9 @@ int loopcxt_setup_device(struct loopdev_cxt *lc) + * -- since Linux v5.8-rc1, commit 3448914e8cc550ba792d4ccc74471d1ca4293aae + */ + lc->config.fd = file_fd; ++ if (lc->blocksize > 0) ++ lc->config.block_size = lc->blocksize; ++ + if (ioctl(dev_fd, LOOP_CONFIGURE, &lc->config) < 0) { + rc = -errno; + errsv = errno; +@@ -1366,11 +1369,6 @@ int loopcxt_setup_device(struct loopdev_cxt *lc) + } + fallback = 1; + } else { +- if (lc->blocksize > 0 +- && (rc = loopcxt_ioctl_blocksize(lc, lc->blocksize)) < 0) { +- errsv = -rc; +- goto err; +- } + DBG(SETUP, ul_debugobj(lc, "LOOP_CONFIGURE: OK")); + } + +-- +2.27.0 +
View file
_service:tar_scm:backport-lscpu-fix-p-output-all-caches-delimiter.patch
Added
@@ -0,0 +1,34 @@ +From 0da947eb78e3f37f63f33157562c221805ec7fe9 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Mon, 17 Apr 2023 10:50:08 +0200 +Subject: PATCH lscpu: fix -p --output-all caches delimiter + +Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2187099 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + sys-utils/lscpu.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c +index 3f28db61c..8333dcbea 100644 +--- a/sys-utils/lscpu.c ++++ b/sys-utils/lscpu.c +@@ -1444,6 +1444,7 @@ int main(int argc, char *argv) + print_cpus_readable(cxt, columns, ncolumns); + break; + case LSCPU_OUTPUT_PARSABLE: ++ cxt->show_compatible = 1; + if (!ncolumns) { + columnsncolumns++ = COL_CPU_CPU; + columnsncolumns++ = COL_CPU_CORE; +@@ -1453,7 +1454,6 @@ int main(int argc, char *argv) + columnsncolumns++ = COL_CPU_SOCKET; + columnsncolumns++ = COL_CPU_NODE; + columnsncolumns++ = COL_CPU_CACHE; +- cxt->show_compatible = 1; + } + if (outarg && string_add_to_idarray(outarg, columns, + ARRAY_SIZE(columns), +-- +2.27.0 +
View file
_service:tar_scm:backport-lslocks-fix-maj-min-scanf.patch
Added
@@ -0,0 +1,28 @@ +From 9b725af7028163bd29d39da3b910dffc903107ee Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Mon, 28 Mar 2022 11:39:27 +0200 +Subject: PATCH lslocks: fix maj:min scanf + +Fixes: https://github.com/util-linux/util-linux/issues/1633 +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + misc-utils/lslocks.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c +index 941ef7f..6427318 100644 +--- a/misc-utils/lslocks.c ++++ b/misc-utils/lslocks.c +@@ -224,7 +224,8 @@ static ino_t get_dev_inode(char *str, dev_t *dev) + unsigned int maj = 0, min = 0; + ino_t inum = 0; + +- sscanf(str, "%02x:%02x:%ju", &maj, &min, &inum); ++ if (sscanf(str, "%x:%x:%ju", &maj, &min, &inum) != 3) ++ errx(EXIT_FAILURE, _("failed to parse '%s'"), str); + + *dev = (dev_t) makedev(maj, min); + return inum; +-- +2.27.0 +
View file
_service:tar_scm:backport-lslogins-fix-free-invalid-pointer.patch
Added
@@ -0,0 +1,33 @@ +From 890d4d3f236e2d28db35ea9bc9dc3e5e35db975c Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Tue, 7 Jun 2022 09:46:54 +0200 +Subject: PATCH lslogins: fix free(): invalid pointer + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + login-utils/lslogins.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c +index 3646883e0e..3cb30b74e2 100644 +--- a/login-utils/lslogins.c ++++ b/login-utils/lslogins.c +@@ -490,7 +490,7 @@ static int parse_utmpx(const char *path, size_t *nrecords, struct utmpx **record + + /* optimize allocation according to file size, the realloc() below is + * just fallback only */ +- if (stat(path, &st) == 0 && (size_t) st.st_size > sizeof(struct utmpx)) { ++ if (stat(path, &st) == 0 && (size_t) st.st_size >= sizeof(struct utmpx)) { + imax = st.st_size / sizeof(struct utmpx); + ary = xmalloc(imax * sizeof(struct utmpx)); + } +@@ -1013,6 +1013,9 @@ static void free_ctl(struct lslogins_control *ctl) + { + size_t n = 0; + ++ if (!ctl) ++ return; ++ + free(ctl->wtmp); + free(ctl->btmp); +
View file
_service:tar_scm:backport-script-fix-passing-args-to-execlp.patch
Added
@@ -0,0 +1,34 @@ +From 521eb0571eef9352c99d8e401fc8d73d626014cf Mon Sep 17 00:00:00 2001 +From: Jakub Wilk <jwilk@jwilk.net> +Date: Tue, 1 Mar 2022 17:15:45 +0100 +Subject: PATCH script: fix passing args to execlp() + +Fixes: + + $ SHELL=bash script -q -c 'echo Hello world' + -c: echo Hello world: No such file or directory + +Signed-off-by: Jakub Wilk <jwilk@jwilk.net> +--- + term-utils/script.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/term-utils/script.c b/term-utils/script.c +index c8b55c8..89bd0ed 100644 +--- a/term-utils/script.c ++++ b/term-utils/script.c +@@ -975,9 +975,9 @@ int main(int argc, char **argv) + execl(shell, shname, "-i", (char *)NULL); + } else { + if (command) +- execlp(shname, "-c", command, (char *)NULL); ++ execlp(shname, shname, "-c", command, (char *)NULL); + else +- execlp(shname, "-i", (char *)NULL); ++ execlp(shname, shname, "-i", (char *)NULL); + } + + err(EXIT_FAILURE, "failed to execute %s", shell); +-- +2.27.0 +
View file
_service:tar_scm:backport-scriptlive-fix-argv-0-for-execlp.patch
Added
@@ -0,0 +1,26 @@ +From 65856a0deb7200b78f858ba7dc66077f3469e924 Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Wed, 2 Mar 2022 10:00:46 +0100 +Subject: PATCH scriptlive: fix argv0 for execlp() + +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + term-utils/scriptlive.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/term-utils/scriptlive.c b/term-utils/scriptlive.c +index 37f092c1ff..d81712d36f 100644 +--- a/term-utils/scriptlive.c ++++ b/term-utils/scriptlive.c +@@ -321,9 +321,9 @@ main(int argc, char *argv) + execl(shell, shname, "-i", (char *)NULL); + } else { + if (command) +- execlp(shname, "-c", command, (char *)NULL); ++ execlp(shname, shname, "-c", command, (char *)NULL); + else +- execlp(shname, "-i", (char *)NULL); ++ execlp(shname, shname, "-i", (char *)NULL); + } + err(EXIT_FAILURE, "failed to execute %s", shell); + break;
View file
_service:tar_scm:backport-sulogin-fix-KDGKBMODE-ifdef.patch
Added
@@ -0,0 +1,59 @@ +From 8efec058d7a513c18f5e5666e79006ded786221a Mon Sep 17 00:00:00 2001 +From: Karel Zak <kzak@redhat.com> +Date: Tue, 2 May 2023 11:36:49 +0200 +Subject: PATCH sulogin: fix KDGKBMODE ifdef + +* remove ifdef-else for KDGKBMODE + +* always call KDGKBMODE for virtual console to get K_UNICODE status + +* use KDGKBMODE as a fallback to detect serial line + +Fixes: https://github.com/util-linux/util-linux/issues/2185 +Suggested-by: Marcos Mello +Signed-off-by: Karel Zak <kzak@redhat.com> +--- + login-utils/sulogin.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c +index 851d92d..3507272 100644 +--- a/login-utils/sulogin.c ++++ b/login-utils/sulogin.c +@@ -108,7 +108,7 @@ static void tcinit(struct console *con) + struct termios *tio = &con->tio; + const int fd = con->fd; + #if defined(TIOCGSERIAL) +- struct serial_struct serinfo; ++ struct serial_struct serinfo = { .flags = 0 }; + #endif + #ifdef USE_PLYMOUTH_SUPPORT + struct termios lock; +@@ -132,18 +132,18 @@ static void tcinit(struct console *con) + errno = 0; + #endif + +-#if defined(TIOCGSERIAL) ++#ifdef TIOCGSERIAL + if (ioctl(fd, TIOCGSERIAL, &serinfo) >= 0) + con->flags |= CON_SERIAL; + errno = 0; +-#else +-# if defined(KDGKBMODE) +- if (ioctl(fd, KDGKBMODE, &mode) < 0) ++#endif ++ ++#ifdef KDGKBMODE ++ if (!(con->flags & CON_SERIAL) ++ && ioctl(fd, KDGKBMODE, &mode) < 0) + con->flags |= CON_SERIAL; + errno = 0; +-# endif + #endif +- + if (tcgetattr(fd, tio) < 0) { + int saveno = errno; + #if defined(KDGKBMODE) || defined(TIOCGSERIAL) +-- +2.33.0 +
View file
_service:tar_scm:backport-sulogin-ignore-none-existing-console-devices.patch
Added
@@ -0,0 +1,227 @@ +From 0d092db5c40b94e1ea9529f3f1c384a74eca19f8 Mon Sep 17 00:00:00 2001 +From: Werner Fink <werner@suse.de> +Date: Mon, 17 May 2021 17:20:32 +0200 +Subject: PATCH sulogin: ignore none-existing console devices + +and also none-functional console devices. Redirect the error +messages to the appropiate console device. + +Signed-off-by: Werner Fink <werner@suse.de> +--- + login-utils/sulogin-consoles.h | 1 + + login-utils/sulogin.c | 92 ++++++++++++++++++++++++++++------ + 2 files changed, 79 insertions(+), 14 deletions(-) + +diff --git a/login-utils/sulogin-consoles.h b/login-utils/sulogin-consoles.h +index 0bfbc38..12032c9 100644 +--- a/login-utils/sulogin-consoles.h ++++ b/login-utils/sulogin-consoles.h +@@ -40,6 +40,7 @@ struct console { + int fd, id; + #define CON_SERIAL 0x0001 + #define CON_NOTTY 0x0002 ++#define CON_EIO 0x0004 + pid_t pid; + struct chardata cp; + struct termios tio; +diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c +index 4d48943..df27896 100644 +--- a/login-utils/sulogin.c ++++ b/login-utils/sulogin.c +@@ -52,6 +52,7 @@ + #ifdef __linux__ + # include <sys/kd.h> + # include <sys/param.h> ++# include <linux/serial.h> + #endif + + #include "c.h" +@@ -106,6 +107,9 @@ static void tcinit(struct console *con) + int flags = 0, mode = 0; + struct termios *tio = &con->tio; + const int fd = con->fd; ++#if defined(TIOCGSERIAL) ++ struct serial_struct serinfo; ++#endif + #ifdef USE_PLYMOUTH_SUPPORT + struct termios lock; + int i = (plymouth_command(MAGIC_PING)) ? PLYMOUTH_TERMIOS_FLAGS_DELAY : 0; +@@ -125,27 +129,72 @@ static void tcinit(struct console *con) + } + memset(&lock, 0, sizeof(struct termios)); + ioctl(fd, TIOCSLCKTRMIOS, &lock); ++ errno = 0; + #endif ++ ++#if defined(TIOCGSERIAL) ++ if (ioctl(fd, TIOCGSERIAL, &serinfo) >= 0) ++ con->flags |= CON_SERIAL; ++ errno = 0; ++#else ++# if defined(KDGKBMODE) ++ if (ioctl(fd, KDGKBMODE, &mode) < 0) ++ con->flags |= CON_SERIAL; + errno = 0; ++# endif ++#endif + + if (tcgetattr(fd, tio) < 0) { +- warn(_("tcgetattr failed")); +- con->flags |= CON_NOTTY; +- return; ++ int saveno = errno; ++#if defined(KDGKBMODE) || defined(TIOCGSERIAL) ++ if (con->flags & CON_SERIAL) { /* Try to recover this */ ++ ++# if defined(TIOCGSERIAL) ++ serinfo.flags |= ASYNC_SKIP_TEST; /* Skip test of UART */ ++ ++ if (ioctl(fd, TIOCSSERIAL, &serinfo) < 0) ++ goto tcgeterr; ++ if (ioctl(fd, TIOCSERCONFIG) < 0) /* Try to autoconfigure */ ++ goto tcgeterr; ++ if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0) ++ goto tcgeterr; /* Ouch */ ++# endif ++ if (tcgetattr(fd, tio) < 0) /* Retry to get tty attributes */ ++ saveno = errno; ++ } ++# if defined(TIOCGSERIAL) ++ tcgeterr: ++# endif ++ if (saveno) ++#endif ++ { ++ FILE *fcerr = fdopen(fd, "w"); ++ if (fcerr) { ++ fprintf(fcerr, _("tcgetattr failed")); ++ fclose(fcerr); ++ } ++ warn(_("tcgetattr failed")); ++ ++ con->flags &= ~CON_SERIAL; ++ if (saveno != EIO) ++ con->flags |= CON_NOTTY; ++ else ++ con->flags |= CON_EIO; ++ ++ errno = 0; ++ return; ++ } + } + + /* Handle lines other than virtual consoles here */ +-#if defined(KDGKBMODE) +- if (ioctl(fd, KDGKBMODE, &mode) < 0) ++#if defined(KDGKBMODE) || defined(TIOCGSERIAL) ++ if (con->flags & CON_SERIAL) + #endif + { + speed_t ispeed, ospeed; + struct winsize ws; + errno = 0; + +- /* this is a modem line */ +- con->flags |= CON_SERIAL; +- + /* Flush input and output queues on modem lines */ + tcflush(fd, TCIOFLUSH); + +@@ -222,6 +271,8 @@ static void tcfinal(struct console *con) + struct termios *tio = &con->tio; + const int fd = con->fd; + ++ if (con->flags & CON_EIO) ++ return; + if ((con->flags & CON_SERIAL) == 0) { + xsetenv("TERM", "linux", 1); + return; +@@ -559,12 +610,16 @@ err: + static void setup(struct console *con) + { + int fd = con->fd; +- const pid_t pid = getpid(), pgrp = getpgid(0), ppgrp = +- getpgid(getppid()), ttypgrp = tcgetpgrp(fd); ++ const pid_t pid = getpid(), pgrp = getpgid(0), ppgrp = getpgid(getppid()); ++ pid_t ttypgrp; + + if (con->flags & CON_NOTTY) ++ goto notty; ++ if (con->flags & CON_EIO) + return; + ++ ttypgrp = tcgetpgrp(fd); ++ + /* + * Only go through this trouble if the new + * tty doesn't fall in this process group. +@@ -587,6 +642,7 @@ static void setup(struct console *con) + ioctl(fd, TIOCSCTTY, (char *)1); + tcsetpgrp(fd, ppgrp); + } ++notty: + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); +@@ -616,15 +672,19 @@ static char *getpasswd(struct console *con) + int eightbit; + const int fd = con->fd; + +- if (con->flags & CON_NOTTY) ++ if (con->flags & CON_EIO) + goto out; ++ + cp = &con->cp; + tty = con->tio; + ++ tc = 0; + ret = pass; + tty.c_iflag &= ~(IUCLC|IXON|IXOFF|IXANY); + tty.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|TOSTOP|ISIG); +- tc = (tcsetattr(fd, TCSAFLUSH, &tty) == 0); ++ ++ if ((con->flags & CON_NOTTY) == 0) ++ tc = (tcsetattr(fd, TCSAFLUSH, &tty) == 0); + + sigemptyset(&sa.sa_mask); + sa.sa_handler = alrm_handler; +@@ -650,11 +710,12 @@ static char *getpasswd(struct console *con) + } + ret = NULL; + switch (errno) { +- case 0: + case EIO: ++ con->flags |= CON_EIO; + case ESRCH: + case EINVAL: + case ENOENT: ++ case 0: + break;
View file
_service:tar_scm:backport-sysfs-fallback-for-partitions-not-including-parent-name.patch
Added
@@ -0,0 +1,45 @@ +From 9b59641bcec3df9c451eea4c7057751a153a3fcb Mon Sep 17 00:00:00 2001 +From: Portisch <hugo.portisch@yahoo.de> +Date: Mon, 8 Nov 2021 12:31:39 +0100 +Subject: PATCH sysfs: fallback for partitions not including parent name + +--- + lib/sysfs.c | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +diff --git a/lib/sysfs.c b/lib/sysfs.c +index bb71833193..191d870f66 100644 +--- a/lib/sysfs.c ++++ b/lib/sysfs.c +@@ -210,9 +210,10 @@ int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *par + d->d_type != DT_UNKNOWN) + return 0; + #endif ++ size_t len = 0; ++ + if (parent_name) { + const char *p = parent_name; +- size_t len; + + /* /dev/sda --> "sda" */ + if (*parent_name == '/') { +@@ -223,14 +224,15 @@ int sysfs_blkdev_is_partition_dirent(DIR *dir, struct dirent *d, const char *par + } + + len = strlen(p); +- if (strlen(d->d_name) <= len) +- return 0; ++ if ((strlen(d->d_name) <= len) || (strncmp(p, d->d_name, len) != 0)) ++ len = 0; ++ } + ++ if (len > 0) { + /* partitions subdir name is + * "<parent>:digit:" or "<parent>p:digit:" + */ +- return strncmp(p, d->d_name, len) == 0 && +- ((*(d->d_name + len) == 'p' && isdigit(*(d->d_name + len + 1))) ++ return ((*(d->d_name + len) == 'p' && isdigit(*(d->d_name + len + 1))) + || isdigit(*(d->d_name + len))); + } +
View file
_service:tar_scm:backport-wall-convert-homebrew-buffering-to-open_memstream.patch
Added
@@ -0,0 +1,170 @@ +From 27ee6446503af7ec0c2647704ca47ac4de3852ef Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz> +Date: Wed, 15 Mar 2023 16:16:43 +0100 +Subject: PATCH wall: convert homebrew buffering to open_memstream() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +The struct buffer system duplicates a plethora of standard I/O +functions (including a fork of fputc_careful()) +and adds a lot of complexity ‒ open_memstream() is standard, +and fits perfectly into this niche +--- + term-utils/wall.c | 95 ++++++++++------------------------------------- + 1 file changed, 20 insertions(+), 75 deletions(-) + +diff --git a/term-utils/wall.c b/term-utils/wall.c +index c601d3e5b..a51a92829 100644 +--- a/term-utils/wall.c ++++ b/term-utils/wall.c +@@ -274,74 +274,22 @@ int main(int argc, char **argv) + exit(EXIT_SUCCESS); + } + +-struct buffer { +- size_t sz; +- size_t used; +- char *data; +-}; +- +-static void buf_enlarge(struct buffer *bs, size_t len) ++static void buf_putc_careful(FILE *fs, int c) + { +- if (bs->sz == 0 || len > bs->sz - bs->used) { +- bs->sz += len < 128 ? 128 : len; +- bs->data = xrealloc(bs->data, bs->sz); +- } +-} +- +-static void buf_puts(struct buffer *bs, const char *s) +-{ +- size_t len = strlen(s); +- +- buf_enlarge(bs, len + 1); +- memcpy(bs->data + bs->used, s, len + 1); +- bs->used += len; +-} +- +-static void __attribute__((__format__ (__printf__, 2, 3))) +- buf_printf(struct buffer *bs, const char *fmt, ...) +-{ +- int rc; +- va_list ap; +- size_t limit; +- +- buf_enlarge(bs, 0); /* default size */ +- limit = bs->sz - bs->used; +- +- va_start(ap, fmt); +- rc = vsnprintf(bs->data + bs->used, limit, fmt, ap); +- va_end(ap); +- +- if (rc >= 0 && (size_t) rc >= limit) { /* not enough, enlarge */ +- buf_enlarge(bs, (size_t)rc + 1); +- limit = bs->sz - bs->used; +- va_start(ap, fmt); +- rc = vsnprintf(bs->data + bs->used, limit, fmt, ap); +- va_end(ap); +- } +- +- if (rc > 0) +- bs->used += rc; +-} +- +-static void buf_putc_careful(struct buffer *bs, int c) +-{ +- if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') { +- buf_enlarge(bs, 1); +- bs->databs->used++ = c; +- } else if (!c_isascii(c)) +- buf_printf(bs, "\\%3o", (unsigned char)c); +- else { +- char tmp = { '^', c ^ 0x40, '\0' }; +- buf_puts(bs, tmp); +- } ++ if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') ++ fputc(c, fs); ++ else if (!c_isascii(c)) ++ fprintf(fs, "\\%3o", (unsigned char)c); ++ else ++ fputs((char){ '^', c ^ 0x40, '\0' }, fs); + } + + static char *makemsg(char *fname, char **mvec, int mvecsz, + size_t *mbufsize, int print_banner) + { +- struct buffer _bs = {.used = 0}, *bs = &_bs; + register int ch, cnt; +- char *p, *lbuf; ++ char *p, *lbuf, *retbuf; ++ FILE * fs = open_memstream(&retbuf, mbufsize); + long line_max; + + line_max = sysconf(_SC_LINE_MAX); +@@ -379,15 +327,15 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, + */ + /* snprintf is not always available, but the sprintf's here + will not overflow as long as %d takes at most 100 chars */ +- buf_printf(bs, "\r%*s\r\n", TERM_WIDTH, " "); ++ fprintf(fs, "\r%*s\r\n", TERM_WIDTH, " "); + + snprintf(lbuf, line_max, + _("Broadcast message from %s@%s (%s) (%s):"), + whom, hostname, where, date); +- buf_printf(bs, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf); ++ fprintf(fs, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf); + free(hostname); + } +- buf_printf(bs, "%*s\r\n", TERM_WIDTH, " "); ++ fprintf(fs, "%*s\r\n", TERM_WIDTH, " "); + + if (mvec) { + /* +@@ -396,11 +344,11 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, + int i; + + for (i = 0; i < mvecsz; i++) { +- buf_puts(bs, mveci); ++ fputs(mveci, fs); + if (i < mvecsz - 1) +- buf_puts(bs, " "); ++ fputc(' ', fs); + } +- buf_puts(bs, "\r\n"); ++ fputs("\r\n", fs); + } else { + /* + * read message from <file> +@@ -428,23 +376,20 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, + while (fgets(lbuf, line_max, stdin)) { + for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { + if (cnt == TERM_WIDTH || ch == '\n') { +- for (; cnt < TERM_WIDTH; ++cnt) +- buf_puts(bs, " "); +- buf_puts(bs, "\r\n"); ++ fprintf(fs, "%*s\r\n", TERM_WIDTH - cnt, ""); + cnt = 0; + } + if (ch == '\t') + cnt += (7 - (cnt % 8)); + if (ch != '\n') +- buf_putc_careful(bs, ch); ++ buf_putc_careful(fs, ch); + } + } + } +- buf_printf(bs, "%*s\r\n", TERM_WIDTH, " "); ++ fprintf(fs, "%*s\r\n", TERM_WIDTH, " "); + + free(lbuf); + +- bs->databs->used = '\0'; /* be paranoid */ +- *mbufsize = bs->used; +- return bs->data; ++ fclose(fs); ++ return retbuf; + } +-- +2.27.0 +
View file
_service:tar_scm:backport-wall-use-fputs_careful.patch
Added
@@ -0,0 +1,218 @@ +From aa13246a1bf1be9e4f6eb331f4d4d2dbc875e22f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz> +Date: Wed, 15 Mar 2023 16:16:48 +0100 +Subject: PATCH wall: use fputs_careful() + +LINE_MAX only applies to teletypes in canonical mode: when stdin is a +file, it could still very much tear; start off at 512 for the sprintf(), +then use getline() like in write. + +The line wrapping has one suboptimal edge-case: + $ wall < all + + Broadcast message from nabijaczleweli@tarta (pts/4) (Tue Mar 14 22:31:25 + 2023): + + ^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^^\^^^^_ + !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJ + KLMNOPQRSTUVWXYZ\^_`abcdefghijklmnopqrstuvwxyz{|}~^?\200\201\202\203\204\205\206 + \207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232 + \233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256 + \257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302 + \303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326 + \327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352 + \353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376 + \377 +but that's a pathological input, and the result is still infinitely +better than it was before, so fixing that is more trouble than it's +worth. + +Bug-Debian: https://bugs.debian.org/826596 +--- + include/carefulputc.h | 42 +++++++++++++++++++++++++++++++++--------- + login-utils/last.c | 2 +- + term-utils/wall.c | 38 ++++++-------------------------------- + term-utils/write.c | 2 +- + 4 files changed, 41 insertions(+), 43 deletions(-) + +diff --git a/include/carefulputc.h b/include/carefulputc.h +index 740add68e..3cc6f7ff9 100644 +--- a/include/carefulputc.h ++++ b/include/carefulputc.h +@@ -6,6 +6,7 @@ + #include <ctype.h> + #ifdef HAVE_WIDECHAR + #include <wctype.h> ++#include <wchar.h> + #endif + #include <stdbool.h> + +@@ -15,18 +16,35 @@ + * A puts() for use in write and wall (that sometimes are sgid tty). + * It avoids control and invalid characters. + * The locale of the recipient is nominally unknown, +- * but it's a solid bet that the encoding is compatible with the author's. ++ * but it's a solid bet that it's compatible with the author's. ++ * Use soft_width=0 to disable wrapping. + */ +-static inline int fputs_careful(const char * s, FILE *fp, const char ctrl, bool cr_lf) ++static inline int fputs_careful(const char * s, FILE *fp, const char ctrl, bool cr_lf, int soft_width) + { +- int ret = 0; ++ int ret = 0, col = 0; + + for (size_t slen = strlen(s); *s; ++s, --slen) { +- if (*s == '\n') ++ if (*s == '\t') ++ col += (7 - (col % 8)) - 1; ++ else if (*s == '\r') ++ col = -1; ++ else if (*s == '\a') ++ --col; ++ ++ if ((soft_width && col >= soft_width) || *s == '\n') { ++ if (soft_width) { ++ fprintf(fp, "%*s", soft_width - col, ""); ++ col = 0; ++ } + ret = fputs(cr_lf ? "\r\n" : "\n", fp); +- else if (isprint(*s) || *s == '\a' || *s == '\t' || *s == '\r') ++ if (*s == '\n' || ret < 0) ++ goto wrote; ++ } ++ ++ if (isprint(*s) || *s == '\a' || *s == '\t' || *s == '\r') { + ret = putc(*s, fp); +- else if (!c_isascii(*s)) { ++ ++col; ++ } else if (!c_isascii(*s)) { + #ifdef HAVE_WIDECHAR + wchar_t w; + size_t clen = mbtowc(&w, s, slen); +@@ -35,21 +53,27 @@ static inline int fputs_careful(const char * s, FILE *fp, const char ctrl, bool + case (size_t)-1: // EILSEQ + mbtowc(NULL, NULL, 0); + nonprint: +- ret = fprintf(fp, "\\%3hho", *s); ++ col += ret = fprintf(fp, "\\%3hho", *s); + break; + default: + if(!iswprint(w)) + goto nonprint; + ret = fwrite(s, 1, clen, fp); ++ if (soft_width) ++ col += wcwidth(w); + s += clen - 1; + slen -= clen - 1; + break; + } + #else +- ret = fprintf(fp, "\\%3hho", *s); ++ col += ret = fprintf(fp, "\\%3hho", *s); + #endif +- } else ++ } else { + ret = fputs((char){ ctrl, *s ^ 0x40, '\0' }, fp); ++ col += 2; ++ } ++ ++ wrote: + if (ret < 0) + return EOF; + } +diff --git a/login-utils/last.c b/login-utils/last.c +index 1b45dbf24..37c6abe97 100644 +--- a/login-utils/last.c ++++ b/login-utils/last.c +@@ -547,7 +547,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t + /* + * Print out "final" string safely. + */ +- fputs_careful(final, stdout, '*', false); ++ fputs_careful(final, stdout, '*', false, 0); + + if (len < 0 || (size_t)len >= sizeof(final)) + putchar('\n'); +diff --git a/term-utils/wall.c b/term-utils/wall.c +index a51a92829..377db4518 100644 +--- a/term-utils/wall.c ++++ b/term-utils/wall.c +@@ -274,29 +274,13 @@ int main(int argc, char **argv) + exit(EXIT_SUCCESS); + } + +-static void buf_putc_careful(FILE *fs, int c) +-{ +- if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') +- fputc(c, fs); +- else if (!c_isascii(c)) +- fprintf(fs, "\\%3o", (unsigned char)c); +- else +- fputs((char){ '^', c ^ 0x40, '\0' }, fs); +-} +- + static char *makemsg(char *fname, char **mvec, int mvecsz, + size_t *mbufsize, int print_banner) + { +- register int ch, cnt; +- char *p, *lbuf, *retbuf; ++ char *lbuf, *retbuf; + FILE * fs = open_memstream(&retbuf, mbufsize); +- long line_max; +- +- line_max = sysconf(_SC_LINE_MAX); +- if (line_max <= 0) +- line_max = 512; +- +- lbuf = xmalloc(line_max); ++ size_t lbuflen = 512; ++ lbuf = xmalloc(lbuflen); + + if (print_banner == TRUE) { + char *hostname = xgethostname(); +@@ -329,7 +313,7 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, + will not overflow as long as %d takes at most 100 chars */ + fprintf(fs, "\r%*s\r\n", TERM_WIDTH, " "); + +- snprintf(lbuf, line_max, ++ snprintf(lbuf, lbuflen, + _("Broadcast message from %s@%s (%s) (%s):"), + whom, hostname, where, date); + fprintf(fs, "%-*.*s\007\007\r\n", TERM_WIDTH, TERM_WIDTH, lbuf); +@@ -373,18 +357,8 @@ static char *makemsg(char *fname, char **mvec, int mvecsz, + /* + * Read message from stdin. + */ +- while (fgets(lbuf, line_max, stdin)) { +- for (cnt = 0, p = lbuf; (ch = *p) != '\0'; ++p, ++cnt) { +- if (cnt == TERM_WIDTH || ch == '\n') { +- fprintf(fs, "%*s\r\n", TERM_WIDTH - cnt, ""); +- cnt = 0; +- } +- if (ch == '\t') +- cnt += (7 - (cnt % 8)); +- if (ch != '\n') +- buf_putc_careful(fs, ch); +- } +- } ++ while (getline(&lbuf, &lbuflen, stdin) >= 0) ++ fputs_careful(lbuf, fs, '^', true, TERM_WIDTH);
View file
_service:tar_scm:backport-wrap-return-in-else-directive-to-avoid-dead-code.patch
Added
@@ -0,0 +1,28 @@ +From 3fe8061d4a7cf2e282ef4b67202d351ce05de4d1 Mon Sep 17 00:00:00 2001 +From: Stefan Radu <stefan270101@gmail.com> +Date: Tue, 25 Apr 2023 18:55:07 +0300 +Subject: PATCH wrap return in #else directive to avoid dead code + +Signed-off-by: Stefan Radu <stefan270101@gmail.com> +--- + login-utils/su-common.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/login-utils/su-common.c b/login-utils/su-common.c +index 67c4fa271..b67492048 100644 +--- a/login-utils/su-common.c ++++ b/login-utils/su-common.c +@@ -343,8 +343,9 @@ static int supam_conv( int num_msg, + return misc_conv(num_msg, msg, resp, data); + #elif defined(HAVE_SECURITY_OPENPAM_H) + return openpam_ttyconv(num_msg, msg, resp, data); +-#endif ++#else + return PAM_CONV_ERR; ++#endif + } + + static void supam_cleanup(struct su_context *su, int retcode) +-- +2.27.0 +
View file
_service:tar_scm:backport-write-correctly-handle-wide-characters.patch
Added
@@ -0,0 +1,199 @@ +From 8a7b8456d1dc0e7ca557d1ac31f638986704757f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= <nabijaczleweli@nabijaczleweli.xyz> +Date: Wed, 15 Mar 2023 16:16:31 +0100 +Subject: PATCH write: correctly handle wide characters +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Do this by replacing fputc_careful() (notice that the description said +it's locale-aware ‒ it very much is /not/), with a fputs_careful() which +does the same thing, but if it were to output a byte in the \123 format, +first it checks whether this byte starts a valid multibyte character. + +If it does, and that character is printable, write it verbatim. +This means that + echo 'foo åäö ąęćźżń bar' | write nabijaczleweli pts/4 +instead of + foo \303\245\303\244\303\266 + \304\205\304\231\304\207\305\272\305\274\305\204 bar +yields + foo åäö ąęćźżń bar +or, more realistically, from a message I got earlier today, + Filip powiedzia\305\202 \305\274e zap\305\202aci jutro +becomes + Filip powiedział że zapłaci jutro + +Invalid/non-printable sequences get processed as before. + +Line reading in write must become getline() to avoid dealing with +partial characters: for example on input consisting solely of +ąęćźżń, where every {1} is an instance, the output would be + {42}ąęć\305\272żń{84}ąęćź\305\274ń{84}ąęćźż\305\204{39} +with just fixed-512 fgets() + +Bug-Debian: https://bugs.debian.org/826596 +--- + include/carefulputc.h | 60 +++++++++++++++++++++++++++++++------------ + login-utils/last.c | 4 +-- + term-utils/write.c | 25 +++++------------- + 3 files changed, 52 insertions(+), 37 deletions(-) + +diff --git a/include/carefulputc.h b/include/carefulputc.h +index 8860b1234..740add68e 100644 +--- a/include/carefulputc.h ++++ b/include/carefulputc.h +@@ -1,31 +1,59 @@ + #ifndef UTIL_LINUX_CAREFULPUTC_H + #define UTIL_LINUX_CAREFULPUTC_H + +-/* +- * A putc() for use in write and wall (that sometimes are sgid tty). +- * It avoids control characters in our locale, and also ASCII control +- * characters. Note that the locale of the recipient is unknown. +-*/ + #include <stdio.h> + #include <string.h> + #include <ctype.h> ++#ifdef HAVE_WIDECHAR ++#include <wctype.h> ++#endif ++#include <stdbool.h> + + #include "cctype.h" + +-static inline int fputc_careful(int c, FILE *fp, const char fail) ++/* ++ * A puts() for use in write and wall (that sometimes are sgid tty). ++ * It avoids control and invalid characters. ++ * The locale of the recipient is nominally unknown, ++ * but it's a solid bet that the encoding is compatible with the author's. ++ */ ++static inline int fputs_careful(const char * s, FILE *fp, const char ctrl, bool cr_lf) + { +- int ret; ++ int ret = 0; + +- if (isprint(c) || c == '\a' || c == '\t' || c == '\r' || c == '\n') +- ret = putc(c, fp); +- else if (!c_isascii(c)) +- ret = fprintf(fp, "\\%3o", (unsigned char)c); +- else { +- ret = putc(fail, fp); +- if (ret != EOF) +- ret = putc(c ^ 0x40, fp); ++ for (size_t slen = strlen(s); *s; ++s, --slen) { ++ if (*s == '\n') ++ ret = fputs(cr_lf ? "\r\n" : "\n", fp); ++ else if (isprint(*s) || *s == '\a' || *s == '\t' || *s == '\r') ++ ret = putc(*s, fp); ++ else if (!c_isascii(*s)) { ++#ifdef HAVE_WIDECHAR ++ wchar_t w; ++ size_t clen = mbtowc(&w, s, slen); ++ switch(clen) { ++ case (size_t)-2: // incomplete ++ case (size_t)-1: // EILSEQ ++ mbtowc(NULL, NULL, 0); ++ nonprint: ++ ret = fprintf(fp, "\\%3hho", *s); ++ break; ++ default: ++ if(!iswprint(w)) ++ goto nonprint; ++ ret = fwrite(s, 1, clen, fp); ++ s += clen - 1; ++ slen -= clen - 1; ++ break; ++ } ++#else ++ ret = fprintf(fp, "\\%3hho", *s); ++#endif ++ } else ++ ret = fputs((char){ ctrl, *s ^ 0x40, '\0' }, fp); ++ if (ret < 0) ++ return EOF; + } +- return (ret < 0) ? EOF : 0; ++ return 0; + } + + static inline void fputs_quoted_case(const char *data, FILE *out, int dir) +diff --git a/login-utils/last.c b/login-utils/last.c +index d3eeed4b6..1b45dbf24 100644 +--- a/login-utils/last.c ++++ b/login-utils/last.c +@@ -392,7 +392,6 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t + char final512; + char utlinesizeof(p->ut_line) + 1; + char domain256; +- char *s; + int mins, hours, days; + int r, len; + struct last_timefmt *fmt; +@@ -548,8 +547,7 @@ static int list(const struct last_control *ctl, struct utmpx *p, time_t logout_t + /* + * Print out "final" string safely. + */ +- for (s = final; *s; s++) +- fputc_careful(*s, stdout, '*'); ++ fputs_careful(final, stdout, '*', false); + + if (len < 0 || (size_t)len >= sizeof(final)) + putchar('\n'); +diff --git a/term-utils/write.c b/term-utils/write.c +index 8b86e9a9d..b485e28fd 100644 +--- a/term-utils/write.c ++++ b/term-utils/write.c +@@ -223,21 +223,6 @@ static void signal_handler(int signo) + signal_received = signo; + } + +-/* +- * write_line - like fputs(), but makes control characters visible and +- * turns \n into \r\n. +- */ +-static void write_line(char *s) +-{ +- while (*s) { +- const int c = *s++; +- +- if ((c == '\n' && fputc_careful('\r', stdout, '^') == EOF) +- || fputc_careful(c, stdout, '^') == EOF) +- err(EXIT_FAILURE, _("carefulputc failed")); +- } +-} +- + /* + * do_write - actually make the connection + */ +@@ -247,7 +232,8 @@ static void do_write(const struct write_control *ctl) + struct passwd *pwd; + time_t now; + struct tm *tm; +- char *host, line512; ++ char *host, *line = NULL; ++ size_t linelen = 0; + struct sigaction sigact; + + /* Determine our login name(s) before the we reopen() stdout */ +@@ -286,11 +272,14 @@ static void do_write(const struct write_control *ctl) + free(host); + printf("\r\n"); + +- while (fgets(line, sizeof(line), stdin) != NULL) { ++ while (getline(&line, &linelen, stdin) >= 0) { + if (signal_received) + break; +- write_line(line); ++ ++ if (fputs_careful(line, stdout, '^', true) == EOF) ++ err(EXIT_FAILURE, _("carefulputc failed")); + } ++ free(line); + printf("EOF\r\n"); + } + +-- +2.27.0 +
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2