Bug 459823 - `` expansion in /etc/profile.d *.sh files do not provide correct number of parameters to '[' builtin
`` expansion in /etc/profile.d *.sh files do not provide correct number of pa...
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: vim (Show other bugs)
5.4
All Linux
medium Severity low
: rc
: ---
Assigned To: Karsten Hopp
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-08-22 13:43 EDT by pr-rhat
Modified: 2013-04-12 15:51 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-06-22 13:27:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description pr-rhat 2008-08-22 13:43:18 EDT
Description of problem:

/etc/profile.d/*sh files for krb5-devel, krb5-workstation, vim-enhanced, and probably other packages make the incorrect assumption that `id -u` always returns something other than ''


Version-Release number of selected component (if applicable):

krb5-devel-1.6.1-25.el5
krb5-workstation-1.6.1-25.el5
vim-enhanced-7.0.109-3.el5.3


How reproducible:

See bug 448014 for one set of events causing the bug to be reproduced.

Steps to Reproduce:
1.
2.
3.
  
Actual results:

.sh file errors out with 
'-bash: [: -le: unary operator expected'

Expected results:

No output


Additional info:

The root cause of this bug are incorrectly written .sh files.

They use the construct 
[ `/usr/bin/id -u` = 0 ] 
and
[ `/usr/bin/id -u` -le 100 ]

The proper construct to guarantee enough parameters to the '[' shell builtin is
[ "$(/usr/bin/id -u)" = 0]
and
[ "$(/usr/bin/id -u" -le 100 ]

Thanks,
Chris Dukes
Comment 3 Karsten Hopp 2009-05-14 08:32:37 EDT
This construct won't work either as p.e.  '-le' doesn't accept an empty string
as an integer.
The correct fix is to check the value of id -u before using it. Please note that
I'm not setting the alias for security reasons when id -u returns nothing.

  tmpid=$(/usr/bin/id -u)
  [ "$tmpid" = "" ] && tmpid=0
  [ $tmpid -le 100 ] && return
Comment 7 errata-xmlrpc 2009-06-22 13:27:38 EDT
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-1117.html

Note You need to log in before you can comment on or make changes to this bug.