Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 May 2016 16:06:42 +0200
From:      Marko Turk <markoml@markoturk.info>
To:        twilight <pipfstarrd@openmailbox.org>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Bug with pointer corruption when assigning smth to dereferenced pointer (part of a structure)
Message-ID:  <20160509140642.GA2689@vps.markoturk.info>
In-Reply-To: <4b9ef7c8-20e2-a004-9f3a-0ee564179513@openmailbox.org>
References:  <4b9ef7c8-20e2-a004-9f3a-0ee564179513@openmailbox.org>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
On Mon, May 09, 2016 at 01:39:32PM +0000, twilight wrote:
> Hello!
> 
> When I were working on my FreeBSD-powered ThinkPad X200 I encounted a
> bug (not sure what causes that) that produced a segfault. After some
> investigation I were able to cut down the problem to such a small piece
> of code: https://ideone.com/VVtgpG.
> 
> As you can see on ideone, it works absolutely fine.
> But in my case I have:
> 
> ###############################
> In main we've got
> container->first: 0x801006060
> container->last 0x801006060
> container: 0x801006058
> 
> In main after change we've got
> container->first: 0x801006060
> container->last 0x800000005
> container: 0x801006058
> ###############################
> 
> 
> I've wondered if it's hardware related or compiler related, so at first
> I tried to compile with gcc and got the same result. Then, I tried to
> compile and run the same on Ubuntu Live USB (with gcc). Everything
> worked like a charm.
> 
> Here's the generated asm code: http://pastebin.com/8yRyk5nG.
> 
> Any suggestions where to submit the bug or what extra information to
> provide?

Hi,

you have a bug in your code:

Container *container = (Container*) malloc(sizeof(Container*));

This line will not malloc enough space for Container structure.

BR,
Marko

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJXMJlxAAoJEHg6bF2mqM2ImzgQALmW/oksaUP+/3t+ClmVE9IQ
hD70eLn3lrdoymZiuYx1NYqYYT4sSV8Tp5oXpA3Il42nIEsQPiS8UaoPrwAldbml
1LrC2gpACzyNAUZIGBho2f6vFxdX5RbGJ0ZI+glfsIRDvyewQU0j5gIT+VvFpf0j
DNop3ab14zFu41KtBt3rF7xciPTeE6MIn8AZkYPL8hBbahlz+6KkMsjBN3H7HbZB
vbwU5q9JsPyE3fbaDaY0csT/QmYSSU8UoOb589kamF2CAQLokkhn/mo2yACq6H1l
DAf240YOtxD8HK/V4I3aX7+H3dEqvGG7wTf08YoMJqJLZX3f5fsUmK3nyNRx7Ylx
EvAF0W8EcUjfTcahhIpTUVwhY4wNP3q6nNZSiEaxvsYfl+cynMW2Y8OwSEQ9cV+z
nrqdpKL+duUANfICabo0OWxtY9LGycxJALKJhtKnBhuN9rFnh5eATDH2/rnFqcQJ
9EWMVfcM7s7C5JtK1Y9buppyQKrgCTCH/712FjIUzVutTPWBiHaBwGW1BTTV6tx0
br+7EVKJYQfi6AG0So8y/D7UMjN47jm9GovGMqckTgyEzCOIMoj47yO2Br2O1LUe
zymPvGLSqzYnPMeQePuokUWkY+b/E6WTNke+wtLDGeWa+HwKMaYWhOhRIexzMDCI
yQ5RVl7ECuzrbm979p52
=04AC
-----END PGP SIGNATURE-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160509140642.GA2689>