1
0
mirror of https://github.com/dockur/windows.git synced 2026-07-27 21:42:36 +07:00

fix: Handling of UTF-16 batch files (#1979)

This commit is contained in:
Kroese
2026-07-26 03:18:41 +02:00
committed by GitHub
parent 2b7d7bf902
commit 36d127d8cf
2 changed files with 52 additions and 6 deletions
+47 -5
View File
@@ -806,6 +806,42 @@ detectImage() {
return 0 return 0
} }
normalizeBatch() {
local file="$1"
local bom tmp encoding
[ ! -f "$file" ] && return 0
[ ! -s "$file" ] && return 0
bom=$(od -An -N2 -tx1 "$file" | tr -d ' \n') || return 1
case "$bom" in
"fffe" ) encoding="UTF-16LE" ;;
"feff" ) encoding="UTF-16BE" ;;
* ) return 0 ;;
esac
if ! tmp=$(mktemp "${file}.XXXXXX"); then
error "Failed to create temporary batch file!"
return 1
fi
if ! tail -c +3 "$file" | iconv -f "$encoding" -t UTF-8 > "$tmp"; then
rm -f "$tmp"
error "Failed to convert $file from $encoding to UTF-8!"
return 1
fi
if ! chmod --reference="$file" "$tmp" || ! mv -f "$tmp" "$file"; then
rm -f "$tmp"
error "Failed to replace batch file: $file"
return 1
fi
return 0
}
checkBatch() { checkBatch() {
local file="$1" local file="$1"
@@ -813,7 +849,7 @@ checkBatch() {
local tmp output local tmp output
local matches line local matches line
[ ! -f "$file" ] && return 0 [ -s "$file" ] || return 0
if ! tmp=$(mktemp -d /tmp/blinter.XXXXXX); then if ! tmp=$(mktemp -d /tmp/blinter.XXXXXX); then
warn "failed to create temporary Blinter directory." warn "failed to create temporary Blinter directory."
@@ -824,14 +860,20 @@ checkBatch() {
[ -n "${COMMAND:-}" ] && source="your COMMAND variable" [ -n "${COMMAND:-}" ] && source="your COMMAND variable"
if enabled "$DEBUG"; then if enabled "$DEBUG"; then
report="Y" report="Y"
if LC_ALL=C grep -Pq '[^\x09\x0D\x20-\x7E]' "$file"; then
warn "non-ASCII characters were detected in $source and may not execute correctly in Windows Command Prompt."
fi
else else
# First pass: silently check only for Error-level findings. # First pass: silently check only for Error-level findings.
cat > "$tmp/blinter.ini" <<'EOF' cat > "$tmp/blinter.ini" <<'EOC'
[general] [general]
min_severity = error min_severity = error
EOF EOC
if ! ( if ! (
cd "$tmp" cd "$tmp"
@@ -846,14 +888,14 @@ EOF
# Show useful diagnostic context, while excluding findings that are # Show useful diagnostic context, while excluding findings that are
# irrelevant to unattended OEM scripts. # irrelevant to unattended OEM scripts.
cat > "$tmp/blinter.ini" <<'EOF' cat > "$tmp/blinter.ini" <<'EOC'
[general] [general]
min_severity = warning min_severity = warning
show_summary = false show_summary = false
[rules] [rules]
disabled_rules = W001,W028,W041,SEC002,SEC005 disabled_rules = W001,W028,W041,SEC002,SEC005
EOF EOC
output=$( output=$(
cd "$tmp" cd "$tmp"
+5 -1
View File
@@ -820,6 +820,10 @@ addFolder() {
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat -print -quit) || return 1 file=$(find "$dest" -maxdepth 1 -type f -iname install.bat -print -quit) || return 1
if [ -s "$file" ]; then
normalizeBatch "$file" || return 1
fi
if [ -n "$COMMAND" ]; then if [ -n "$COMMAND" ]; then
[ -z "$file" ] && file="$dest/install.bat" [ -z "$file" ] && file="$dest/install.bat"
@@ -832,7 +836,7 @@ addFolder() {
fi fi
if [ -f "$file" ]; then if [ -s "$file" ]; then
if ! unix2dos -q "$file"; then if ! unix2dos -q "$file"; then
error "Failed to convert $file to DOS format!" error "Failed to convert $file to DOS format!"