usr/bin/libreoffice script bad symlink following

Bug #1141106 reported by Julian Taylor on 2013-03-03
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Fix Released
libreoffice (Debian)
Fix Released
libreoffice (Ubuntu)

Bug Description


content of usr/bin/libreoffice:

while [ -h "$sd_res" ] ; do
    cd "`dirname "$sd_res"`"
    sd_basename=`basename "$sd_res"`
    sd_res=`ls -l "$sd_basename" | sed "s/.*$sd_basename -> //g"`
cd "`dirname "$sd_res"`"
cd "$sd_cwd"

sd_res is a symlink in ubuntu so it goes in there
please use something sane like readlink to get the target instead of that weird sed line

a user in #ubuntu+1 reports issues with it because he apparently has some invalid locale in the month part of ls -l:
he gets:
02:04 <Allard> /usr/bin/libreoffice: 49: cd: can't cd to lrwxrwxrwx 1 root root 34 ���../lib/libreoffice/program
02:04 <Allard> /usr/bin/libreoffice: 156: exec: /usr/bin/oosplash: not found

Problem description:

I ran into this problem last year, in the same month, and here I am again. This section of code is in /usr/lib/libreoffice/program/soffice:

# resolve installation directory
if [ -h "$0" ] ; then
    sd_basename=`basename "$0"`
     sd_script=`ls -l "$0" | sed "s/.*${sd_basename} -> //g"`
    cd "`dirname "$0"`"
    cd "`dirname "$sd_script"`"
    cd "`dirname "$0"`"
cd "$sd_cwd"
The gentoo developers rightly refer to this code as "completely broken", as it causes LibreOffice to puke on launch when trying to determine the month string of its working directory if used on a system for which certain months use non-standard characters.

For instance, in Gremany, the current month is "März." Launching LO any time between now and 2013-04-01 will cause LO to fail with the following error:

$ libreoffice
ls: error initializing month strings
/usr/bin/libreoffice: line 58: cd: lrwxrwxrwx 1 root root 38 10. Mä/usr/lib64/libreoffice/program: No such file or directory
/usr/bin/libreoffice: line 180: /usr/bin/oosplash: No such file or directory

Steps to reproduce:
1. set the filesystem locale to German (any variant)
2. try to launch LO in the month of March
3. cry

Current behavior: the launcher pukes

Expected behavior: the launcher could maybe use a coreutil that is pretty good at reading month strings? In any case, it should launch properly.


Operating System: Linux (Other)
Version: release

Changed in libreoffice (Debian):
status: Unknown → New
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in libreoffice (Ubuntu):
status: New → Confirmed

while it seems obvious to use readlink, it think the original rationale here was to be POSIXy-correct.

Julian Taylor (jtaylor) wrote :

one can try readlink and fall back to the thing that breaks under unusual circumstances only if its not there.
But for ubuntu/debian we don't even need to care, we have readlink in coreutils.

Yes, should be fixed with a test for `which readlink` and only then a fallback to the sed-voodoo in. Code pointer is:

This is an easy hack. The only trick is that the solution need to work on a wide variety of systems, not on Linux only.
See also:

Created attachment 80803

The script should be locale independent. Set LC_ALL=C to do this.

Unconditionally overwriting locale settings might have unintended consequences for the started LibreOffice program. Thus I have written two alternative patches:

1. libreoffice_bug62192_minimal_fix.patch
 This fixes the offending 'ls' call only.

2. libreoffice_bug62192_involved_fix.patch
 This saves the current LC_ALL setting, sets the POSIX locale for (most of) the script, and restores the original setting before exec'ing the LibreOffice binary.

The minimal fix seems quite safe, but the more invovled one should be tested on several different systems.

BTW, this bug is not reproducible with Debian GNU/Linux (checked, old stable, stable and unstable), because the GNU sed used copes with non-ASCII input.

Created attachment 80825
[PATCH] Minimal fix: use POSIX locale for ls call only

Created attachment 80826
[PATCH] Save LC_ALL, use POSIX locale for script, and restore LC_ALL before starting LibreOffice

Erik Auerswald committed a patch related to this issue.
It has been pushed to "master":

fdo#62192: broken launch script, bork in March in Germany

The patch should be included in the daily builds available at in the next 24-48 hours. More
information about daily builds can be found at:
Affected users are encouraged to test the fix and report feedback.

Changed in libreoffice (Ubuntu):
status: Confirmed → Fix Committed
Changed in df-libreoffice:
importance: Unknown → Medium
status: Unknown → Incomplete
WoodyEckelzone (bcr497) wrote :

I stumbled on a similar bug, Libreoffice wouldn't start caused by a homemade (experimental) `ls` script in ~/bin.

Seems Libreoffice is calling `ls` instead of `/bin/ls`

assumed fixed with the commit.

Changed in df-libreoffice:
status: Incomplete → Fix Released
Adolfo Jayme (fitojb) on 2015-05-18
Changed in libreoffice (Ubuntu):
status: Fix Committed → Fix Released
Changed in libreoffice (Debian):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.