From: "Dmitry V. Levin" <ldv@altlinux.org>
To: ALT Linux Team development discussions <devel@lists.altlinux.org>
Subject: Re: [devel] [SCM] packages/gnupg2: heads/master
Date: Wed, 15 Jul 2009 02:51:19 +0400
Message-ID: <20090714225119.GC9973@wo.int.altlinux.org> (raw)
In-Reply-To: <20090714173734.GA11410@ubuntu>
[-- Attachment #1: Type: text/plain, Size: 1670 bytes --]
On Tue, Jul 14, 2009 at 09:37:34PM +0400, Vladimir Lettiev wrote:
> On Tue, Jul 14, 2009 at 02:54:16PM +0400, Dmitry V. Levin wrote:
> > On Tue, Jul 14, 2009 at 01:46:56PM +0400, Sergey V. Turchin wrote:
> > > --- /dev/null
> > > +++ b/gnupg-2.0.12-alt-fix-possible-overflow.patch
> > > @@ -0,0 +1,11 @@
> > > +--- gnupg-2.0.12/g10/keygen.c~ 2009-07-13 17:27:14 +0400
> > > ++++ gnupg-2.0.12/g10/keygen.c 2009-07-14 13:33:08 +0400
> > > +@@ -85,7 +85,7 @@ struct para_data_s {
> > > + u32 creation;
> > > + unsigned int usage;
> > > + struct revocation_key revkey;
> > > +- char value[1];
> ^^^^^^^^^^^^^
> > > ++ char value[21];
> > > + } u;
> > > + };
> > > +
> >
> > После этого изменения gnupg2 начнёт падать.
>
> Как я понимаю, это очень популярный приём для создания поля переменной длины в структуре.
Насчёт того, что это очень популярный приём, я не уверен, но то что этот
метод хорошо известен в узких кругах, это точно.
> Память выделяется как сумма sizeof(структура)+strlen(данные), а потом в поле, которое
> объявлено размером в один байт загоняются данные большей длины и это срабатывает т.к.
> памяти выделенно достаточно, хотя с точки зрения компилятора будет переполнение.
>
> Как теперь быть? Какой правильный путь решения такой задачи?
Задача в описанной вами форме (поле переменной длины в конце структуры)
решается с помощью массива переменной длины (flexible array member).
Но в gnupg/g10/keygen.c поле переменной длины помещено в union, который
помещён в структуру, а стандарт С не позволяет помещать flexible array
member в union.
--
ldv
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2009-07-14 22:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-14 10:54 ` Dmitry V. Levin
2009-07-14 14:56 ` Sergey V Turchin
2009-07-14 10:57 ` Dmitry V. Levin
2009-07-14 15:07 ` Sergey V Turchin
2009-07-14 17:37 ` Vladimir Lettiev
2009-07-14 18:29 ` Ivan A. Melnikov
2009-07-14 18:34 ` Led
2009-07-14 22:51 ` Dmitry V. Levin [this message]
2009-08-18 22:47 ` Dmitry V. Levin
2009-08-18 22:51 ` Dmitry V. Levin
2009-08-19 9:17 ` Michael Shigorin
2009-08-19 12:49 ` Dmitry V. Levin
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=20090714225119.GC9973@wo.int.altlinux.org \
--to=ldv@altlinux.org \
--cc=devel@lists.altlinux.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
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git