Bug#1059325: bash: printf does not recognise numeric constants with explicit base 10

2024-03-22 Thread Gioele Barabucci

Control: tags -1 moreinfo

On Fri, 22 Dec 2023 15:12:12 +0100 Francesco =?utf-8?Q?Potort=C3=AC?= 
 wrote:

Package: bash
Version: 5.2.21-2
Severity: normal
X-Debbugs-Cc: none, Francesco Potortì 

$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ echo $((10#08))
8

pot@pot:~$ printf %d\\n 10#08
bash: printf: 10#08: invalid number
10

This is clearly a bug: printf should print no error, and just print 8 followed 
by newline.


The rules that apply to printf arguments are not the same rules that 
apply to $(( )). Here "10#08" is a plain string that is not interpreted 
at all by bash nor printf. Only inside $(( )) and a few other cases, 
"10#08" will be interpreted as the representation of a number in base 10 
(this is a bashism, other shells do not do that).


From ARITHMETIC EVALUATION in bash(1):

The  shell allows arithmetic expressions to be evaluated, under 
certain circumstances (see the let and declare builtin commands, the 
(( compound command, and Arithmetic  Expansion).>


[...]

Integer constants follow the C language definition, without suffixes>
or  character  constants.   Constants with a leading 0 are 
interpreted as octal numbers.  A leading 0x or 0X denotes 
hexadecimal.  Otherwise, numbers take the form [base#]n, where the 
optional  base is  a  decimal number between 2 and 64 representing 
the arithmetic base, and n is a number in that base.  If base# is 
omitted, then base 10 is used.



However, this only happens on one of my two boxes with Debian
testing.  The other one does not exhibit the bug, and printf just
prints 8 followed by newline.

That's interesting. What version of bash is installed in the other boxes?

Regards,

--
Gioele Barabucci



Bug#1059325: bash: printf does not recognise numeric constants with explicit base 10

2023-12-22 Thread Francesco Potortì
Package: bash
Version: 5.2.21-2
Severity: normal
X-Debbugs-Cc: none, Francesco Potortì 

$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ echo $((10#08))
8

pot@pot:~$ printf %d\\n 10#08
bash: printf: 10#08: invalid number
10

This is clearly a bug: printf should print no error, and just print 8 followed 
by newline.  However, this only happens on one of my two boxes with Debian 
testing.  The other one does not exhibit the bug, and printf just prints 8 
followed by newline.

I tried with bash --login --noprofile, but nothing changes.

-- 
Francesco Potortì (ricercatore)Mobile: +39.348.8283.107
ISTI - Area della ricerca CNR  Skype:  wnlabisti
via G. Moruzzi 1, I-56124 Pisa Web:http://fly.isti.cnr.it
(gate 20, 1st floor, room C71) ISPIN:  https://ieee-jispin.org/


-- System Information:
Debian Release: trixie/sid
  APT prefers testing
  APT policy: (990, 'testing'), (101, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.5.0-4-amd64 (SMP w/24 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=C.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages bash depends on:
ii  base-files   13
ii  debianutils  5.14
ii  libc62.37-12
ii  libtinfo66.4+20231209-1

Versions of packages bash recommends:
ii  bash-completion  1:2.11-8

Versions of packages bash suggests:
ii  bash-doc  5.2.21-2

-- Configuration Files:
/etc/bash.bashrc changed:
[ -z "$PS1" ] && return
shopt -s checkwinsize
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
  fi
fi
if [ -x /usr/lib/command-not-found -o -x 
/usr/share/command-not-found/command-not-found ]; then
function command_not_found_handle {
# check because c-n-f could've been removed in the meantime
if [ -x /usr/lib/command-not-found ]; then
   /usr/lib/command-not-found -- "$1"
   return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
   /usr/share/command-not-found/command-not-found -- "$1"
   return $?
else
   printf "%s: command not found\n" "$1" >&2
   return 127
fi
}
fi
alias ls='ls --color=auto '
set -o emacs
eval "$(lessfile)"


-- no debconf information