Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 488920 - sys-libs/uclibc-0.9.33.2-r4: sscanf/fscanf mishandles %[x-y] conversion
Summary: sys-libs/uclibc-0.9.33.2-r4: sscanf/fscanf mishandles %[x-y] conversion
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-21 17:51 UTC by Claudio Calvelli
Modified: 2013-10-21 18:08 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Calvelli 2013-10-21 17:51:38 UTC
sscanf/fscanf handles "%number[range]" conversion wrongly, as seen from the following:

#include <stdio.h>
int main(void) {
  char line[] = "abcde-";
  char s1[11] = "?", s2[11] = "?";
  int n1, n2;
  n1 = sscanf(line, "%10[abcdefghi]", s1);
  n2 = sscanf(line, "%10[a-i]", s2);
  printf("n1=%d s1=<%s>\n", n1, s1);
  printf("n2=%d s2=<%s>\n", n2, s2);
  return 0;
}

The two sscanf() should have the same result but they don't: the first one works as expected, storing "abcde" in s1, the second one leaves "?" in s2; both return 1 suggesting that the conversion happened, so leaving s2 unchanged is definitely wrong.

Compiling against glibc (as well as libc from other systems e.g. NetBSD) produces the expected result: both s1 and s2 get "abcde", so it looks like this is a uclibc-specific issue. Further investigation shows that the problem was introduced by patch 04_all_stdio-m-format-2.patch -- see "additional details" for full information about that.

Reproducible: Always

Steps to Reproduce:
1.copy above code to a file code.c
2.gcc -o code code.c
3../code
Actual Results:  
n1=1 s1=<abcde>
n2=1 s2=<?>

Expected Results:  
n1=1 s1=<abcde>
n2=1 s2=<abcde>

This was observed on a system freshly installed from stage3-amd64-uclibc-hardened-20131005.tar.bz2 -- but persisted after rebuilding uclibc and even after an "emerge -e world".

This happens only when using the gentoo patches to uclibc i.e. the uclibc installed by "emerge sys-libs/uclibc" -- linking against a library built from the original sources does not have the problem.  For example:

$ cd /tmp
$ tar xvf uClibc-0.9.33.2.tar.bz2
$ cd uClibc-0.9.33.2.tar.bz2
$ cp /etc/portage/savedconfig/sys-libs/uclibc-0.9.33.2-r4 .config
$ make oldconfig
$ make

now the program has different results whether one uses the just-built uclibc, or the one installed by emerge:

$ cd /tmp
$ gcc -ocode code.c
$ ./code
n1=1 s1=<abcde>
n2=1 s2=<?>
$ LD_LIBRARY_PATH=/tmp/uClibc-0.9.33.2/lib/ ./code
n1=1 s1=<abcde>
n2=1 s2=<abcde>

This suggests that the problem has been introduced by one of the patches, and further investigation shows that the issue has been introduced by 04_all_stdio-m-format-2.patch (sorry I can't figure out why it introduced it, but applying all other patches except this one still results in the correct behaviour, so that implies that the patch introduced the problem).

This issue is observable with the unmodified stage3 tarball (it is also noticeable when "netstat -tn" shows 0.0.0.0 instead of any IP address, this is because the *scanf of /proc/net/tcp fails).  However, here's my current output from "emerge --info" in case it makes a difference:

Portage 2.2.7 (hardened/linux/uclibc/amd64, gcc-4.7.3, uclibc-0.9.33.2-r4, 3.11.6 x86_64)
=================================================================
System uname: Linux-3.11.6-x86_64-Intel-R-_Core-TM-_i3-3220_CPU_@_3.30GHz-with-gentoo-2.2
KiB Mem:     2048160 total,   1419052 free
KiB Swap:    2097148 total,   2097148 free
Timestamp of tree: Mon, 21 Oct 2013 00:45:01 +0000
ld GNU ld (GNU Binutils) 2.23.1
app-shells/bash:          4.2_p45
dev-lang/python:          2.7.5-r3, 3.2.5-r3
dev-util/pkgconfig:       0.28
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.11.8
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.69
sys-devel/automake:       1.13.4
sys-devel/binutils:       2.23.1
sys-devel/gcc:            4.7.3-r1
sys-devel/gcc-config:     1.7.3
sys-devel/libtool:        2.4.2
sys-devel/make:           3.82-r4
sys-kernel/linux-headers: 3.9 (virtual/os-headers)
sys-libs/uclibc:          0.9.33.2-r4
Repositories: gentoo
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-gentoo-linux-uclibc"
CFLAGS="-O2 -march=native -mtune=native -pipe"
CHOST="x86_64-gentoo-linux-uclibc"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=native -mtune=native -pipe"
DISTDIR="/var/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs buildpkg config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://mirror.bytemark.co.uk/gentoo/ http://mirror.qubenet.net/mirror/gentoo/ http://www.mirrorservice.org/sites/www.ibiblio.org/gentoo/"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j1"
PKGDIR="/var/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--omit-dir-times"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/var/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://come-from.intercal.org.uk/gentoo-portage"
USE="amd64 cli cracklib crypt cxx dri fortran hardened iconv ipv6 mmx modules mudflap ncurses nptl pax_kernel pcre readline session sse sse2 ssl ssse3 uclibc unicode xattr zlib" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="uclibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_2" RUBY_TARGETS="ruby19 ruby18" USERLAND="GNU" VIDEO_CARDS="dummy fbdev v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, USE_PYTHON
Comment 1 Claudio Calvelli 2013-10-21 18:08:07 UTC
I see that unmasking a later version fixes this by removing one of the patches.  Sorry for the noise.