public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/47642] real(kind=16) - libquadmath - segfault on amd64 FreeBSD
Date: Tue, 08 Feb 2011 12:54:00 -0000	[thread overview]
Message-ID: <bug-47642-4-JGdKHCNZaI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-47642-4@http.gcc.gnu.org/bugzilla/>

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47642

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-02-08 12:50:44 UTC ---
    size_t l = c - p;
    memcpy (res + 3, p + 1, l);
    size_t l2 = strlen (c + 1);
    memcpy (res + 2 + l, c + 1, l2);
    memset (res + 2 + l + l2, '0', n - (l + l2) + 1);

p is "174224571863520493293247799005065324265470", thus l is 42, l2 is 0
and n - (l + l2) + 1 is -1.

quadmath_io.c has more issues though, e.g.
void
quadmath_flt128tostr (char *s, size_t size, size_t n, __float128 x)
{
  char buffer[1024];
  memset (buffer, 0, sizeof(buffer));
  format (buffer, x, n);
  memcpy (s, buffer, size);
}
will happily copy garbage over for size > 1024, other buffer overflows will
happen for n > 1024 - epsilon, etc. and there is no reason why we need so many
extra buffers.  At least the one in quadmath_flt128tostr doesn't make sense,
size should be simply passed through down to format and it should make sure it
never overflows the given size.  The other memset in format:
memset (buffer, 0, sizeof(buffer));
should be avoided too, I believe g_Qfmt should return the pointer after the
last character it wrote, or NULL, so for NULL the caller should just clear
buffer[0] and for other value it should clear *g_Qfmt.


  parent reply	other threads:[~2011-02-08 12:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-08  9:56 [Bug fortran/47642] New: " mexas at bristol dot ac.uk
2011-02-08 10:44 ` [Bug fortran/47642] " dominiq at lps dot ens.fr
2011-02-08 12:51 ` jvdelisle at gcc dot gnu.org
2011-02-08 12:54 ` jakub at gcc dot gnu.org [this message]
2011-02-08 13:37 ` jvdelisle at gcc dot gnu.org
2011-02-08 14:06 ` jakub at gcc dot gnu.org
2011-02-08 18:28 ` burnus at gcc dot gnu.org
2011-02-08 20:25 ` jvdelisle at gcc dot gnu.org
2011-02-09  0:54 ` mexas at bristol dot ac.uk
2011-02-09  9:03 ` jakub at gcc dot gnu.org
2011-02-12 12:03 ` jakub at gcc dot gnu.org
2011-02-12 12:07 ` jakub at gcc dot gnu.org
2011-02-12 12:08 ` jakub at gcc dot gnu.org
2011-02-12 12:10 ` jakub at gcc dot gnu.org
2011-02-12 12:49 ` jakub at gcc dot gnu.org
2011-02-12 14:57 ` jakub at gcc dot gnu.org
2011-02-14 11:52 ` dominiq at lps dot ens.fr
2011-02-14 11:57 ` jakub at gcc dot gnu.org
2011-02-14 12:56 ` dominiq at lps dot ens.fr
2011-02-14 14:34 ` jakub at gcc dot gnu.org
2011-02-14 15:35 ` dominiq at lps dot ens.fr
2011-02-14 15:45 ` jakub at gcc dot gnu.org
2011-02-17 13:42 ` jakub at gcc dot gnu.org
2011-02-17 14:25 ` jakub at gcc dot gnu.org
2014-04-16 15:46 ` mexas at bristol dot ac.uk
2014-04-17  6:53 ` ubizjak at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-47642-4-JGdKHCNZaI@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).