From owner-freebsd-chat Fri Feb 14 02:33:57 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id CAA23559 for chat-outgoing; Fri, 14 Feb 1997 02:33:57 -0800 (PST) Received: from relay.nuxi.com (nuxi.ucdavis.edu [128.120.37.176]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id CAA23554 for ; Fri, 14 Feb 1997 02:33:54 -0800 (PST) Received: from dragon.nuxi.com (reqf-098.ucdavis.edu [128.120.253.218]) by relay.nuxi.com (8.8.4/8.6.12) with ESMTP id CAA23640 for ; Fri, 14 Feb 1997 02:33:51 -0800 (PST) Received: (from obrien@localhost) by dragon.nuxi.com (8.8.5/8.7.3) id KAA02690; Fri, 14 Feb 1997 10:33:55 GMT Message-ID: <19970214023354.GX64728@dragon.nuxi.com> Date: Fri, 14 Feb 1997 02:33:54 -0800 From: obrien@NUXI.com (David O'Brien) To: freebsd-chat@freebsd.org Subject: Re: Trying to understand stack overflow References: <199702140448.OAA27909@ogre.devetir.qld.gov.au> X-Mailer: Mutt 0.60_p2-3,5,8-9 Mime-Version: 1.0 X-Disclaimer: Mutt Bites! Organization: The NUXI *BSD group X-PGP-Fingerprint: B7 4D 3E E9 11 39 5F A3 90 76 5D 69 58 D9 98 7A X-Pgp-Keyid: 34F9F9D5 In-Reply-To: <199702140448.OAA27909@ogre.devetir.qld.gov.au>; from Stephen McKay on Feb 14, 1997 14:48:06 +1000 Sender: owner-chat@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Stephen McKay writes: > > The function arguments are pushed onto the stack in reverse order, This is by convention only, and is quite implimentation specific. This is not required by the i386 architecture. Microsoft Pascal pushes arguments on the stack in call order. There is a requirement for the C language that variable length parameter lists be dealt with. Pushing things in reverse order is simply one way of dealing with it. Another would be to pass the number of args in a register (the small C compiler did this). With the reverse order method, you know that the first arg is pointed to by BP/EBP + x (where X is size of return address + frame info), and you "walk" the stack for each argument you access. Of course you need to know when to stop. Think about what happens when you have one too many "%s'" in your printf format... :-) -- -- David (obrien@NUXI.com -or- obrien@FreeBSD.org)