FTBFS with FORTIFY_SOURCES

Bug #688730 reported by Dimitri John Ledkov
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
htmldoc (Ubuntu)
Fix Released
Undecided
Unassigned
Natty
Fix Released
Undecided
Unassigned
Quantal
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: htmldoc

See bug #687976 where I have discovered this.

bug #491310 maybe related.

Will attach backtrace.

Related branches

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Download full text (8.9 KiB)

:~/src/build-dir/htmldoc-1.8.27/doc$ gdb ../htmldoc/htmldoc
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc...done.
(gdb) run --datadir .. --strict --verbose --batch htmldoc.book -f htmldoc.ps
Starting program: /home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc --datadir .. --strict --verbose --batch htmldoc.book -f htmldoc.ps
[Thread debugging using libthread_db enabled]
INFO: Reading intro.html...
INFO: Reading 1-install.html...
INFO: Reading 2-starting.html...
INFO: Reading 3-books.html...
INFO: Reading 4-cmdline.html...
INFO: Reading 5-cgi.html...
INFO: Reading 6-htmlref.html...
INFO: Reading 7-guiref.html...
INFO: Reading 8-cmdref.html...
INFO: Reading a-license.html...
INFO: Reading b-book.html...
INFO: Reading c-relnotes.html...
INFO: Reading d-compile.html...
*** buffer overflow detected ***: /home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x50)[0x5f8990]
/lib/libc.so.6(+0xe488a)[0x5f788a]
/lib/libc.so.6(__strcpy_chk+0x44)[0x5f6c04]
/home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc[0x8077f17]
/home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc[0x808e337]
/home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc[0x8062a54]
/lib/libc.so.6(__libc_start_main+0xe7)[0x529ce7]
/home/tdlk/src/build-dir/htmldoc-1.8.27/htmldoc/htmldoc[0x804d8f1]
======= Memory map: ========
00110000-0012c000 r-xp 00000000 08:03 1310896 /lib/ld-2.12.1.so
0012c000-0012d000 r--p 0001b000 08:03 1310896 /lib/ld-2.12.1.so
0012d000-0012e000 rw-p 0001c000 08:03 1310896 /lib/ld-2.12.1.so
0012e000-0012f000 r-xp 00000000 00:00 0 [vdso]
0012f000-00173000 r-xp 00000000 08:03 1314308 /lib/libssl.so.0.9.8
00173000-00174000 r--p 00044000 08:03 1314308 /lib/libssl.so.0.9.8
00174000-00177000 rw-p 00045000 08:03 1314308 /lib/libssl.so.0.9.8
00177000-002a9000 r-xp 00000000 08:03 1314307 /lib/libcrypto.so.0.9.8
002a9000-002b1000 r--p 00131000 08:03 1314307 /lib/libcrypto.so.0.9.8
002b1000-002c0000 rw-p 00139000 08:03 1314307 /lib/libcrypto.so.0.9.8
002c0000-002c3000 rw-p 00000000 00:00 0
002c3000-003d7000 r-xp 00000000 08:03 3408816 /usr/lib/libX11.so.6.3.0
003d7000-003d8000 r--p 00113000 08:03 3408816 /usr/lib/libX11.so.6.3.0
003d8000-003da000 rw-p 00114000 08:03 3408816 /usr/lib/libX11.so.6.3.0
003da000-003db000 rw-p 00000000 00:00 0
003db000-003fe000 r-xp 00000000 08:03 1310812 /lib/libpng12.so.0.44.0
003fe000-003ff000 r--p 00022000 08:03 1310812 /lib/libpng12.so.0.44.0
003ff000-00400000 rw-p 00023000 08:03 1310812 /lib/libpng12.so.0.44.0
00400000-00413000 r-xp 00000000 08:03 1310780 /lib/libz.so.1.2.3.4
00413000-00414000 r--p 00012000 08:03 1310780 ...

Read more...

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

 8617 // Safe because buffer is allocated...
 8618 strcpy((char *)r->data.text.buffer, (char *)data);

Will investigate further =)

Revision history for this message
Dimitri John Ledkov (xnox) wrote :
Revision history for this message
StefanPotyra (sistpoty) wrote :

From a quick glimpse, the code should be correct.

What's happening here is that FORITFY_SOURCE will replace strcpy with a function similar to strncpy(.., .., target buffer size). Target buffer size is taken from the structure definition, and hence is 1 (buffer is uchar[1]). That's wrong, since the calloc on line 8593 has already allocated enough space.

Revision history for this message
StefanPotyra (sistpoty) wrote :

Kees, any good ideas?

Revision history for this message
Kees Cook (kees) wrote :

The problem is the use of "strcpy" instead of "strncpy". The code should be modified to include the expected malloced string size for such a strncpy call.

summary: - Buffer Overflow happens over it's own documentation when compiled with
- -O2
+ FTBFS with FORTIFY_SOURCES
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Hmm strncpy didn't work, but memcpy does. OpenSUSE had memcpy before me =) kudos to them. Branch ready to be merged and uploaded.

Revision history for this message
StefanPotyra (sistpoty) wrote :

patch looks good, but please document changing to use dh-autoreconf in changelog. I've added that prior to uploading.

Uploaded, thanks for your contribution.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package htmldoc - 1.8.27-4.1ubuntu1

---------------
htmldoc (1.8.27-4.1ubuntu1) natty; urgency=low

  * Fix FTBFS on natty (LP: #687976):
    - Added X11 to libs
    - Switch to dh-autoreconf
    - Make subdir makes fail the build
    - Use memcpy instead of strcpy, fixes FTBFS with FORTIFY (LP: #688730),
      patch from openSUSE same license as the package.
 -- Dmitrijs Ledkovs <email address hidden> Fri, 10 Dec 2010 14:27:39 +0000

Changed in htmldoc (Ubuntu):
status: New → Fix Released
Revision history for this message
Dave Walker (davewalker) wrote :

Was this patch ever pushed back to Debian?.. I can't see the bug.

Revision history for this message
StefanPotyra (sistpoty) wrote :

Partially: DBTS: #554803.

Also there's the upstream bug report, see comment 3.

I think it might be worthwhile to check if changing buffer to a variable sized array will lead to improvements (htmldoc/ps-pdf.cxx:205).

Revision history for this message
StefanPotyra (sistpoty) wrote :

Oh, forgot to mention, looking at debian source package 1.8.27-5 right now.

Dave Walker (davewalker)
Changed in htmldoc (Ubuntu Natty):
status: New → Fix Released
Changed in htmldoc (Ubuntu Quantal):
status: Fix Released → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package htmldoc - 1.8.27-8ubuntu1

---------------
htmldoc (1.8.27-8ubuntu1) quantal; urgency=low

   * debian/patches/strcpy-to-memcpy-fix-ftbfs.patch: Use memcpy instead of
     strcpy, resolves FTBFS when FORTIFY is used. Patch cherry picked from
     upstream tracker, based on previously directly applied changes to
     1.8.27-4.1ubuntu1. (LP: #688730)

htmldoc (1.8.27-8) unstable; urgency=low

  * Use dpkg-buildflags if available.
  * Update Standards-Version.

htmldoc (1.8.27-7) unstable; urgency=low

  * Add patch from upstream bug tracker to fix libpng 1.5 builds.
    Closes: #650562.

htmldoc (1.8.27-6) unstable; urgency=low

  * Add build-arch and build-indep to debian/rules per the
    (potential?) release goal for wheezy.
  * Update Standards-Version.

htmldoc (1.8.27-5) unstable; urgency=low

  * Acknowledge and pull in security team NMU. Closes: #537637.
  * Switch to 3.0 (quilt) source format, and separate patches.
  * Tweak build system to produce more useful information on build
    failures.
  * Build-Depend on libxpm-dev to fix a FTBFS with newer X11 dev packages.
    Closes: #554803.
  * Fix lintian warnings.
 -- Dave Walker (Daviey) <email address hidden> Thu, 17 May 2012 23:02:28 +0100

Changed in htmldoc (Ubuntu Quantal):
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.