File: lang-bash.texi

package info (click to toggle)
gettext 0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 168,104 kB
  • sloc: ansic: 532,579; sh: 68,252; perl: 28,011; makefile: 9,068; lisp: 3,184; yacc: 1,055; java: 615; cs: 589; cpp: 397; objc: 343; sed: 79; tcl: 63; xml: 40; pascal: 11; awk: 7; php: 7
file content (42 lines) | stat: -rw-r--r-- 2,051 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
@c This file is part of the GNU gettext manual.
@c Copyright (C) 1995-2020 Free Software Foundation, Inc.
@c See the file gettext.texi for copying conditions.

@node bash
@subsection bash - Bourne-Again Shell Script
@cindex bash

GNU @code{bash} 2.0 or newer has a special shorthand for translating a
string and substituting variable values in it: @code{$"msgid"}.  But
the use of this construct is @strong{discouraged}, due to the security
holes it opens and due to its portability problems.

The security holes of @code{$"..."} come from the fact that after looking up
the translation of the string, @code{bash} processes it like it processes
any double-quoted string: dollar and backquote processing, like @samp{eval}
does.

@enumerate
@item
In a locale whose encoding is one of BIG5, BIG5-HKSCS, GBK, GB18030, SHIFT_JIS,
JOHAB, some double-byte characters have a second byte whose value is
@code{0x60}.  For example, the byte sequence @code{\xe0\x60} is a single
character in these locales.  Many versions of @code{bash} (all versions
up to bash-2.05, and newer versions on platforms without @code{mbsrtowcs()}
function) don't know about character boundaries and see a backquote character
where there is only a particular Chinese character.  Thus it can start
executing part of the translation as a command list.  This situation can occur
even without the translator being aware of it: if the translator provides
translations in the UTF-8 encoding, it is the @code{gettext()} function which
will, during its conversion from the translator's encoding to the user's
locale's encoding, produce the dangerous @code{\x60} bytes.

@item
A translator could - voluntarily or inadvertently - use backquotes
@code{"`...`"} or dollar-parentheses @code{"$(...)"} in her translations.
The enclosed strings would be executed as command lists by the shell.
@end enumerate

The portability problem is that @code{bash} must be built with
internationalization support; this is normally not the case on systems
that don't have the @code{gettext()} function in libc.