Permalink
Browse files

Don’t crash with invalid values, such as malformed utf8.

  • Loading branch information...
alloy committed Oct 17, 2012
1 parent bcc376c commit 89ec7c90066f35bd03f5cd45c5072f67d01bf3fc
Showing with 11 additions and 1 deletion.
  1. +5 −1 ext/xcodeproj/xcodeproj_ext.c
  2. +6 −0 spec/xcodeproj_ext_spec.rb
@@ -103,7 +103,7 @@ hash_set(const void *keyRef, const void *valueRef, void *hash) {
} else {
CFStringRef descriptionRef = CFCopyDescription(elementRef);
- // obviously not optimial, but we're raising here, so it doesn't really matter
+ // obviously not optimal, but we're raising here, so it doesn't really matter
VALUE description = cfstr_to_str(descriptionRef);
rb_raise(rb_eTypeError, "Plist array value contains a object type unsupported by Xcodeproj. In: `%s'", RSTRING_PTR(description));
CFRelease(descriptionRef);
@@ -153,6 +153,10 @@ dictionary_set(st_data_t key, st_data_t value, CFMutableDictionaryRef dict) {
valueRef = str_to_cfstr(value);
}
+ if (valueRef == NULL) {
+ rb_raise(rb_eTypeError, "Unable to convert value of key `%s'.", RSTRING_PTR(rb_inspect(key)));
+ }
+
CFDictionaryAddValue(dict, keyRef, valueRef);
CFRelease(keyRef);
CFRelease(valueRef);
@@ -96,4 +96,10 @@ def o.to_hash; { 'from' => 'object' }; end
end
lambda { Xcodeproj.read_plist(@plist) }.should.raise TypeError
end
+
+ it "it raises if for whatever reason the value could not be converted to a CFTypeRef" do
+ lambda do
+ Xcodeproj.write_plist({ "invalid" => "\xCA" }, @plist)
+ end.should.raise TypeError
+ end
end

0 comments on commit 89ec7c9

Please sign in to comment.