Skip to content

Commit

Permalink
Don’t crash with invalid values, such as malformed utf8.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Oct 17, 2012
1 parent bcc376c commit 89ec7c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/xcodeproj/xcodeproj_ext.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions spec/xcodeproj_ext_spec.rb
Expand Up @@ -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.