From: Michael Buesch <mb@bu3sch.de>
To: David Miller <davem@davemloft.net>
Cc: joe@perches.com, johannes@sipsolutions.net, netdev@vger.kernel.org
Subject: Re: [PATCH net-2.6.24] introduce MAC_FMT/MAC_ARG
Date: Wed, 29 Aug 2007 19:46:23 +0200 [thread overview]
Message-ID: <200708291946.24017.mb@bu3sch.de> (raw)
In-Reply-To: <20070828.155419.74563234.davem@davemloft.net>
On Wednesday 29 August 2007 00:54:19 David Miller wrote:
> From: Michael Buesch <mb@bu3sch.de>
> Date: Tue, 28 Aug 2007 16:48:44 +0200
>
> > On Monday 27 August 2007 23:11:50 David Miller wrote:
> > > From: Joe Perches <joe@perches.com>
> > > Date: Mon, 27 Aug 2007 13:57:42 -0700
> > >
> > > > On Mon, 2007-08-27 at 13:41 -0700, David Miller wrote:
> > > > > From: Johannes Berg <johannes@sipsolutions.net>
> > > > > Date: Mon, 27 Aug 2007 12:54:09 +0200
> > > > > > #define MAC_FMT "%s"
> > > > > > #define MAC_ARG(a) ({char __buf[18]; print_mac(a, __buf); __buf;})
> > > >
> > > > > I don't think this works.
> > > >
> > > > $ cat test_fmt.c
> > > > #include <stdio.h>
> > > > #include <stdlib.h>
> > >
> > > You're just getting lucky in this test case.
> > >
> > > The language does not allow what you are doing, so you're
> > > playing with fire.
> >
> > What exactly to you think it invalid in this code?
> > I think it's fine (except that I'd chose an u8* for the mac
> > address (first arg in print_mac()).
>
> The __buf[] is used out of scope, therefore it's stack space is
> fair game for the compiler to reuse.
>
> When the compiler sees:
>
> printk(FMT, ({ char __buf[x]; print_mac(a, __buf); __buf;}));
>
> It first all of the printk() argument expressions, first FMT and
> then it evaluates the ({ ... }) argument.
>
> Now that the ({ ... }) expression is done, __buf[] is out of
> scope and illegal to reference.
>
> printk() is now called, with a pointer to an out-of-scope buffer.
> This is illegal.
>
> I don't know how else to explain this to you, I can learn how to
> describe the issue in German if this would help :-)
Oh, not needed. I see the bug and indeed, this is a ticking
timebomb.
I don't use the ({}) notation a lot, so I didn't see this here.
--
Greetings Michael.
next prev parent reply other threads:[~2007-08-29 17:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-22 18:46 [PATCH net-2.6.24] introduce MAC_FMT/MAC_ARG Johannes Berg
2007-08-23 16:01 ` Joe Perches
2007-08-23 16:12 ` Johannes Berg
2007-08-23 17:08 ` John W. Linville
2007-08-25 6:14 ` David Miller
2007-08-26 0:09 ` Joe Perches
2007-08-27 10:54 ` Johannes Berg
2007-08-27 15:44 ` Joe Perches
2007-08-27 20:41 ` David Miller
[not found] ` <1188248263.18004.131.camel@localhost>
2007-08-27 21:09 ` Stephen Hemminger
2007-08-27 21:11 ` David Miller
[not found] ` <200708281648.44352.mb@bu3sch.de>
[not found] ` <20070828.155419.74563234.davem@davemloft.net>
2007-08-29 17:46 ` Michael Buesch [this message]
2007-08-27 21:26 ` Joe Perches
2007-08-27 21:37 ` David Miller
[not found] ` <1188335521.6062.56.camel@localhost>
[not found] ` <20070828.142216.99461544.davem@davemloft.net>
2007-08-31 22:16 ` Joe Perches
2007-08-31 22:21 ` Johannes Berg
2007-08-31 22:24 ` Joe Perches
2007-08-31 22:27 ` Johannes Berg
2007-08-31 22:32 ` Johannes Berg
2007-08-31 22:39 ` Joe Perches
2007-09-14 19:41 ` Joe Perches
2007-09-14 19:48 ` David Miller
2007-09-18 2:05 ` David Miller
2007-09-18 2:14 ` Joe Perches
2007-09-19 4:50 ` Joe Perches
2007-09-19 18:11 ` David Miller
2007-09-19 18:50 ` Joe Perches
2007-09-19 19:54 ` David Miller
2007-09-24 17:28 ` Joe Perches
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=200708291946.24017.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=davem@davemloft.net \
--cc=joe@perches.com \
--cc=johannes@sipsolutions.net \
--cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.