• 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: NSLog and [NSDictionary description], bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLog and [NSDictionary description], bug?


  • Subject: Re: NSLog and [NSDictionary description], bug?
  • From: Gwynne <email@hidden>
  • Date: Tue, 6 Apr 2004 08:50:51 -0400

On Apr 6, 2004, at 8:16 AM, Stiphane Sudre wrote:
- when I do NSLog(@"%@",myDictionary); it works too (there is no %@ in the dictionary objects).
%@ is not the only placeholder. Are you absolutely 100% sure that it does not contain other placeholders?
The only object with a % is a NSString which contains "50% S".

But another dictionary with a "60% o" string is working. I don't see why it would work in that case and not in the other.

% S, interpreted loosely, means "read a wchar_t string from a pointer in the va_arg list until you find 0x0000", plus the space modifier which is ignored here. % o means "read an integer from the va_arg list and print it as an octal number", with the same modifier which is again ignored here.

Hence, what you have in both cases is va_arg() falling right off the end of the argument list, since there are no extra arguments, and reading whatever's next on the stack. With %o that's relatively harmless since it's not trying to dereference the value as a pointer (it'll just print junk), but with %s or %S it's disasterous.

Never, ever, ever, pass an arbitrary string whose contents you don't know as the format to NSLog(), printf(), sprintf(), fprintf(), or anything of that family. It's a security risk, it's bad form, and as proven here, it's likely as not to crash. This applies as much to Carbon or BSD code as to Cocoa.

-- Gwynne, key to the Code that runs us all
Formerly known as Sailor Quasar.
Email: email@hidden
Web: http://musicimage.plasticchicken.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: NSLog and [NSDictionary description], bug?
      • From: Alastair Houghton <email@hidden>
References: 
 >NSLog and [NSDictionary description], bug? (From: Stéphane Sudre <email@hidden>)
 >Re: NSLog and [NSDictionary description], bug? (From: Allan Odgaard <email@hidden>)
 >Re: NSLog and [NSDictionary description], bug? (From: Stéphane Sudre <email@hidden>)

  • Prev by Date: Re: NSLog and [NSDictionary description], bug?
  • Next by Date: Re: Scrolling Back Terminal Window
  • Previous by thread: Re: NSLog and [NSDictionary description], bug?
  • Next by thread: Re: NSLog and [NSDictionary description], bug?
  • Index(es):
    • Date
    • Thread