From f346458f275f5e04087c6d2140db6c5f0eeb5ee3 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Mon, 23 Nov 2015 20:50:12 +0100 Subject: [PATCH] Ensure strings are zero terminated, where C-str pointers are expected. Ruby-2.2 changes the String handling in such a way, that strings can no longer be expected to be zero terminated. When zero terminated strings are expected in the C code, StringValueCStr() must be used. See: https://github.com/ruby/ruby/blob/v2_2_0/NEWS#L319 Using StringValuePtr() without a length check, can also become a security issue, because it can leak the memory after the string. This was already an issue in the pg.gem: https://github.com/ged/ruby-pg/pull/5 --- ext/nokogiri/html_document.c | 12 +++--- ext/nokogiri/html_element_description.c | 2 +- ext/nokogiri/html_entity_lookup.c | 2 +- ext/nokogiri/html_sax_parser_context.c | 8 ++-- ext/nokogiri/html_sax_push_parser.c | 4 +- ext/nokogiri/xml_attr.c | 4 +- ext/nokogiri/xml_comment.c | 2 +- ext/nokogiri/xml_document.c | 36 ++++++++-------- ext/nokogiri/xml_encoding_handler.c | 6 +-- ext/nokogiri/xml_entity_reference.c | 2 +- ext/nokogiri/xml_node.c | 52 +++++++++++------------ ext/nokogiri/xml_processing_instruction.c | 4 +- ext/nokogiri/xml_reader.c | 12 +++--- ext/nokogiri/xml_sax_parser.c | 4 +- ext/nokogiri/xml_sax_parser_context.c | 2 +- ext/nokogiri/xml_sax_push_parser.c | 2 +- ext/nokogiri/xml_schema.c | 2 +- ext/nokogiri/xml_text.c | 2 +- ext/nokogiri/xml_xpath_context.c | 12 +++--- ext/nokogiri/xslt_stylesheet.c | 12 +++--- 20 files changed, 91 insertions(+), 91 deletions(-) diff --git a/ext/nokogiri/html_document.c b/ext/nokogiri/html_document.c index 3e8e8ec7c83..5cf93a84137 100644 --- a/ext/nokogiri/html_document.c +++ b/ext/nokogiri/html_document.c @@ -18,8 +18,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) external_id = rb_ary_entry(rest, (long)1); doc = htmlNewDoc( - RTEST(uri) ? (const xmlChar *)StringValuePtr(uri) : NULL, - RTEST(external_id) ? (const xmlChar *)StringValuePtr(external_id) : NULL + RTEST(uri) ? (const xmlChar *)StringValueCStr(uri) : NULL, + RTEST(external_id) ? (const xmlChar *)StringValueCStr(external_id) : NULL ); rb_doc = Nokogiri_wrap_xml_document(klass, doc); rb_obj_call_init(rb_doc, argc, argv); @@ -39,8 +39,8 @@ static VALUE read_io( VALUE klass, VALUE encoding, VALUE options ) { - const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url); - const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding); + const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url); + const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding); VALUE error_list = rb_ary_new(); VALUE document; htmlDocPtr doc; @@ -103,8 +103,8 @@ static VALUE read_memory( VALUE klass, VALUE options ) { const char * c_buffer = StringValuePtr(string); - const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url); - const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding); + const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url); + const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding); int len = (int)RSTRING_LEN(string); VALUE error_list = rb_ary_new(); VALUE document; diff --git a/ext/nokogiri/html_element_description.c b/ext/nokogiri/html_element_description.c index 696ed9a5133..196757e99b8 100644 --- a/ext/nokogiri/html_element_description.c +++ b/ext/nokogiri/html_element_description.c @@ -245,7 +245,7 @@ static VALUE name(VALUE self) static VALUE get_description(VALUE klass, VALUE tag_name) { const htmlElemDesc * description = htmlTagLookup( - (const xmlChar *)StringValuePtr(tag_name) + (const xmlChar *)StringValueCStr(tag_name) ); if(NULL == description) return Qnil; diff --git a/ext/nokogiri/html_entity_lookup.c b/ext/nokogiri/html_entity_lookup.c index 56ca4fea7a6..c9f745550e3 100644 --- a/ext/nokogiri/html_entity_lookup.c +++ b/ext/nokogiri/html_entity_lookup.c @@ -9,7 +9,7 @@ static VALUE get(VALUE self, VALUE key) { const htmlEntityDesc * desc = - htmlEntityLookup((const xmlChar *)StringValuePtr(key)); + htmlEntityLookup((const xmlChar *)StringValueCStr(key)); VALUE klass, args[3]; if(NULL == desc) return Qnil; diff --git a/ext/nokogiri/html_sax_parser_context.c b/ext/nokogiri/html_sax_parser_context.c index 02172ad02a9..c75c5cb1f12 100644 --- a/ext/nokogiri/html_sax_parser_context.c +++ b/ext/nokogiri/html_sax_parser_context.c @@ -31,12 +31,12 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding) } if (RTEST(encoding)) { - xmlCharEncodingHandlerPtr enc = xmlFindCharEncodingHandler(StringValuePtr(encoding)); + xmlCharEncodingHandlerPtr enc = xmlFindCharEncodingHandler(StringValueCStr(encoding)); if (enc != NULL) { xmlSwitchToEncoding(ctxt, enc); if (ctxt->errNo == XML_ERR_UNSUPPORTED_ENCODING) { rb_raise(rb_eRuntimeError, "Unsupported encoding %s", - StringValuePtr(encoding)); + StringValueCStr(encoding)); } } } @@ -47,8 +47,8 @@ parse_memory(VALUE klass, VALUE data, VALUE encoding) static VALUE parse_file(VALUE klass, VALUE filename, VALUE encoding) { htmlParserCtxtPtr ctxt = htmlCreateFileParserCtxt( - StringValuePtr(filename), - StringValuePtr(encoding) + StringValueCStr(filename), + StringValueCStr(encoding) ); return Data_Wrap_Struct(klass, NULL, deallocate, ctxt); } diff --git a/ext/nokogiri/html_sax_push_parser.c b/ext/nokogiri/html_sax_push_parser.c index da28675ca3a..2df4532f10b 100644 --- a/ext/nokogiri/html_sax_push_parser.c +++ b/ext/nokogiri/html_sax_push_parser.c @@ -46,10 +46,10 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename, Data_Get_Struct(_xml_sax, xmlSAXHandler, sax); - if(_filename != Qnil) filename = StringValuePtr(_filename); + if(_filename != Qnil) filename = StringValueCStr(_filename); if (!NIL_P(encoding)) { - enc = xmlParseCharEncoding(StringValuePtr(encoding)); + enc = xmlParseCharEncoding(StringValueCStr(encoding)); if (enc == XML_CHAR_ENCODING_ERROR) rb_raise(rb_eArgError, "Unsupported Encoding"); } diff --git a/ext/nokogiri/xml_attr.c b/ext/nokogiri/xml_attr.c index 0863f61d3e7..ed5345a091f 100644 --- a/ext/nokogiri/xml_attr.c +++ b/ext/nokogiri/xml_attr.c @@ -20,7 +20,7 @@ static VALUE set_value(VALUE self, VALUE content) xmlNode *tmp; /* Encode our content */ - buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValuePtr(content)); + buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValueCStr(content)); attr->children = xmlStringGetNodeList(attr->doc, buffer); attr->last = NULL; @@ -61,7 +61,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) node = xmlNewDocProp( xml_doc, - (const xmlChar *)StringValuePtr(name), + (const xmlChar *)StringValueCStr(name), NULL ); diff --git a/ext/nokogiri/xml_comment.c b/ext/nokogiri/xml_comment.c index ad532f3a2c3..a3eb056b063 100644 --- a/ext/nokogiri/xml_comment.c +++ b/ext/nokogiri/xml_comment.c @@ -34,7 +34,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) node = xmlNewDocComment( xml_doc, - (const xmlChar *)StringValuePtr(content) + (const xmlChar *)StringValueCStr(content) ); rb_node = Nokogiri_wrap_xml_node(klass, node); diff --git a/ext/nokogiri/xml_document.c b/ext/nokogiri/xml_document.c index d8adbbfaceb..49129de0e60 100644 --- a/ext/nokogiri/xml_document.c +++ b/ext/nokogiri/xml_document.c @@ -181,7 +181,7 @@ static VALUE set_encoding(VALUE self, VALUE encoding) if (doc->encoding) free((char *) doc->encoding); /* this may produce a gcc cast warning */ - doc->encoding = xmlStrdup((xmlChar *)StringValuePtr(encoding)); + doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding)); return encoding; } @@ -228,8 +228,8 @@ static VALUE read_io( VALUE klass, VALUE encoding, VALUE options ) { - const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url); - const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding); + const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url); + const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding); VALUE error_list = rb_ary_new(); VALUE document; xmlDocPtr doc; @@ -279,8 +279,8 @@ static VALUE read_memory( VALUE klass, VALUE options ) { const char * c_buffer = StringValuePtr(string); - const char * c_url = NIL_P(url) ? NULL : StringValuePtr(url); - const char * c_enc = NIL_P(encoding) ? NULL : StringValuePtr(encoding); + const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url); + const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding); int len = (int)RSTRING_LEN(string); VALUE error_list = rb_ary_new(); VALUE document; @@ -357,7 +357,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) version = rb_ary_entry(rest, (long)0); if (NIL_P(version)) version = rb_str_new2("1.0"); - doc = xmlNewDoc((xmlChar *)StringValuePtr(version)); + doc = xmlNewDoc((xmlChar *)StringValueCStr(version)); rb_doc = Nokogiri_wrap_xml_document(klass, doc); rb_obj_call_init(rb_doc, argc, argv); return rb_doc ; @@ -385,13 +385,13 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) * * * EOXML - * + * * doc.xpath("//tire").to_s # => "" * doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => "Michelin Model XGV" * doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => "I'm a bicycle tire!" - * + * * doc.remove_namespaces! - * + * * doc.xpath("//tire").to_s # => "Michelin Model XGVI'm a bicycle tire!" * doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => "" * doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => "" @@ -438,11 +438,11 @@ static VALUE create_entity(int argc, VALUE *argv, VALUE self) xmlResetLastError(); ptr = xmlAddDocEntity( doc, - (xmlChar *)(NIL_P(name) ? NULL : StringValuePtr(name)), + (xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)), (int) (NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)), - (xmlChar *)(NIL_P(external_id) ? NULL : StringValuePtr(external_id)), - (xmlChar *)(NIL_P(system_id) ? NULL : StringValuePtr(system_id)), - (xmlChar *)(NIL_P(content) ? NULL : StringValuePtr(content)) + (xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)), + (xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)), + (xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content)) ); if(NULL == ptr) { @@ -486,9 +486,9 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent) * doc.canonicalize { |obj, parent| ... } * * Canonicalize a document and return the results. Takes an optional block - * that takes two parameters: the +obj+ and that node's +parent+. + * that takes two parameters: the +obj+ and that node's +parent+. * The +obj+ will be either a Nokogiri::XML::Node, or a Nokogiri::XML::Namespace - * The block must return a non-nil, non-false value if the +obj+ passed in + * The block must return a non-nil, non-false value if the +obj+ passed in * should be included in the canonicalized document. */ static VALUE canonicalize(int argc, VALUE* argv, VALUE self) @@ -533,14 +533,14 @@ static VALUE canonicalize(int argc, VALUE* argv, VALUE self) ns = calloc((size_t)ns_len+1, sizeof(xmlChar *)); for (i = 0 ; i < ns_len ; i++) { VALUE entry = rb_ary_entry(incl_ns, i); - const char * ptr = StringValuePtr(entry); + const char * ptr = StringValueCStr(entry); ns[i] = (xmlChar*) ptr; } } - xmlC14NExecute(doc, cb, ctx, - (int) (NIL_P(mode) ? 0 : NUM2INT(mode)), + xmlC14NExecute(doc, cb, ctx, + (int) (NIL_P(mode) ? 0 : NUM2INT(mode)), ns, (int) RTEST(with_comments), buf); diff --git a/ext/nokogiri/xml_encoding_handler.c b/ext/nokogiri/xml_encoding_handler.c index 1ac378e1b8d..837c28da252 100644 --- a/ext/nokogiri/xml_encoding_handler.c +++ b/ext/nokogiri/xml_encoding_handler.c @@ -9,7 +9,7 @@ static VALUE get(VALUE klass, VALUE key) { xmlCharEncodingHandlerPtr handler; - handler = xmlFindCharEncodingHandler(StringValuePtr(key)); + handler = xmlFindCharEncodingHandler(StringValueCStr(key)); if(handler) return Data_Wrap_Struct(klass, NULL, NULL, handler); @@ -23,7 +23,7 @@ static VALUE get(VALUE klass, VALUE key) */ static VALUE delete(VALUE klass, VALUE name) { - if(xmlDelEncodingAlias(StringValuePtr(name))) return Qnil; + if(xmlDelEncodingAlias(StringValueCStr(name))) return Qnil; return Qtrue; } @@ -35,7 +35,7 @@ static VALUE delete(VALUE klass, VALUE name) */ static VALUE alias(VALUE klass, VALUE from, VALUE to) { - xmlAddEncodingAlias(StringValuePtr(from), StringValuePtr(to)); + xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to)); return to; } diff --git a/ext/nokogiri/xml_entity_reference.c b/ext/nokogiri/xml_entity_reference.c index 261f78773b6..17fe6fa72b1 100644 --- a/ext/nokogiri/xml_entity_reference.c +++ b/ext/nokogiri/xml_entity_reference.c @@ -21,7 +21,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) node = xmlNewReference( xml_doc, - (const xmlChar *)StringValuePtr(name) + (const xmlChar *)StringValueCStr(name) ); nokogiri_root_node(node); diff --git a/ext/nokogiri/xml_node.c b/ext/nokogiri/xml_node.c index 41c195f7462..13c454271bb 100644 --- a/ext/nokogiri/xml_node.c +++ b/ext/nokogiri/xml_node.c @@ -339,7 +339,7 @@ static VALUE encode_special_chars(VALUE self, VALUE string) Data_Get_Struct(self, xmlNode, node); encoded = xmlEncodeSpecialChars( node->doc, - (const xmlChar *)StringValuePtr(string) + (const xmlChar *)StringValueCStr(string) ); encoded_str = NOKOGIRI_STR_NEW2(encoded); @@ -375,9 +375,9 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V dtd = xmlCreateIntSubset( doc, - NIL_P(name) ? NULL : (const xmlChar *)StringValuePtr(name), - NIL_P(external_id) ? NULL : (const xmlChar *)StringValuePtr(external_id), - NIL_P(system_id) ? NULL : (const xmlChar *)StringValuePtr(system_id) + NIL_P(name) ? NULL : (const xmlChar *)StringValueCStr(name), + NIL_P(external_id) ? NULL : (const xmlChar *)StringValueCStr(external_id), + NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id) ); if(!dtd) return Qnil; @@ -406,9 +406,9 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V dtd = xmlNewDtd( doc, - NIL_P(name) ? NULL : (const xmlChar *)StringValuePtr(name), - NIL_P(external_id) ? NULL : (const xmlChar *)StringValuePtr(external_id), - NIL_P(system_id) ? NULL : (const xmlChar *)StringValuePtr(system_id) + NIL_P(name) ? NULL : (const xmlChar *)StringValueCStr(name), + NIL_P(external_id) ? NULL : (const xmlChar *)StringValueCStr(external_id), + NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id) ); if(!dtd) return Qnil; @@ -751,7 +751,7 @@ static VALUE key_eh(VALUE self, VALUE attribute) { xmlNodePtr node; Data_Get_Struct(self, xmlNode, node); - if(xmlHasProp(node, (xmlChar *)StringValuePtr(attribute))) + if(xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) return Qtrue; return Qfalse; } @@ -766,8 +766,8 @@ static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace) { xmlNodePtr node; Data_Get_Struct(self, xmlNode, node); - if(xmlHasNsProp(node, (xmlChar *)StringValuePtr(attribute), - NIL_P(namespace) ? NULL : (xmlChar *)StringValuePtr(namespace))) + if(xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute), + NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace))) return Qtrue; return Qfalse; } @@ -790,7 +790,7 @@ static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb) return(Qnil); // TODO: would raising an exception be more appropriate? } - property_name = (xmlChar *)StringValuePtr(property_name_rb); + property_name = (xmlChar *)StringValueCStr(property_name_rb); /* If a matching attribute node already exists, then xmlSetProp will destroy * the existing node's children. However, if Nokogiri has a node object @@ -811,7 +811,7 @@ static VALUE set(VALUE node_rb, VALUE property_name_rb, VALUE property_value_rb) xmlResetLastError(); xmlSetStructuredErrorFunc(NULL, Nokogiri_error_silencer); - xmlSetProp(node, property_name, (xmlChar *)StringValuePtr(property_value_rb)); + xmlSetProp(node, property_name, (xmlChar *)StringValueCStr(property_value_rb)); xmlSetStructuredErrorFunc(NULL, NULL); @@ -836,7 +836,7 @@ static VALUE get(VALUE self, VALUE rattribute) if (NIL_P(rattribute)) return Qnil; Data_Get_Struct(self, xmlNode, node); - attribute = strdup(StringValuePtr(rattribute)); + attribute = strdup(StringValueCStr(rattribute)); colon = strchr(attribute, ':'); if (colon) { @@ -847,7 +847,7 @@ static VALUE get(VALUE self, VALUE rattribute) if (ns) { value = xmlGetNsProp(node, (xmlChar*)(attr_name), ns->href); } else { - value = xmlGetProp(node, (xmlChar*)StringValuePtr(rattribute)); + value = xmlGetProp(node, (xmlChar*)StringValueCStr(rattribute)); } } else { value = xmlGetNoNsProp(node, (xmlChar*)attribute); @@ -894,7 +894,7 @@ static VALUE attr(VALUE self, VALUE name) xmlNodePtr node; xmlAttrPtr prop; Data_Get_Struct(self, xmlNode, node); - prop = xmlHasProp(node, (xmlChar *)StringValuePtr(name)); + prop = xmlHasProp(node, (xmlChar *)StringValueCStr(name)); if(! prop) return Qnil; return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop); @@ -911,8 +911,8 @@ static VALUE attribute_with_ns(VALUE self, VALUE name, VALUE namespace) xmlNodePtr node; xmlAttrPtr prop; Data_Get_Struct(self, xmlNode, node); - prop = xmlHasNsProp(node, (xmlChar *)StringValuePtr(name), - NIL_P(namespace) ? NULL : (xmlChar *)StringValuePtr(namespace)); + prop = xmlHasNsProp(node, (xmlChar *)StringValueCStr(name), + NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace)); if(! prop) return Qnil; return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop); @@ -1049,7 +1049,7 @@ static VALUE set_native_content(VALUE self, VALUE content) child = next ; } - xmlNodeSetContent(node, (xmlChar *)StringValuePtr(content)); + xmlNodeSetContent(node, (xmlChar *)StringValueCStr(content)); return content; } @@ -1087,7 +1087,7 @@ static VALUE set_lang(VALUE self_rb, VALUE lang_rb) xmlChar* lang ; Data_Get_Struct(self_rb, xmlNode, self); - lang = (xmlChar*)StringValuePtr(lang_rb); + lang = (xmlChar*)StringValueCStr(lang_rb); xmlNodeSetLang(self, lang); @@ -1152,7 +1152,7 @@ static VALUE set_name(VALUE self, VALUE new_name) { xmlNodePtr node; Data_Get_Struct(self, xmlNode, node); - xmlNodeSetName(node, (xmlChar*)StringValuePtr(new_name)); + xmlNodeSetName(node, (xmlChar*)StringValueCStr(new_name)); return new_name; } @@ -1226,13 +1226,13 @@ static VALUE native_write_to( before_indent = xmlTreeIndentString; - xmlTreeIndentString = StringValuePtr(indent_string); + xmlTreeIndentString = StringValueCStr(indent_string); savectx = xmlSaveToIO( (xmlOutputWriteCallback)io_write_callback, (xmlOutputCloseCallback)io_close_callback, (void *)io, - RTEST(encoding) ? StringValuePtr(encoding) : NULL, + RTEST(encoding) ? StringValueCStr(encoding) : NULL, (int)NUM2INT(options) ); @@ -1279,7 +1279,7 @@ static VALUE add_namespace_definition(VALUE self, VALUE prefix, VALUE href) ns = xmlSearchNs( node->doc, node, - (const xmlChar *)(NIL_P(prefix) ? NULL : StringValuePtr(prefix)) + (const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix)) ); if(!ns) { @@ -1288,8 +1288,8 @@ static VALUE add_namespace_definition(VALUE self, VALUE prefix, VALUE href) } ns = xmlNewNs( namespacee, - (const xmlChar *)StringValuePtr(href), - (const xmlChar *)(NIL_P(prefix) ? NULL : StringValuePtr(prefix)) + (const xmlChar *)StringValueCStr(href), + (const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix)) ); } @@ -1319,7 +1319,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) Data_Get_Struct(document, xmlDoc, doc); - node = xmlNewNode(NULL, (xmlChar *)StringValuePtr(name)); + node = xmlNewNode(NULL, (xmlChar *)StringValueCStr(name)); node->doc = doc->doc; nokogiri_root_node(node); diff --git a/ext/nokogiri/xml_processing_instruction.c b/ext/nokogiri/xml_processing_instruction.c index 71854af0954..cbb68d5ac90 100644 --- a/ext/nokogiri/xml_processing_instruction.c +++ b/ext/nokogiri/xml_processing_instruction.c @@ -23,8 +23,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) node = xmlNewDocPI( xml_doc, - (const xmlChar *)StringValuePtr(name), - (const xmlChar *)StringValuePtr(content) + (const xmlChar *)StringValueCStr(name), + (const xmlChar *)StringValueCStr(content) ); nokogiri_root_node(node); diff --git a/ext/nokogiri/xml_reader.c b/ext/nokogiri/xml_reader.c index 7fcf3cd6e0d..d35565c2803 100644 --- a/ext/nokogiri/xml_reader.c +++ b/ext/nokogiri/xml_reader.c @@ -218,12 +218,12 @@ static VALUE reader_attribute(VALUE self, VALUE name) if(NIL_P(name)) return Qnil; name = StringValue(name) ; - value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValuePtr(name)); + value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValueCStr(name)); if(value == NULL) { /* this section is an attempt to workaround older versions of libxml that don't handle namespaces properly in all attribute-and-friends functions */ xmlChar *prefix = NULL ; - xmlChar *localname = xmlSplitQName2((xmlChar*)StringValuePtr(name), &prefix); + xmlChar *localname = xmlSplitQName2((xmlChar*)StringValueCStr(name), &prefix); if (localname != NULL) { value = xmlTextReaderLookupNamespace(reader, localname); xmlFree(localname) ; @@ -546,8 +546,8 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass) rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options); if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil"); - if (RTEST(rb_url)) c_url = StringValuePtr(rb_url); - if (RTEST(encoding)) c_encoding = StringValuePtr(encoding); + if (RTEST(rb_url)) c_url = StringValueCStr(rb_url); + if (RTEST(encoding)) c_encoding = StringValueCStr(encoding); if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options); reader = xmlReaderForMemory( @@ -590,8 +590,8 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass) rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options); if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil"); - if (RTEST(rb_url)) c_url = StringValuePtr(rb_url); - if (RTEST(encoding)) c_encoding = StringValuePtr(encoding); + if (RTEST(rb_url)) c_url = StringValueCStr(rb_url); + if (RTEST(encoding)) c_encoding = StringValueCStr(encoding); if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options); reader = xmlReaderForIO( diff --git a/ext/nokogiri/xml_sax_parser.c b/ext/nokogiri/xml_sax_parser.c index 866fa2e3cf1..acd1fce857c 100644 --- a/ext/nokogiri/xml_sax_parser.c +++ b/ext/nokogiri/xml_sax_parser.c @@ -160,7 +160,7 @@ start_element_ns ( } /** - * end_element_ns was borrowed heavily from libxml-ruby. + * end_element_ns was borrowed heavily from libxml-ruby. */ static void end_element_ns ( @@ -172,7 +172,7 @@ end_element_ns ( VALUE self = NOKOGIRI_SAX_SELF(ctx); VALUE doc = rb_iv_get(self, "@document"); - rb_funcall(doc, id_end_element_namespace, 3, + rb_funcall(doc, id_end_element_namespace, 3, NOKOGIRI_STR_NEW2(localname), RBSTR_OR_QNIL(prefix), RBSTR_OR_QNIL(uri) diff --git a/ext/nokogiri/xml_sax_parser_context.c b/ext/nokogiri/xml_sax_parser_context.c index 4b45dce1773..57aa74064f7 100644 --- a/ext/nokogiri/xml_sax_parser_context.c +++ b/ext/nokogiri/xml_sax_parser_context.c @@ -45,7 +45,7 @@ parse_io(VALUE klass, VALUE io, VALUE encoding) */ static VALUE parse_file(VALUE klass, VALUE filename) { - xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename)); + xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(StringValueCStr(filename)); return Data_Wrap_Struct(klass, NULL, deallocate, ctxt); } diff --git a/ext/nokogiri/xml_sax_push_parser.c b/ext/nokogiri/xml_sax_push_parser.c index 9b69c989bb8..f6107f272af 100644 --- a/ext/nokogiri/xml_sax_push_parser.c +++ b/ext/nokogiri/xml_sax_push_parser.c @@ -59,7 +59,7 @@ static VALUE initialize_native(VALUE self, VALUE _xml_sax, VALUE _filename) Data_Get_Struct(_xml_sax, xmlSAXHandler, sax); - if(_filename != Qnil) filename = StringValuePtr(_filename); + if(_filename != Qnil) filename = StringValueCStr(_filename); ctx = xmlCreatePushParserCtxt( sax, diff --git a/ext/nokogiri/xml_schema.c b/ext/nokogiri/xml_schema.c index e8b1d8f88b4..da2774ba8c4 100644 --- a/ext/nokogiri/xml_schema.c +++ b/ext/nokogiri/xml_schema.c @@ -61,7 +61,7 @@ static VALUE validate_file(VALUE self, VALUE rb_filename) VALUE errors; Data_Get_Struct(self, xmlSchema, schema); - filename = (const char*)StringValuePtr(rb_filename) ; + filename = (const char*)StringValueCStr(rb_filename) ; errors = rb_ary_new(); diff --git a/ext/nokogiri/xml_text.c b/ext/nokogiri/xml_text.c index f824717ad41..971a31e879e 100644 --- a/ext/nokogiri/xml_text.c +++ b/ext/nokogiri/xml_text.c @@ -19,7 +19,7 @@ static VALUE new(int argc, VALUE *argv, VALUE klass) Data_Get_Struct(document, xmlDoc, doc); - node = xmlNewText((xmlChar *)StringValuePtr(string)); + node = xmlNewText((xmlChar *)StringValueCStr(string)); node->doc = doc->doc; nokogiri_root_node(node); diff --git a/ext/nokogiri/xml_xpath_context.c b/ext/nokogiri/xml_xpath_context.c index 25e43aa9945..f47f4e3ea55 100644 --- a/ext/nokogiri/xml_xpath_context.c +++ b/ext/nokogiri/xml_xpath_context.c @@ -21,8 +21,8 @@ static VALUE register_ns(VALUE self, VALUE prefix, VALUE uri) Data_Get_Struct(self, xmlXPathContext, ctx); xmlXPathRegisterNs( ctx, - (const xmlChar *)StringValuePtr(prefix), - (const xmlChar *)StringValuePtr(uri) + (const xmlChar *)StringValueCStr(prefix), + (const xmlChar *)StringValueCStr(uri) ); return self; } @@ -39,10 +39,10 @@ static VALUE register_variable(VALUE self, VALUE name, VALUE value) xmlXPathObjectPtr xmlValue; Data_Get_Struct(self, xmlXPathContext, ctx); - xmlValue = xmlXPathNewCString(StringValuePtr(value)); + xmlValue = xmlXPathNewCString(StringValueCStr(value)); xmlXPathRegisterVariable( ctx, - (const xmlChar *)StringValuePtr(name), + (const xmlChar *)StringValueCStr(name), xmlValue ); @@ -109,7 +109,7 @@ void Nokogiri_marshal_xpath_funcall_and_return_values(xmlXPathParserContextPtr c case T_STRING: xmlXPathReturnString( ctx, - xmlCharStrdup(StringValuePtr(result)) + xmlCharStrdup(StringValueCStr(result)) ); break; case T_TRUE: @@ -203,7 +203,7 @@ static VALUE evaluate(int argc, VALUE *argv, VALUE self) if(rb_scan_args(argc, argv, "11", &search_path, &xpath_handler) == 1) xpath_handler = Qnil; - query = (xmlChar *)StringValuePtr(search_path); + query = (xmlChar *)StringValueCStr(search_path); if(Qnil != xpath_handler) { /* FIXME: not sure if this is the correct place to shove private data. */ diff --git a/ext/nokogiri/xslt_stylesheet.c b/ext/nokogiri/xslt_stylesheet.c index e132b83c3fe..15206977587 100644 --- a/ext/nokogiri/xslt_stylesheet.c +++ b/ext/nokogiri/xslt_stylesheet.c @@ -22,7 +22,7 @@ static void dealloc(nokogiriXsltStylesheetTuple *wrapper) NOKOGIRI_DEBUG_START(doc); xsltFreeStylesheet(doc); /* commented out for now. */ NOKOGIRI_DEBUG_END(doc); - + free(wrapper); } @@ -47,7 +47,7 @@ VALUE Nokogiri_wrap_xslt_stylesheet(xsltStylesheetPtr ss) self = Data_Make_Struct(cNokogiriXsltStylesheet, nokogiriXsltStylesheetTuple, mark, dealloc, wrapper); - + ss->_private = (void *)self; wrapper->ss = ss; wrapper->func_instances = rb_ary_new(); @@ -122,7 +122,7 @@ static void swallow_superfluous_xml_errors(void * userdata, xmlErrorPtr error, . * returns Nokogiri::XML::Document * * Example: - * + * * doc = Nokogiri::XML(File.read(ARGV[0])) * xslt = Nokogiri::XSLT(File.read(ARGV[1])) * puts xslt.transform(doc, ['key', 'value']) @@ -158,7 +158,7 @@ static VALUE transform(int argc, VALUE* argv, VALUE self) params = calloc((size_t)param_len+1, sizeof(char*)); for (j = 0 ; j < param_len ; j++) { VALUE entry = rb_ary_entry(paramobj, j); - const char * ptr = StringValuePtr(entry); + const char * ptr = StringValueCStr(entry); params[j] = ptr; } params[param_len] = 0 ; @@ -211,7 +211,7 @@ static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri) for(i = 0; i < RARRAY_LEN(methods); i++) { VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i)); xsltRegisterExtFunction(ctxt, - (unsigned char *)StringValuePtr(method_name), uri, method_caller); + (unsigned char *)StringValueCStr(method_name), uri, method_caller); } Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple, @@ -245,7 +245,7 @@ static VALUE registr(VALUE self, VALUE uri, VALUE obj) if(NIL_P(modules)) rb_raise(rb_eRuntimeError, "wtf! @modules isn't set"); rb_hash_aset(modules, uri, obj); - xsltRegisterExtModule((unsigned char *)StringValuePtr(uri), initFunc, shutdownFunc); + xsltRegisterExtModule((unsigned char *)StringValueCStr(uri), initFunc, shutdownFunc); return self; }