glibc/stdio-common
Adhemerval Zanella 9b646f5dc9 elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263]
When an executable is invoked directly, we calculate $ORIGIN by calling
readlink on /proc/self/exe, which the Linux kernel resolves to the
target of any symlinks.  However, if an executable is run through ld.so,
we cannot use /proc/self/exe and instead use the path given as an
argument.  This leads to a different calculation of $ORIGIN, which is
most notable in that it causes ldd to behave differently (e.g., by not
finding a library) from directly running the program.

To make the behavior consistent, take advantage of the fact that the
kernel also resolves /proc/self/fd/ symlinks to the target of any
symlinks in the same manner, so once we have opened the main executable
in order to load it, replace the user-provided path with the result of
calling readlink("/proc/self/fd/N").

(On non-Linux platforms this resolution does not happen and so no
behavior change is needed.)

The __fd_to_filename requires _fitoa_word and _itoa_word, which for
32-bits pulls a lot of definitions from _itoa.c (due _ITOA_NEEDED
being defined).  To simplify the build move the required function
to a new file, _fitoa_word.c.

Checked on x86_64-linux-gnu and i686-linux-gnu.

Co-authored-by: Geoffrey Thomas <geofft@ldpreload.com>
Reviewed-by: Geoffrey Thomas <geofft@ldpreload.com>
Tested-by: Geoffrey Thomas <geofft@ldpreload.com>
2025-03-13 16:50:16 -03:00
..
bits
Depend
Makefile elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263] 2025-03-13 16:50:16 -03:00
Versions
Xprintf_buffer_done.c
Xprintf_buffer_flush.c
Xprintf_buffer_pad_1.c
Xprintf_buffer_putc_1.c
Xprintf_buffer_puts_1.c
Xprintf_buffer_write.c
Xprintf_function_invoke.c
_fitoa_word.c elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263] 2025-03-13 16:50:16 -03:00
_i18n_number.h
_itoa.c elf: Canonicalize $ORIGIN in an explicit ld.so invocation [BZ 25263] 2025-03-13 16:50:16 -03:00
_itowa.c
_itowa.h
asprintf.c
bug-vfprintf-nargs.c
bug1.c
bug1.input
bug2.c
bug3.c
bug4.c
bug5.c
bug6.c
bug6.input
bug7.c
bug8.c
bug9.c
bug10.c
bug11.c
bug12.c
bug13.c
bug14.c
bug16.c
bug17.c
bug18.c
bug18a.c
bug19.c
bug19a.c
bug20.c
bug21.c
bug22.c
bug23.c
bug24.c
bug25.c
bug26.c
bug27.c
bug28.c
bug29.c
ctermid.c
cuserid.c
dprintf.c
err_map.h
errlist-compat-data.h
errlist-data-gen.c
errlist-data.S
errlist.c
errname.c
errnobug.c
flockfile.c
fprintf.c
fscanf.c
ftrylockfile.c
funlockfile.c
fxprintf.c
gentempfd.c
getline.c
getw.c
grouping_iterator.c
grouping_iterator.h
iovfscanf.c
isoc23_fscanf.c
isoc23_scanf.c
isoc23_sscanf.c
isoc23_vfscanf.c
isoc23_vscanf.c
isoc23_vsscanf.c
isoc99_fscanf.c
isoc99_scanf.c
isoc99_sscanf.c
isoc99_vfscanf.c
isoc99_vscanf.c
isoc99_vsscanf.c
itoa-digits.c
itoa-udigits.c
itowa-digits.c
perror.c
printf-parse.h
printf-parsemb.c
printf-parsewc.c
printf-prs.c
printf.c
printf.h
printf_buffer-char.h
printf_buffer-wchar_t.h
printf_buffer_as_file.c
printf_buffer_as_file.h
printf_buffer_done.c
printf_buffer_flush.c
printf_buffer_pad_1.c
printf_buffer_putc_1.c
printf_buffer_puts_1.c
printf_buffer_to_file.c
printf_buffer_to_file.h
printf_buffer_write.c
printf_fp.c
printf_fphex.c
printf_function_invoke.c
printf_size.c
psiginfo-data.h
psiginfo-define.h
psiginfo.c
psignal.c
putw.c
reg-modifier.c
reg-printf.c
reg-type.c
remove.c
rename.c
renameat.c
renameat2.c
scanf.c
scanf1.c
scanf2.c
scanf3.c
scanf4.c
scanf5.c
scanf7.c
scanf8.c
scanf9.c
scanf10.c
scanf11.c
scanf12.c
scanf12.input
scanf13.c
scanf14.c
scanf15.c
scanf16.c
scanf17.c
scanf18.c
scanf19.c
siglist-gen.c
siglist.S
snprintf.c
sprintf.c
sscanf.c
stdio_ext.h
tempnam.c
tempname.c
temptest.c
test-fseek.c
test-fwrite.c
test-popen.c
test-strerr.c
test-vfprintf.c
test_rdwr.c
tfformat.c
tiformat.c
tllformat.c
tmpdir.c
tmpdir.h
tmpfile.c
tmpfile64.c
tmpnam.c
tmpnam_r.c
translated_number_width.c
tst-bz11319-fortify2.c
tst-bz11319.c
tst-cookie.c
tst-dprintf-length.c
tst-errno-manual.py
tst-fclose-offset.c Make fclose seek input file to right offset (bug 12724) 2025-01-28 20:22:56 +00:00
tst-fdopen.c
tst-fdopen2.c
tst-ferror.c
tst-ferror.input
tst-fflush-all-input.c Make fflush (NULL) flush input files (bug 32369) 2025-01-28 21:53:49 +00:00
tst-fflush-mmap.c Fix fflush handling for mmap files after ungetc (bug 32535) 2025-01-28 23:20:08 +00:00
tst-fgets.c
tst-fgets2.c
tst-fileno.c
tst-fmemopen.c
tst-fmemopen2.c
tst-fmemopen3.c
tst-fmemopen4.c
tst-fopen.c Add new tests for fopen 2025-01-28 12:50:50 -05:00
tst-fphex-wide.c
tst-fphex.c
tst-fread.c
tst-freopen2-main.c
tst-freopen2.c
tst-freopen3-main.c
tst-freopen3.c
tst-freopen4-main.c
tst-freopen4.c
tst-freopen5.c
tst-freopen6-main.c
tst-freopen6.c
tst-freopen7-main.c
tst-freopen7.c
tst-freopen64-2.c
tst-freopen64-3.c
tst-freopen64-4.c
tst-freopen64-6.c
tst-freopen64-7.c
tst-fseek-mmap.c Fix fseek handling for mmap files after ungetc or fflush (bug 32529) 2025-01-28 22:35:21 +00:00
tst-fseek.c
tst-fwrite-bz29459.c Increase the amount of data tested in stdio-common/tst-fwrite-bz29459.c 2025-02-14 15:46:38 -03:00
tst-fwrite-bz29459.sh libio: Start to return errors when flushing fwrite's buffer [BZ #29459] 2025-01-28 15:37:44 -03:00
tst-fwrite-memstrm.c
tst-fwrite-overflow.c
tst-fwrite-pipe.c Increase the amount of data tested in stdio-common/tst-fwrite-pipe.c 2025-02-24 14:45:55 +01:00
tst-fwrite-pos.c libio: Add a new fwrite test that evaluates partial writes 2025-01-28 15:37:44 -03:00
tst-fwrite-ro.c
tst-fwrite.c
tst-getline-enomem.c
tst-getline.c
tst-gets.c
tst-gets.input
tst-grouping.c
tst-grouping2.c
tst-grouping3.c
tst-grouping_iterator.c
tst-long-dbl-fphex.c
tst-memstream-string.c
tst-obprintf.c
tst-perror.c
tst-popen.c
tst-popen2.c
tst-popen3.c
tst-printf-binary-main.c
tst-printf-binary.c
tst-printf-bz18872.sh
tst-printf-bz25691.c
tst-printf-format-as-c.c
tst-printf-format-as-char.c
tst-printf-format-as-double.c
tst-printf-format-as-int.c
tst-printf-format-as-ldouble.c
tst-printf-format-as-llong.c
tst-printf-format-as-long.c
tst-printf-format-as-s.c
tst-printf-format-as-short.c
tst-printf-format-as-uchar.c
tst-printf-format-as-uint.c
tst-printf-format-as-ullong.c
tst-printf-format-as-ulong.c
tst-printf-format-as-ushort.c
tst-printf-format-as.h
tst-printf-format-c.sh
tst-printf-format-char.sh
tst-printf-format-d-c.c
tst-printf-format-d-char.c
tst-printf-format-d-double.c
tst-printf-format-d-int.c
tst-printf-format-d-ldouble.c
tst-printf-format-d-llong.c
tst-printf-format-d-long.c
tst-printf-format-d-s.c
tst-printf-format-d-short.c
tst-printf-format-d-uchar.c
tst-printf-format-d-uint.c
tst-printf-format-d-ullong.c
tst-printf-format-d-ulong.c
tst-printf-format-d-ushort.c
tst-printf-format-d.h
tst-printf-format-double.sh
tst-printf-format-f-c.c
tst-printf-format-f-char.c
tst-printf-format-f-double.c
tst-printf-format-f-int.c
tst-printf-format-f-ldouble.c
tst-printf-format-f-llong.c
tst-printf-format-f-long.c
tst-printf-format-f-s.c
tst-printf-format-f-short.c
tst-printf-format-f-uchar.c
tst-printf-format-f-uint.c
tst-printf-format-f-ullong.c
tst-printf-format-f-ulong.c
tst-printf-format-f-ushort.c
tst-printf-format-f.h
tst-printf-format-int.sh
tst-printf-format-ldouble.sh
tst-printf-format-llong.sh
tst-printf-format-long.sh
tst-printf-format-p-c.c
tst-printf-format-p-char.c
tst-printf-format-p-double.c
tst-printf-format-p-int.c
tst-printf-format-p-ldouble.c
tst-printf-format-p-llong.c
tst-printf-format-p-long.c
tst-printf-format-p-s.c
tst-printf-format-p-short.c
tst-printf-format-p-uchar.c
tst-printf-format-p-uint.c
tst-printf-format-p-ullong.c
tst-printf-format-p-ulong.c
tst-printf-format-p-ushort.c
tst-printf-format-p.h
tst-printf-format-s-c.c
tst-printf-format-s-char.c
tst-printf-format-s-double.c
tst-printf-format-s-int.c
tst-printf-format-s-ldouble.c
tst-printf-format-s-llong.c
tst-printf-format-s-long.c
tst-printf-format-s-s.c
tst-printf-format-s-short.c
tst-printf-format-s-uchar.c
tst-printf-format-s-uint.c
tst-printf-format-s-ullong.c
tst-printf-format-s-ulong.c
tst-printf-format-s-ushort.c
tst-printf-format-s.h
tst-printf-format-s.sh
tst-printf-format-short.sh
tst-printf-format-skeleton-c.c
tst-printf-format-skeleton-char.c
tst-printf-format-skeleton-double.c
tst-printf-format-skeleton-int.c
tst-printf-format-skeleton-ldouble.c
tst-printf-format-skeleton-llong.c
tst-printf-format-skeleton-long.c
tst-printf-format-skeleton-s.c
tst-printf-format-skeleton-short.c
tst-printf-format-skeleton-uchar.c
tst-printf-format-skeleton-uint.c
tst-printf-format-skeleton-ullong.c
tst-printf-format-skeleton-ulong.c
tst-printf-format-skeleton-ushort.c
tst-printf-format-skeleton.c
tst-printf-format-sn-c.c
tst-printf-format-sn-char.c
tst-printf-format-sn-double.c
tst-printf-format-sn-int.c
tst-printf-format-sn-ldouble.c
tst-printf-format-sn-llong.c
tst-printf-format-sn-long.c
tst-printf-format-sn-s.c
tst-printf-format-sn-short.c
tst-printf-format-sn-uchar.c
tst-printf-format-sn-uint.c
tst-printf-format-sn-ullong.c
tst-printf-format-sn-ulong.c
tst-printf-format-sn-ushort.c
tst-printf-format-sn.h
tst-printf-format-uchar.sh
tst-printf-format-uint.sh
tst-printf-format-ullong.sh
tst-printf-format-ulong.sh
tst-printf-format-ushort.sh
tst-printf-format-v-c.c
tst-printf-format-v-char.c
tst-printf-format-v-double.c
tst-printf-format-v-int.c
tst-printf-format-v-ldouble.c
tst-printf-format-v-llong.c
tst-printf-format-v-long.c
tst-printf-format-v-s.c
tst-printf-format-v-short.c
tst-printf-format-v-uchar.c
tst-printf-format-v-uint.c
tst-printf-format-v-ullong.c
tst-printf-format-v-ulong.c
tst-printf-format-v-ushort.c
tst-printf-format-v.h
tst-printf-format-vas-c.c
tst-printf-format-vas-char.c
tst-printf-format-vas-double.c
tst-printf-format-vas-int.c
tst-printf-format-vas-ldouble.c
tst-printf-format-vas-llong.c
tst-printf-format-vas-long.c
tst-printf-format-vas-s.c
tst-printf-format-vas-short.c
tst-printf-format-vas-uchar.c
tst-printf-format-vas-uint.c
tst-printf-format-vas-ullong.c
tst-printf-format-vas-ulong.c
tst-printf-format-vas-ushort.c
tst-printf-format-vas.h
tst-printf-format-vd-c.c
tst-printf-format-vd-char.c
tst-printf-format-vd-double.c
tst-printf-format-vd-int.c
tst-printf-format-vd-ldouble.c
tst-printf-format-vd-llong.c
tst-printf-format-vd-long.c
tst-printf-format-vd-s.c
tst-printf-format-vd-short.c
tst-printf-format-vd-uchar.c
tst-printf-format-vd-uint.c
tst-printf-format-vd-ullong.c
tst-printf-format-vd-ulong.c
tst-printf-format-vd-ushort.c
tst-printf-format-vd.h
tst-printf-format-vf-c.c
tst-printf-format-vf-char.c
tst-printf-format-vf-double.c
tst-printf-format-vf-int.c
tst-printf-format-vf-ldouble.c
tst-printf-format-vf-llong.c
tst-printf-format-vf-long.c
tst-printf-format-vf-s.c
tst-printf-format-vf-short.c
tst-printf-format-vf-uchar.c
tst-printf-format-vf-uint.c
tst-printf-format-vf-ullong.c
tst-printf-format-vf-ulong.c
tst-printf-format-vf-ushort.c
tst-printf-format-vf.h
tst-printf-format-vs-c.c
tst-printf-format-vs-char.c
tst-printf-format-vs-double.c
tst-printf-format-vs-int.c
tst-printf-format-vs-ldouble.c
tst-printf-format-vs-llong.c
tst-printf-format-vs-long.c
tst-printf-format-vs-s.c
tst-printf-format-vs-short.c
tst-printf-format-vs-uchar.c
tst-printf-format-vs-uint.c
tst-printf-format-vs-ullong.c
tst-printf-format-vs-ulong.c
tst-printf-format-vs-ushort.c
tst-printf-format-vs.h
tst-printf-format-vsn-c.c
tst-printf-format-vsn-char.c
tst-printf-format-vsn-double.c
tst-printf-format-vsn-int.c
tst-printf-format-vsn-ldouble.c
tst-printf-format-vsn-llong.c
tst-printf-format-vsn-long.c
tst-printf-format-vsn-s.c
tst-printf-format-vsn-short.c
tst-printf-format-vsn-uchar.c
tst-printf-format-vsn-uint.c
tst-printf-format-vsn-ullong.c
tst-printf-format-vsn-ulong.c
tst-printf-format-vsn-ushort.c
tst-printf-format-vsn.h
tst-printf-format.awk
tst-printf-format.sh
tst-printf-fp-free.c
tst-printf-fp-leak.c
tst-printf-intn-main.c
tst-printf-intn.c
tst-printf-oct.c
tst-printf-round.c
tst-printf.c
tst-printf.sh
tst-printfsz-islongdouble.c
tst-printfsz-islongdouble.sh
tst-printfsz.c
tst-put-error.c
tst-read-offset.c Add test of input file flushing / offset issues 2025-01-28 23:39:12 +00:00
tst-renameat2.c
tst-rndseek.c
tst-scanf-binary-c11.c
tst-scanf-binary-c23.c
tst-scanf-binary-gnu11.c
tst-scanf-binary-gnu89.c
tst-scanf-binary-main.c
tst-scanf-bz27650.c
tst-scanf-intn-main.c
tst-scanf-intn.c
tst-scanf-nan.c
tst-scanf-round.c
tst-scanf-to_inpunct.c
tst-setvbuf1.c
tst-setvbuf1.expect
tst-sprintf-errno.c
tst-sprintf.c
tst-sprintf2.c
tst-sprintf3.c
tst-sscanf.c
tst-swprintf.c
tst-swscanf.c
tst-tmpnam.c
tst-unbputc.c
tst-unbputc.sh
tst-ungetc-fflush.c Fix fflush after ungetc on input file (bug 5994) 2025-01-28 19:38:27 +00:00
tst-ungetc-leak.c
tst-ungetc-nomem.c
tst-ungetc.c
tst-unlockedio.c
tst-vfprintf-mbs-prec.c
tst-vfprintf-user-type.c
tst-vfprintf-width-i18n.c
tst-vfprintf-width-prec-alloc.c
tst-vfprintf-width-prec.c
tst-wc-printf.c
tstdiomisc.c
tstgetln.c
tstgetln.input
tstscanf.c
tstscanf.input
vfprintf-internal.c
vfprintf-process-arg.c
vfprintf.c
vfscanf-internal.c
vfscanf.c
vfwprintf-internal.c
vfwprintf.c
vfwscanf-internal.c
vfwscanf.c
vprintf.c
wprintf_buffer_as_file.c
wprintf_buffer_done.c
wprintf_buffer_flush.c
wprintf_buffer_pad_1.c
wprintf_buffer_putc_1.c
wprintf_buffer_puts_1.c
wprintf_buffer_to_file.c
wprintf_buffer_write.c
wprintf_function_invoke.c
xbug.c