[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command substitution with null bytes generates warning

From: L. A. Walsh
Subject: Re: Command substitution with null bytes generates warning
Date: Tue, 20 Sep 2016 12:17:37 -0700
User-agent: Thunderbird

Greg Wooledge wrote:
I probably shouldn't even bother at this point, but morbid curiosity
compels me to foolish ends.

What are you DOING with these files that contain NUL bytes that makes
it permissible to simply drop the NUL bytes on the floor, with no
explicit step like tr -d \\0 to remove them?
Usually to write a quick & dirty 1-off script to read something
and give me some info.

If I want to improve upon it or have it handle the null data better,
I'd probably use perl.  But as an example see attached.  I've had a few
versions of this script (this one is dated 2011).
If you run it in a dir where there is binary
data, you are almost certain to see have some nulls in the data.

I used something this script to look at values in /proc or /sys.
Run as a normal user -- I get many unreadables, but enough interesting
things to help me understand what to do and how to use some of the values:

/sys/class/net/br0> /tmp/showvals
addr_assign_type:              1
addr_len:                      6
address:                       00:15:17:bf:be:b2
/tmp/showvals: line 63: printf: `invalid format character
brforward: '`f#สง 7ridge/ageing_time: 30000
bridge/bridge_id:              8000.001517bfbeb2
bridge/default_pvid:           1
bridge/flush:                  <Unreadable>
bridge/forward_delay:          1500
bridge/gc_timer:               23319
bridge/group_addr:             1:80:c2:0:0:0
bridge/group_fwd_mask:         0x0
bridge/hash_elasticity:        4
bridge/hash_max:               512
bridge/hello_time:             200
bridge/hello_timer:            0
bridge/max_age:                2000
etc... brforward sure looks like binary, for example.

One can do the same on windows in /proc/registry (in cygwin) --
lots of binary values  that display just fine, in spite of dropping
This is just 1 example...But since these are knockoff scripts, I often
don't remember how/where to find them ... this one was by luck, last
modified ~ 5 years ago.

How is your script anything but buggy, if it is relying on a program
(shell) to drop certain input bytes, when there is no documentation
stating that it does this?
How is it buggy?  ... works fine for the listed requirements! ;-)

Remember What I said about you being "too advanced" to relate to
some of these things: case in point.  ;-)


# designed for displaying config vals stored in files;
# recursively display values (or 1st line) of files in cur dir
# or given on cmd line;  
# dirs given or below targets will be expanded;
# (c) 2011 L. Walsh (address@hidden); 
# License: copy and distribute freely, but for this source:
#   * leave attribution on unmodified or slightly modified copies. (OR)
#               * leave 'honorable mention' if this is > 30% of any final work 
#   * Else, Do as thow wilt... and enjoy!
#       (Hopefully, that's not too onerous a license...)

# this is writtin 'split', so if one wants auto-priv-raising,
# it can be done once and not on every recursive call

# If you want to force root to be used when running this
# instead of raising privs as needed, written / split this file can be 
'sourced' and the function
# will define to mem and so if 'sudo' is needed

# to prevent automatically trying sudo, uncomment next line

sudop=$([[ -n $USE_SUDO && ! -n $_SUDO ]] && echo '/usr/bin/sudo')
shopt -s expand_aliases extglob
getfacl=$(type -P getfacl)
if [[ -n $getfacl ]]; then
        function _showvals_tread {
                local fn=$1
                local -a acc
                readarray acc < <($getfacl  -c $fn)
                ans="$(echo ${acc[*]##*:*([^r])})"
                if [[ -n $ans ]]; then
                        return 0 
                        return 1
        function _showvals_tread {      #use broken test...
                test -r $1
export -f _showvals_tread
#type _showvals_tread

#export sudoed_showvals='
function showvals {
        local -i width=30
        for n in "address@hidden" ; do
                [[ -z $n || $n == \* ]] && return 0
                if [[ -d $n && ! -L $n ]] ; then
                        [[ $n == .  ]]  && return 0
                        (cd "$n"; shift; 
                                export prefx="${prefx:-""}${prefx:+/}$n"; 
shift; showvals * )
                elif [[ -f $n ]] ; then
                        if _showvals_tread "$n" ; then  
                                read -t .1 -r val <"$n"
                                printf -v  val -- "$val"
                        [[ -n "key" ]] && keylen=${#key}
                        width=$((width<keylen&&keylen<50 ? keylen : width))
                        printf  "%-*s %-.40s\n" "$width" "$key" "$val"
        return 0
export -f showvals
showvals  #'

function showvials {
        if [[ $EUID!=0  && -n "$_SUDO" ]]; then 
                (local s=$_SUDO; export -u _SUDO;  
                $s /bin/bash --norc -c "$sudoed_showvals \"address@hidden"" )
                eval "$sudoed_showvals $@"

export -f showvals

if [[ $EUID != 0 && -x /usr/bin/sudo ]]; then 
        if sudo grep "$(id -un)" /etc/sudoers &> /dev/null; then
                export _SUDO="$sudop"

hash -r &>/dev/null

if [[ $0 =~ showvals ]] ;then
        showvals ${@:-*}
        echo "(showvals defined)"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]