• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [OT] What kind of data is is returned by 'new' ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] What kind of data is is returned by 'new' ?


  • Subject: Re: [OT] What kind of data is is returned by 'new' ?
  • From: Mark Bessey <email@hidden>
  • Date: Wed, 6 Jul 2005 14:11:39 -0700

On Jul 6, 2005, at 12:35 PM, Dirk Stegemann wrote:

If I recall correctly, Mac OS X provides a security feature to wipe memory pages allocated by a process; is this true?

Yes - all pages allocated to your process are zero-filled by the OS when they're first mapped in. You can't really depend on this in any useful way though - see below.

When I allocate a buffer using

{
    char* buffer = new char [numberOfBytes];
}

then the buffer seems to contain random data.

Has this data advertantly been made "random" or is it some remaining "valid" data leftover from previous processes which should be considered an security issue?

This is because this memory has previously been allocated to and written on by your process. The heap that "new" allocates out of is re-used as you allocate and free memory. This is not normally a security issue, unless your process handles data for multiple users (if you're a server process, for example). It can certainly be a correctness issue if you don't initialize the buffer before using it, however.

Are there runtime / compile options to get "wiped" memory buffers by a call to 'new'?

Maybe someone more familiar with C++ can answer this - in C, the answer would be to use calloc() instead of malloc(). In C++, you should of course have constructors defined for all your classes that initialize them to valid states when they're allocated, but for arrays of plain data types, I think you'll have to set the elements explicitly. In the exact case you gave, memset() could be used to clear your buffer after allocating it. I think you can also redefine the global operator new[], but that's very heavy-handed, and most likely redundant for most of your memory allocations.

-Mark

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [OT] What kind of data is is returned by 'new' ?
      • From: Dirk Stegemann <email@hidden>
References: 
 >[OT] What kind of data is is returned by 'new' ? (From: Dirk Stegemann <email@hidden>)

  • Prev by Date: Re: Tracking down type mismatches
  • Next by Date: Re: gcc-3.3:linking against gcc-4.0 linked framework
  • Previous by thread: [OT] What kind of data is is returned by 'new' ?
  • Next by thread: Re: [OT] What kind of data is is returned by 'new' ?
  • Index(es):
    • Date
    • Thread