From 84c712b4b12d1a9068ee7c1cde95ec57bd121ecb Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Thu, 13 Aug 2026 11:37:53 +0200 Subject: [PATCH 1/3] init: fix command injection in bash Tab completion (compgen -W expansion) _module_comgen_words_and_files() fed untrusted text (module names read off disk, LOADEDMODULES, MODULEPATH) straight into `compgen -W`, which performs a full unquoted-word expansion on its wordlist -- including command substitution -- as a normal, documented part of its behavior. A module name, loaded-module entry, or MODULEPATH component containing e.g. `$(...)` therefore ran arbitrary shell code the moment a user pressed Tab. Fix: never hand candidate text to `compgen -W`. The new _module_comgen_words() splits the candidate list with `read -r -d ''` (pure IFS word-splitting, no expansion of any kind) and does the prefix match itself; _module_comgen_words_and_files() now layers the nospace-for-directory-entries behavior on top of it. Every call site that previously built a compgen -W wordlist from LOADEDMODULES, MODULEPATH, or a stash/save collection name now goes through one of these two functions instead. Fixes CVE-2026-85013 Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle --- .hunspell.en.dic | 5 ++++ init/bash_completion.in | 51 ++++++++++++++++++++++++++--------------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/.hunspell.en.dic b/.hunspell.en.dic index 87f655342..ff33a005a 100644 --- a/.hunspell.en.dic +++ b/.hunspell.en.dic @@ -283,6 +283,7 @@ chemappB chempappB chgrp chmod +claude cleanupAndExit cmake cmd @@ -318,11 +319,13 @@ cmdstring codecov codespell collectModuleTag +comgen commandexp commandname compA compB compat +compgen compilerTag compopt config @@ -631,6 +634,7 @@ nonpersist noop nop noparse +nospace notavail nothreads notuasked @@ -861,6 +865,7 @@ unsetState unsetenv unsets unsetting +untrusted unuse unusing updateInstead diff --git a/init/bash_completion.in b/init/bash_completion.in index 1e9f0e3ca..b42c31362 100644 --- a/init/bash_completion.in +++ b/init/bash_completion.in @@ -2,17 +2,30 @@ # # Bash commandline completion # +_module_comgen_words() { + local -a words + local val + # split candidate list on IFS without triggering shell expansion (command + # substitution, arithmetic, ...): candidate words may come from module + # names read off disk, which must never be treated as executable code + IFS=$' \t\n' read -r -d '' -a words <<<"$1" + for val in "${words[@]}"; do + case "$val" in + "$2"*) COMPREPLY[${#COMPREPLY[@]}]="$val" ;; + esac + done +} + _module_comgen_words_and_files() { - local k=0 - local setnospace=1 + local start=${#COMPREPLY[@]} i + _module_comgen_words "$1" "$2" # do not append space to word completed if it is a directory (ends with /) - for val in $(compgen -W "$1" -- "$2"); do - if [ $setnospace -eq 1 ] && [ "${val: -1:1}" = '/' ]; then + for ((i = start; i < ${#COMPREPLY[@]}; i++)); do + if [ "${COMPREPLY[i]: -1:1}" = '/' ]; then # Bash >=4.0 is required for compopt type compopt &>/dev/null && compopt -o nospace - setnospace=0 + break fi - COMPREPLY[k++]="$val" done } @@ -56,7 +69,7 @@ _module_long_arg_list() { _module_comgen_words_and_files "$(_module_not_yet_loaded "$cur")" "$cur" break;; rm|del|remove|unload|switch|swap) - COMPREPLY=( $(IFS=: compgen -W "${LOADEDMODULES}" -- "$cur") ) + _module_comgen_words "${LOADEDMODULES//:/ }" "$cur" break;; esac done @@ -76,14 +89,14 @@ _module() { list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );; stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );; stashpop|stashshow|stashrm) - COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );; + _module_comgen_words "$(_module_stashlist)" "$cur";; clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; restore|save|saveshow|saverm|is-saved) - COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );; + _module_comgen_words "$(_module_savelist)" "$cur";; rm|del|remove|unload) - COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );; + _module_comgen_words "@comp_unload_opts@ ${LOADEDMODULES//:/ }" "$cur";; + switch|swap) _module_comgen_words "@comp_load_opts@ ${LOADEDMODULES//:/ }" "$cur";; + unuse|is-used) _module_comgen_words "${MODULEPATH//:/ }" "$cur";; use|-a|--append|cachebuild) ;; # let readline handle the completion display|help|show|test|path|paths|is-loaded|info-loaded) _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";; @@ -138,14 +151,14 @@ if type -t ml >/dev/null; then list|savelist) COMPREPLY=( $(compgen -W "@comp_list_opts@" -- "$cur") );; stashlist) COMPREPLY=( $(compgen -W "@comp_stashlist_opts@" -- "$cur") );; stashpop|stashshow|stashrm) - COMPREPLY=( $(compgen -W "$(_module_stashlist)" -- "$cur") );; + _module_comgen_words "$(_module_stashlist)" "$cur";; clear) COMPREPLY=( $(compgen -W "@comp_clear_opts@" -- "$cur") );; restore|save|saveshow|saverm|is-saved) - COMPREPLY=( $(compgen -W "$(_module_savelist)" -- "$cur") );; + _module_comgen_words "$(_module_savelist)" "$cur";; rm|del|remove|unload) - COMPREPLY=( $(compgen -W "@comp_unload_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - switch|swap) COMPREPLY=( $(compgen -W "@comp_load_opts@ ${LOADEDMODULES//:/ }" -- "$cur") );; - unuse|is-used) COMPREPLY=( $(IFS=: compgen -W "${MODULEPATH}" -- "$cur") );; + _module_comgen_words "@comp_unload_opts@ ${LOADEDMODULES//:/ }" "$cur";; + switch|swap) _module_comgen_words "@comp_load_opts@ ${LOADEDMODULES//:/ }" "$cur";; + unuse|is-used) _module_comgen_words "${MODULEPATH//:/ }" "$cur";; use|-a|--append|cachebuild) ;; # let readline handle the completion display|help|show|test|path|paths|is-loaded|info-loaded) _module_comgen_words_and_files "@comp_mfile_opts@ $(_module_avail "$cur")" "$cur";; @@ -182,14 +195,14 @@ if type -t ml >/dev/null; then for i in ${LOADEDMODULES//:/ }; do loaded_modules+="-${i} " done - COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );; + _module_comgen_words "@comp_load_opts@ $loaded_modules" "$cur";; *) _module_comgen_words_and_files "@comp_load_opts@ $(_module_not_yet_loaded "$cur")" "$cur" COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_opts@ @comp_cmds@" -- "$cur") ) loaded_modules="" for i in ${LOADEDMODULES//:/ }; do loaded_modules+="-${i} " done - COMPREPLY=( "${COMPREPLY[@]}" $(compgen -W "@comp_load_opts@ $loaded_modules" -- "$cur") );; + _module_comgen_words "@comp_load_opts@ $loaded_modules" "$cur";; esac fi;; esac From 7817dba0e40613db05f38a0ef2b94e7e086e26d0 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 3 May 2025 14:52:57 +0200 Subject: [PATCH 2/3] script: sync gitlog2changelog.py with upstream Update gitlog2changelog.py script with recent changes made on it in its upstream repository (https://github.com/networkupstools/nut/, commit e4739b9). Keep our local adaptation: * TextWrapper specific configuration Signed-off-by: Xavier Delaruelle --- script/gitlog2changelog.py.in | 161 +++++++++++++++++++++++++++++----- 1 file changed, 139 insertions(+), 22 deletions(-) diff --git a/script/gitlog2changelog.py.in b/script/gitlog2changelog.py.in index 2c79ac38f..bac4c7e8a 100644 --- a/script/gitlog2changelog.py.in +++ b/script/gitlog2changelog.py.in @@ -1,6 +1,7 @@ #!@PYTHON@ # Copyright 2008 Marcus D. Hanwell # Minor changes for NUT by Charles Lepple +# Subsequent maintenance for NUT by Jim Klimov (since 2021) # Distributed under the terms of the GNU General Public License v2 or later import re @@ -9,6 +10,24 @@ from textwrap import TextWrapper import sys import subprocess +# Python 3 compatibility hack +try: + try: + import unicode + except: + # Maybe built-in? + pass + unicode('') +except NameError as ex: + #DEBUG# sys.stderr.write("Using 'str' as 'unicode': %s\n" % str(ex)) + #DEBUG# sys.stderr.flush() + unicode = str + +try: + import unicodedata +except: + pass + rev_range = "HEAD" if len(sys.argv) > 1: @@ -53,11 +72,47 @@ except TypeError: fin_mode = 2 fin_chop = 1 -# Create a ChangeLog file in the current directory. -if fin_mode == 3: - fout = open("ChangeLog", "w", encoding="UTF-8") +# Create a ChangeLog file in the current directory by default. +CHANGELOG_FILE = "ChangeLog" +try: + # e.g. point from Makefile to a builddir (caller ensures it exists) + if os.environ.get("CHANGELOG_FILE", None) is not None: + CHANGELOG_FILE = os.environ.get("CHANGELOG_FILE") +except Exception as ignored: + pass + +if CHANGELOG_FILE == "-": + fout = sys.stdout else: - fout = open("ChangeLog", "w") + if fin_mode == 3: + fout = open(CHANGELOG_FILE, "w", encoding="UTF-8") + else: + fout = open(CHANGELOG_FILE, "w") + +# By default we collect information from a commit and output it as soon as +# we have enough. Part of it is best-effort grouping of a series of commits +# made by the same author on the same day, if they follow each other. +# The alternative is to expend memory to collect all git log entries into a +# dictionary first (key = date+author, value = list of entries) and only +# print the output in the end of processing. This costs more resources, so +# is not default behavior. +requireGroupByDateAuthor = False +try: + tmpEnvVar = os.environ.get("CHANGELOG_REQUIRE_GROUP_BY_DATE_AUTHOR", None) + if str(tmpEnvVar).lower() == "true": + requireGroupByDateAuthor = True +except Exception as ignored: + pass + +cachedContent = None +if requireGroupByDateAuthor: + try: + from collections import defaultdict + cachedContent = defaultdict(list) + except Exception as x: + print("Failed to init requireGroupByDateAuthor processing as defaultdict(list), trying simple dict(): " + str(x)) + requireGroupByDateAuthor = False + cachedContent = dict() # Set up the loop variables in order to locate the blocks we want authorFound = False @@ -69,12 +124,16 @@ messageNL = False files = "" prevAuthorLine = "" -wrapper = TextWrapper( - initial_indent=" ", - subsequent_indent=" ", - width=78, - break_on_hyphens=False -) +# Legacy default: keep as is +authorMustBeASCII = False +authorMustBeASCII_inverse_setting = str(os.environ.get("WITH_PDF_NONASCII_TITLES", "")).upper() +if authorMustBeASCII_inverse_setting in ["YES", "TRUE"]: + authorMustBeASCII = False +elif authorMustBeASCII_inverse_setting in ["NO", "FALSE"]: + authorMustBeASCII = True + +# See also: https://github.com/python/cpython/blob/main/Lib/textwrap.py +wrapper = TextWrapper(initial_indent=" ", subsequent_indent=" ", width=78, break_on_hyphens=False) # The main part of the loop for line in fin: @@ -92,17 +151,33 @@ for line in fin: # Match the author line and extract the part we want # (Don't use startswith to allow Author override inside commit message.) elif "Author:" in line: - authorList = re.split(": ", line, 1) + if sys.version_info >= (3, 13, ): + authorList = re.split(": ", line, maxsplit=1) + else: + authorList = re.split(": ", line, 1) + try: author = authorList[1] author = author[0 : len(author) - fin_chop] + if authorMustBeASCII: + try: + if isinstance(author, str) and unicode != str: + author = unicodedata.normalize(u'NFKD', unicode(author, "utf-8")).encode('ascii', 'ignore').decode('utf8') + else: + author = unicodedata.normalize(u'NFKD', author).encode('ascii', 'ignore').decode('utf8') + except Exception as e: + print("Could not unicodedata.normalize() author '%s': %s" % (author, str(e))) authorFound = True except: print("Could not parse authorList = '%s'" % (line)) # Match the date line elif line.startswith("Date:"): - dateList = re.split(": ", line, 1) + if sys.version_info >= (3, 13, ): + dateList = re.split(": ", line, maxsplit=1) + else: + dateList = re.split(": ", line, 1) + try: date = dateList[1] date = date[0 : len(date) - fin_chop] @@ -120,7 +195,14 @@ for line in fin: continue # Extract the actual commit message for this commit elif authorFound and dateFound and messageFound is False: - # Find the commit message if we can + # Find the commit message if we can (including the optional + # details after the title and a blank line) + # FIXME: Detect end of message by /^#/ to allow for longer essays + # in the detailed comments part? + # FIXME: Some such comments include asciidoc-ish markup, notably + # bullet lists - do not concatenate those into one block but do + # actually pass them as sub-lists (indented, and perhaps not + # starting with an asterisk which we use for this document). if len(line) == fin_chop: if messageNL: messageFound = True @@ -139,23 +221,39 @@ for line in fin: continue # Collect the files for this commit. FIXME: Still need to add +/- to files elif authorFound and dateFound and messageFound: - fileList = re.split(r' \| ', line, 2) + if sys.version_info >= (3, 13, ): + fileList = re.split(r' \| ', line, maxsplit=2) + else: + fileList = re.split(r' \| ', line, 2) + if len(fileList) > 1: if len(files) > 0: files = files + ", " + fileList[0].strip() else: files = fileList[0].strip() + # All of the parts of the commit have been found - write out the entry if authorFound and dateFound and messageFound and filesFound: # First the author line, only outputted if it is the first for that - # author on this day + # author on this day. + # WARNING: In case of git rebase commit shuffling, merges of dormant + # branches, etc. we are not guaranteed to have all dates in the list + # nicely ordered. In fact, the same date+author can be repeated if + # there were commits with other metadata in git history between those + # (e.g. many PRs from a few authors merged during one day). While we + # could cache each section by authorLine and only output in the end, + # it can require a lot of memory - so by default we do not. authorLine = date + " " + author - if len(prevAuthorLine) == 0: - fout.write(authorLine + "\n\n") - elif authorLine == prevAuthorLine: - pass + if requireGroupByDateAuthor: + if authorLine not in cachedContent: + cachedContent[authorLine] = list() else: - fout.write("\n" + authorLine + "\n\n") + if len(prevAuthorLine) == 0: + fout.write(authorLine + "\n\n") + elif authorLine == prevAuthorLine: + pass + else: + fout.write("\n" + authorLine + "\n\n") # Assemble the actual commit message line(s) and limit the line length # to 80 characters. @@ -177,8 +275,11 @@ for line in fin: else: commitLine = "* " + files + ": " + message - # Write out the commit line - fout.write(wrapper.fill(commitLine) + "\n") + if requireGroupByDateAuthor: + cachedContent[authorLine].append(commitLine) + else: + # Write out the commit line, wrapped for length + fout.write(wrapper.fill(commitLine) + "\n") # Now reset all the variables ready for a new commit block. authorFound = False @@ -190,6 +291,22 @@ for line in fin: files = "" prevAuthorLine = authorLine +if requireGroupByDateAuthor: + # We did not print anything before, flush it out now; + # most recent date first (alphanumerically reverse) + counter = 0 + for authorLine in sorted(cachedContent, reverse=True): + if counter == 0: + fout.write(authorLine + "\n\n") + else: + fout.write("\n" + authorLine + "\n\n") + + # Use original list append order + for commitLine in cachedContent[authorLine]: + fout.write(wrapper.fill(commitLine) + "\n") + + counter = counter + 1 + # Close the input and output lines now that we are finished. if fin_mode == 3: p.stdout.close() From 0192e2962e0c92c87bf9ad6e9d4b82a36880cdce Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Mon, 7 Sep 2026 06:39:58 +0200 Subject: [PATCH 3/3] Release of version 5.3.2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 11 +++++++++++ contrib/rpm/environment-modules.spec.in | 5 ++++- doc/source/conf.py | 2 +- version.inc.in | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index 9bf015092..96604cf80 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -8,6 +8,17 @@ documents those changes that are of interest to users and admins. .. _5.3 release notes: +Modules 5.3.2 (2026-09-07) +-------------------------- + +* Init: fix command injection in Bash completion when module names contain + shell meta-characters. Completion candidates were passed to ``compgen -W`` + which evaluates command substitution syntax. (fix `CVE-2026-85013`_ found + by AISLE in partnership with Red Hat) + +.. _CVE-2026-85013: https://github.com/envmodules/modules/security/advisories/GHSA-8hrw-p88g-qhmg + + Modules 5.3.1 (2023-06-27) -------------------------- diff --git a/contrib/rpm/environment-modules.spec.in b/contrib/rpm/environment-modules.spec.in index da232075d..0d7f75bb4 100644 --- a/contrib/rpm/environment-modules.spec.in +++ b/contrib/rpm/environment-modules.spec.in @@ -2,7 +2,7 @@ %global vimdatadir %{_datadir}/vim/vimfiles Name: environment-modules -Version: 5.3.1 +Version: 5.3.2 Release: @MODULES_RPM_RELEASE@%{?dist} Summary: Provides dynamic modification of a user's environment @@ -235,6 +235,9 @@ fi %changelog +* Mon Sep 07 2026 Xavier Delaruelle - 5.3.2-1 +- Update to 5.3.2 (fix CVE-2026-85013) + * Tue Jun 27 2023 Xavier Delaruelle - 5.3.1-1 - Update to 5.3.1 - Distribute ChangeLog as a zipped file to reduce installation size diff --git a/doc/source/conf.py b/doc/source/conf.py index ed39155b9..b1d6a06fb 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -79,7 +79,7 @@ def get_version_release_from_git(): else: return version, version + '+' + branch + '-' + tags else: - return '5.3.1', '' + return '5.3.2', '' # The short X.Y version. # The full version, including alpha/beta/rc tags. diff --git a/version.inc.in b/version.inc.in index 0bcbde73e..9bc2df93b 100644 --- a/version.inc.in +++ b/version.inc.in @@ -1,7 +1,7 @@ # Release definitions shared across the Makefiles of this project # run make to generate version.inc -MODULES_RELEASE := 5.3.1 +MODULES_RELEASE := 5.3.2 MODULES_BUILD_HASH := $Format:%h$ MODULES_BUILD_REFS := $Format:%D$ MODULES_BUILD_FDATE := $Format:%ci$