idx int64 | func_before string | Vulnerability Classification string | vul int64 | func_after string | patch string | CWE ID string | lines_before string | lines_after string |
|---|---|---|---|---|---|---|---|---|
17,600 | raptor_rdfxml_parse_finish_factory(raptor_parser_factory* factory)
{
}
| +Info | 0 | raptor_rdfxml_parse_finish_factory(raptor_parser_factory* factory)
{
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,601 | raptor_rdfxml_parse_init(raptor_parser* rdf_parser, const char *name)
{
raptor_rdfxml_parser* rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
raptor_sax2* sax2;
raptor_world* world = rdf_parser->world;
/* Allocate sax2 object */
sax2 = raptor_new_sax2(rdf_parser->world, &rdf_parser->locator, rdf_parser);
rdf_xml_parser->sax2 = sax2;
if(!sax2)
return 1;
/* Initialize sax2 element handlers */
raptor_sax2_set_start_element_handler(sax2, raptor_rdfxml_start_element_handler);
raptor_sax2_set_end_element_handler(sax2, raptor_rdfxml_end_element_handler);
raptor_sax2_set_characters_handler(sax2, raptor_rdfxml_characters_handler);
raptor_sax2_set_cdata_handler(sax2, raptor_rdfxml_cdata_handler);
raptor_sax2_set_comment_handler(sax2, raptor_rdfxml_comment_handler);
raptor_sax2_set_namespace_handler(sax2, raptor_rdfxml_sax2_new_namespace_handler);
/* Allocate uris */
RAPTOR_DAML_NS_URI(rdf_xml_parser) = raptor_new_uri_from_counted_string(world,
daml_namespace_uri_string,
daml_namespace_uri_string_len);
RAPTOR_DAML_List_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"List");
RAPTOR_DAML_first_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser) ,(const unsigned char *)"first");
RAPTOR_DAML_rest_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"rest");
RAPTOR_DAML_nil_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"nil");
/* Check for uri allocation failures */
if(!RAPTOR_DAML_NS_URI(rdf_xml_parser) ||
!RAPTOR_DAML_List_URI(rdf_xml_parser) ||
!RAPTOR_DAML_first_URI(rdf_xml_parser) ||
!RAPTOR_DAML_rest_URI(rdf_xml_parser) ||
!RAPTOR_DAML_nil_URI(rdf_xml_parser))
return 1;
/* Everything succeeded */
return 0;
}
| +Info | 0 | raptor_rdfxml_parse_init(raptor_parser* rdf_parser, const char *name)
{
raptor_rdfxml_parser* rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
raptor_sax2* sax2;
raptor_world* world = rdf_parser->world;
/* Allocate sax2 object */
sax2 = raptor_new_sax2(rdf_parser->world, &rdf_parser->locator, rdf_parser);
rdf_xml_parser->sax2 = sax2;
if(!sax2)
return 1;
/* Initialize sax2 element handlers */
raptor_sax2_set_start_element_handler(sax2, raptor_rdfxml_start_element_handler);
raptor_sax2_set_end_element_handler(sax2, raptor_rdfxml_end_element_handler);
raptor_sax2_set_characters_handler(sax2, raptor_rdfxml_characters_handler);
raptor_sax2_set_cdata_handler(sax2, raptor_rdfxml_cdata_handler);
raptor_sax2_set_comment_handler(sax2, raptor_rdfxml_comment_handler);
raptor_sax2_set_namespace_handler(sax2, raptor_rdfxml_sax2_new_namespace_handler);
/* Allocate uris */
RAPTOR_DAML_NS_URI(rdf_xml_parser) = raptor_new_uri_from_counted_string(world,
daml_namespace_uri_string,
daml_namespace_uri_string_len);
RAPTOR_DAML_List_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"List");
RAPTOR_DAML_first_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser) ,(const unsigned char *)"first");
RAPTOR_DAML_rest_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"rest");
RAPTOR_DAML_nil_URI(rdf_xml_parser) = raptor_new_uri_from_uri_local_name(world, RAPTOR_DAML_NS_URI(rdf_xml_parser), (const unsigned char *)"nil");
/* Check for uri allocation failures */
if(!RAPTOR_DAML_NS_URI(rdf_xml_parser) ||
!RAPTOR_DAML_List_URI(rdf_xml_parser) ||
!RAPTOR_DAML_first_URI(rdf_xml_parser) ||
!RAPTOR_DAML_rest_URI(rdf_xml_parser) ||
!RAPTOR_DAML_nil_URI(rdf_xml_parser))
return 1;
/* Everything succeeded */
return 0;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,602 | raptor_rdfxml_parse_recognise_syntax(raptor_parser_factory* factory,
const unsigned char *buffer, size_t len,
const unsigned char *identifier,
const unsigned char *suffix,
const char *mime_type)
{
int score = 0;
if(suffix) {
if(!strcmp((const char*)suffix, "rdf") ||
!strcmp((const char*)suffix, "rdfs") ||
!strcmp((const char*)suffix, "foaf") ||
!strcmp((const char*)suffix, "doap") ||
!strcmp((const char*)suffix, "owl") ||
!strcmp((const char*)suffix, "daml"))
score = 9;
if(!strcmp((const char*)suffix, "rss"))
score = 3;
}
if(identifier) {
if(strstr((const char*)identifier, "rss1"))
score += 5;
else if(!suffix && strstr((const char*)identifier, "rss"))
score += 3;
else if(!suffix && strstr((const char*)identifier, "rdf"))
score += 2;
else if(!suffix && strstr((const char*)identifier, "RDF"))
score += 2;
}
if(mime_type) {
if(strstr((const char*)mime_type, "html"))
score -= 4;
else if(!strcmp((const char*)mime_type, "text/rdf"))
score += 7;
else if(!strcmp((const char*)mime_type, "application/xml"))
score += 5;
}
if(buffer && len) {
/* Check it's an XML namespace declared and not N3 or Turtle which
* mention the namespace URI but not in this form.
*/
#define HAS_RDF_XMLNS1 (raptor_memstr((const char*)buffer, len, "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS2 (raptor_memstr((const char*)buffer, len, "xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS3 (raptor_memstr((const char*)buffer, len, "xmlns=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS4 (raptor_memstr((const char*)buffer, len, "xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_ENTITY1 (raptor_memstr((const char*)buffer, len, "<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>") != NULL)
#define HAS_RDF_ENTITY2 (raptor_memstr((const char*)buffer, len, "<!ENTITY rdf \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">") != NULL)
#define HAS_RDF_ENTITY3 (raptor_memstr((const char*)buffer, len, "xmlns:rdf=\"&rdf;\"") != NULL)
#define HAS_RDF_ENTITY4 (raptor_memstr((const char*)buffer, len, "xmlns:rdf='&rdf;'") != NULL)
#define HAS_HTML_NS (raptor_memstr((const char*)buffer, len, "http://www.w3.org/1999/xhtml") != NULL)
#define HAS_HTML_ROOT (raptor_memstr((const char*)buffer, len, "<html") != NULL)
if(!HAS_HTML_NS && !HAS_HTML_ROOT &&
(HAS_RDF_XMLNS1 || HAS_RDF_XMLNS2 || HAS_RDF_XMLNS3 || HAS_RDF_XMLNS4 ||
HAS_RDF_ENTITY1 || HAS_RDF_ENTITY2 || HAS_RDF_ENTITY3 || HAS_RDF_ENTITY4)
) {
int has_rdf_RDF = (raptor_memstr((const char*)buffer, len, "<rdf:RDF") != NULL);
int has_rdf_Description = (raptor_memstr((const char*)buffer, len, "rdf:Description") != NULL);
int has_rdf_about = (raptor_memstr((const char*)buffer, len, "rdf:about") != NULL);
score += 7;
if(has_rdf_RDF)
score++;
if(has_rdf_Description)
score++;
if(has_rdf_about)
score++;
}
}
return score;
}
| +Info | 0 | raptor_rdfxml_parse_recognise_syntax(raptor_parser_factory* factory,
const unsigned char *buffer, size_t len,
const unsigned char *identifier,
const unsigned char *suffix,
const char *mime_type)
{
int score = 0;
if(suffix) {
if(!strcmp((const char*)suffix, "rdf") ||
!strcmp((const char*)suffix, "rdfs") ||
!strcmp((const char*)suffix, "foaf") ||
!strcmp((const char*)suffix, "doap") ||
!strcmp((const char*)suffix, "owl") ||
!strcmp((const char*)suffix, "daml"))
score = 9;
if(!strcmp((const char*)suffix, "rss"))
score = 3;
}
if(identifier) {
if(strstr((const char*)identifier, "rss1"))
score += 5;
else if(!suffix && strstr((const char*)identifier, "rss"))
score += 3;
else if(!suffix && strstr((const char*)identifier, "rdf"))
score += 2;
else if(!suffix && strstr((const char*)identifier, "RDF"))
score += 2;
}
if(mime_type) {
if(strstr((const char*)mime_type, "html"))
score -= 4;
else if(!strcmp((const char*)mime_type, "text/rdf"))
score += 7;
else if(!strcmp((const char*)mime_type, "application/xml"))
score += 5;
}
if(buffer && len) {
/* Check it's an XML namespace declared and not N3 or Turtle which
* mention the namespace URI but not in this form.
*/
#define HAS_RDF_XMLNS1 (raptor_memstr((const char*)buffer, len, "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS2 (raptor_memstr((const char*)buffer, len, "xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS3 (raptor_memstr((const char*)buffer, len, "xmlns=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_XMLNS4 (raptor_memstr((const char*)buffer, len, "xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#") != NULL)
#define HAS_RDF_ENTITY1 (raptor_memstr((const char*)buffer, len, "<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>") != NULL)
#define HAS_RDF_ENTITY2 (raptor_memstr((const char*)buffer, len, "<!ENTITY rdf \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">") != NULL)
#define HAS_RDF_ENTITY3 (raptor_memstr((const char*)buffer, len, "xmlns:rdf=\"&rdf;\"") != NULL)
#define HAS_RDF_ENTITY4 (raptor_memstr((const char*)buffer, len, "xmlns:rdf='&rdf;'") != NULL)
#define HAS_HTML_NS (raptor_memstr((const char*)buffer, len, "http://www.w3.org/1999/xhtml") != NULL)
#define HAS_HTML_ROOT (raptor_memstr((const char*)buffer, len, "<html") != NULL)
if(!HAS_HTML_NS && !HAS_HTML_ROOT &&
(HAS_RDF_XMLNS1 || HAS_RDF_XMLNS2 || HAS_RDF_XMLNS3 || HAS_RDF_XMLNS4 ||
HAS_RDF_ENTITY1 || HAS_RDF_ENTITY2 || HAS_RDF_ENTITY3 || HAS_RDF_ENTITY4)
) {
int has_rdf_RDF = (raptor_memstr((const char*)buffer, len, "<rdf:RDF") != NULL);
int has_rdf_Description = (raptor_memstr((const char*)buffer, len, "rdf:Description") != NULL);
int has_rdf_about = (raptor_memstr((const char*)buffer, len, "rdf:about") != NULL);
score += 7;
if(has_rdf_RDF)
score++;
if(has_rdf_Description)
score++;
if(has_rdf_about)
score++;
}
}
return score;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,603 | raptor_rdfxml_parse_terminate(raptor_parser *rdf_parser)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
int i;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_xml_parser->sax2) {
raptor_free_sax2(rdf_xml_parser->sax2);
rdf_xml_parser->sax2 = NULL;
}
while( (element = raptor_rdfxml_element_pop(rdf_xml_parser)) )
raptor_free_rdfxml_element(element);
for(i = 0; i < RAPTOR_RDFXML_N_CONCEPTS; i++) {
raptor_uri* concept_uri = rdf_xml_parser->concepts[i];
if(concept_uri) {
raptor_free_uri(concept_uri);
rdf_xml_parser->concepts[i] = NULL;
}
}
if(rdf_xml_parser->id_set) {
raptor_free_id_set(rdf_xml_parser->id_set);
rdf_xml_parser->id_set = NULL;
}
}
| +Info | 0 | raptor_rdfxml_parse_terminate(raptor_parser *rdf_parser)
{
raptor_rdfxml_parser* rdf_xml_parser;
raptor_rdfxml_element* element;
int i;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(rdf_xml_parser->sax2) {
raptor_free_sax2(rdf_xml_parser->sax2);
rdf_xml_parser->sax2 = NULL;
}
while( (element = raptor_rdfxml_element_pop(rdf_xml_parser)) )
raptor_free_rdfxml_element(element);
for(i = 0; i < RAPTOR_RDFXML_N_CONCEPTS; i++) {
raptor_uri* concept_uri = rdf_xml_parser->concepts[i];
if(concept_uri) {
raptor_free_uri(concept_uri);
rdf_xml_parser->concepts[i] = NULL;
}
}
if(rdf_xml_parser->id_set) {
raptor_free_id_set(rdf_xml_parser->id_set);
rdf_xml_parser->id_set = NULL;
}
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,604 | raptor_rdfxml_parser_stats_print(raptor_rdfxml_parser* rdf_xml_parser,
FILE *stream)
{
fputs("rdf:ID set ", stream);
raptor_id_set_stats_print(rdf_xml_parser->id_set, stream);
}
| +Info | 0 | raptor_rdfxml_parser_stats_print(raptor_rdfxml_parser* rdf_xml_parser,
FILE *stream)
{
fputs("rdf:ID set ", stream);
raptor_id_set_stats_print(rdf_xml_parser->id_set, stream);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,605 | raptor_rdfxml_record_ID(raptor_parser *rdf_parser,
raptor_rdfxml_element *element,
const unsigned char *id)
{
raptor_rdfxml_parser *rdf_xml_parser;
raptor_uri* base_uri;
size_t id_len;
int rc;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(!RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_CHECK_RDF_ID))
return 0;
base_uri = raptor_rdfxml_inscope_base_uri(rdf_parser);
id_len = strlen((const char*)id);
rc = raptor_id_set_add(rdf_xml_parser->id_set, base_uri, id, id_len);
return (rc != 0);
}
| +Info | 0 | raptor_rdfxml_record_ID(raptor_parser *rdf_parser,
raptor_rdfxml_element *element,
const unsigned char *id)
{
raptor_rdfxml_parser *rdf_xml_parser;
raptor_uri* base_uri;
size_t id_len;
int rc;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
if(!RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_CHECK_RDF_ID))
return 0;
base_uri = raptor_rdfxml_inscope_base_uri(rdf_parser);
id_len = strlen((const char*)id);
rc = raptor_id_set_add(rdf_xml_parser->id_set, base_uri, id, id_len);
return (rc != 0);
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,606 | raptor_rdfxml_start_element_grammar(raptor_parser *rdf_parser,
raptor_rdfxml_element *element)
{
raptor_rdfxml_parser *rdf_xml_parser;
int finished;
raptor_state state;
raptor_xml_element* xml_element;
raptor_qname* el_qname;
const unsigned char *el_name;
int element_in_rdf_ns;
int rc = 0;
raptor_uri* base_uri;
raptor_uri* element_name_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
xml_element = element->xml_element;
el_qname = raptor_xml_element_get_name(xml_element);
el_name = el_qname->local_name;
element_in_rdf_ns = (el_qname->nspace && el_qname->nspace->is_rdf_ms);
base_uri = raptor_rdfxml_inscope_base_uri(rdf_parser);
element_name_uri = el_qname->uri;
state = element->state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Starting in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
finished = 0;
while(!finished) {
switch(state) {
case RAPTOR_STATE_SKIPPING:
element->child_state = state;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PRESERVED;
finished = 1;
break;
case RAPTOR_STATE_UNKNOWN:
/* found <rdf:RDF> ? */
if(element_in_rdf_ns) {
if(raptor_uri_equals(element_name_uri,
RAPTOR_RDF_RDF_URI(rdf_parser->world))) {
element->child_state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES;
/* Yes - need more content before can continue,
* so wait for another element
*/
finished = 1;
break;
}
if(raptor_uri_equals(element_name_uri,
RAPTOR_RDF_Description_URI(rdf_parser->world))) {
state = RAPTOR_STATE_DESCRIPTION;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
/* Yes - found something so move immediately to description */
break;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_nodeElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a node element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
}
/* If scanning for element, can continue */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING)) {
finished = 1;
break;
}
/* Otherwise the choice of the next state can be made
* from the current element by the OBJ state
*/
state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES;
break;
case RAPTOR_STATE_NODE_ELEMENT_LIST:
/* Handling
* http://www.w3.org/TR/rdf-syntax-grammar/#nodeElementList
*
* Everything goes to nodeElement
*/
state = RAPTOR_STATE_NODE_ELEMENT;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
break;
case RAPTOR_STATE_DESCRIPTION:
case RAPTOR_STATE_NODE_ELEMENT:
case RAPTOR_STATE_PARSETYPE_RESOURCE:
case RAPTOR_STATE_PARSETYPE_COLLECTION:
/* Handling <rdf:Description> or other node element
* http://www.w3.org/TR/rdf-syntax-grammar/#nodeElement
*
* or a property element acting as a node element for
* rdf:parseType="Resource"
* http://www.w3.org/TR/rdf-syntax-grammar/#parseTypeResourcePropertyElt
* or rdf:parseType="Collection" (and daml:Collection)
* http://www.w3.org/TR/rdf-syntax-grammar/#parseTypeCollectionPropertyElt
*
* Only create a bag if bagID given
*/
if(!element_name_uri) {
/* We cannot handle this */
raptor_parser_warning(rdf_parser, "Using node element '%s' without a namespace is forbidden.",
el_qname->local_name);
raptor_rdfxml_update_document_locator(rdf_parser);
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_nodeElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a node element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
if(element->content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION &&
element->content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION &&
element->parent &&
(element->parent->state == RAPTOR_STATE_PROPERTYELT ||
element->parent->state == RAPTOR_STATE_MEMBER_PROPERTYELT) &&
element->parent->xml_element->content_element_seen > 1) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser, "The enclosing property already has an object");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(state == RAPTOR_STATE_NODE_ELEMENT ||
state == RAPTOR_STATE_DESCRIPTION ||
state == RAPTOR_STATE_PARSETYPE_COLLECTION) {
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_Description_URI(rdf_parser->world)))
state = RAPTOR_STATE_DESCRIPTION;
else
state = RAPTOR_STATE_NODE_ELEMENT;
}
if((element->rdf_attr[RDF_NS_ID]!=NULL) +
(element->rdf_attr[RDF_NS_about]!=NULL) +
(element->rdf_attr[RDF_NS_nodeID]!=NULL) > 1) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser, "Multiple attributes of rdf:ID, rdf:about and rdf:nodeID on element '%s' - only one allowed.", el_name);
}
if(element->rdf_attr[RDF_NS_ID]) {
unsigned char* subject_id;
raptor_uri* subject_uri;
subject_id = (unsigned char*)element->rdf_attr[RDF_NS_ID];
if(!raptor_valid_xml_ID(rdf_parser, subject_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:ID value '%s'",
subject_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, subject_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:ID value '%s'",
subject_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* after this, subject_id is the owner of the ID string */
element->rdf_attr[RDF_NS_ID] = NULL;
subject_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!subject_uri)
goto oom;
element->subject = raptor_new_term_from_uri(rdf_parser->world,
subject_uri);
raptor_free_uri(subject_uri);
if(!element->subject)
goto oom;
} else if(element->rdf_attr[RDF_NS_about]) {
raptor_uri* subject_uri;
subject_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
base_uri,
(const unsigned char*)element->rdf_attr[RDF_NS_about]);
if(!subject_uri)
goto oom;
element->subject = raptor_new_term_from_uri(rdf_parser->world,
subject_uri);
raptor_free_uri(subject_uri);
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_about]);
element->rdf_attr[RDF_NS_about] = NULL;
if(!element->subject)
goto oom;
} else if(element->rdf_attr[RDF_NS_nodeID]) {
unsigned char* subject_id;
subject_id = raptor_world_internal_generate_id(rdf_parser->world,
(unsigned char*)element->rdf_attr[RDF_NS_nodeID]);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
element->rdf_attr[RDF_NS_nodeID] = NULL;
if(!element->subject)
goto oom;
if(!raptor_valid_xml_ID(rdf_parser, element->subject->value.blank.string)) {
raptor_parser_error(rdf_parser, "Illegal rdf:nodeID value '%s'",
(const char*)element->subject->value.blank.string);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
} else if(element->parent &&
element->parent->child_content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION &&
element->parent->child_content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION &&
element->parent->object) {
/* copy from parent (property element), it has a URI for us */
element->subject = raptor_term_copy(element->parent->object);
} else {
unsigned char* subject_id;
subject_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!element->subject)
goto oom;
}
if(element->rdf_attr[RDF_NS_bagID]) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
unsigned char* bag_id;
raptor_uri* bag_uri = NULL;
bag_id = (unsigned char*)element->rdf_attr[RDF_NS_bagID];
element->rdf_attr[RDF_NS_bagID] = NULL;
bag_uri = raptor_new_uri_from_id(rdf_parser->world,
base_uri, bag_id);
if(!bag_uri) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
element->bag = raptor_new_term_from_uri(rdf_parser->world, bag_uri);
raptor_free_uri(bag_uri);
if(!raptor_valid_xml_ID(rdf_parser, bag_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, bag_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
RAPTOR_FREE(char*, bag_id);
raptor_parser_warning(rdf_parser, "rdf:bagID is deprecated.");
raptor_rdfxml_generate_statement(rdf_parser,
element->bag,
RAPTOR_RDF_type_URI(rdf_parser->world),
RAPTOR_RDF_Bag_term(rdf_parser->world),
NULL,
NULL);
} else {
/* bagID forbidden */
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden.");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
}
if(element->parent) {
/* In a rdf:parseType="Collection" the resources are appended
* to the list at the genid element->parent->tail_id
*/
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION ||
element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
/* <idList> rdf:type rdf:List */
const unsigned char * idList;
raptor_uri *predicate_uri;
raptor_term* idList_term;
raptor_term* object_term;
idList = raptor_world_generate_bnodeid(rdf_parser->world);
if(!idList)
goto oom;
/* idList string is saved below in element->parent->tail_id */
idList_term = raptor_new_term_from_blank(rdf_parser->world, idList);
if(!idList_term) {
RAPTOR_FREE(char*, idList);
goto oom;
}
if((element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ||
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_RDF_TYPE_RDF_LIST)) {
raptor_uri* class_uri = NULL;
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
class_uri = RAPTOR_DAML_List_URI(rdf_xml_parser);
object_term = raptor_new_term_from_uri(rdf_parser->world,
class_uri);
} else
object_term = raptor_term_copy(RAPTOR_RDF_List_term(rdf_parser->world));
raptor_rdfxml_generate_statement(rdf_parser,
idList_term,
RAPTOR_RDF_type_URI(rdf_parser->world),
object_term,
NULL,
element);
raptor_free_term(object_term);
}
predicate_uri = (element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ? RAPTOR_DAML_first_URI(rdf_xml_parser) : RAPTOR_RDF_first_URI(rdf_parser->world);
/* <idList> rdf:first <element->uri> */
raptor_rdfxml_generate_statement(rdf_parser,
idList_term,
predicate_uri,
element->subject,
NULL,
NULL);
/* If there is no rdf:parseType="Collection" */
if(!element->parent->tail_id) {
/* Free any existing object still around.
* I suspect this can never happen.
*/
if(element->parent->object)
raptor_free_term(element->parent->object);
element->parent->object = raptor_new_term_from_blank(rdf_parser->world,
idList);
} else {
raptor_term* tail_id_term;
tail_id_term = raptor_new_term_from_blank(rdf_parser->world,
element->parent->tail_id);
predicate_uri = (element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ? RAPTOR_DAML_rest_URI(rdf_xml_parser) : RAPTOR_RDF_rest_URI(rdf_parser->world);
/* _:tail_id rdf:rest _:listRest */
raptor_rdfxml_generate_statement(rdf_parser,
tail_id_term,
predicate_uri,
idList_term,
NULL,
NULL);
raptor_free_term(tail_id_term);
}
/* update new tail */
if(element->parent->tail_id)
RAPTOR_FREE(char*, (char*)element->parent->tail_id);
element->parent->tail_id = idList;
raptor_free_term(idList_term);
} else if(element->parent->state != RAPTOR_STATE_UNKNOWN &&
element->state != RAPTOR_STATE_PARSETYPE_RESOURCE) {
/* If there is a parent element (property) containing this
* element (node) and it has no object, set it from this subject
*/
if(element->parent->object) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser,
"Tried to set multiple objects of a statement");
} else {
/* Store URI of this node in our parent as the property object */
element->parent->object = raptor_term_copy(element->subject);
element->parent->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
}
}
/* If this is a node element, generate the rdf:type statement
* from this node
*/
if(state == RAPTOR_STATE_NODE_ELEMENT) {
raptor_term* el_name_term;
el_name_term = raptor_new_term_from_uri(rdf_parser->world,
element_name_uri);
raptor_rdfxml_generate_statement(rdf_parser,
element->subject,
RAPTOR_RDF_type_URI(rdf_parser->world),
el_name_term,
element->reified,
element);
raptor_free_term(el_name_term);
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element, NULL))
goto oom;
/* for both productions now need some more content or
* property elements before can do any more work.
*/
element->child_state = RAPTOR_STATE_PROPERTYELT;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_OTHER:
/* FALLTHROUGH */
case RAPTOR_STATE_PARSETYPE_LITERAL:
raptor_xml_writer_start_element(rdf_xml_parser->xml_writer, xml_element);
element->child_state = RAPTOR_STATE_PARSETYPE_LITERAL;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
finished = 1;
break;
/* Handle all the detail of the various options of property element
* http://www.w3.org/TR/rdf-syntax-grammar/#propertyElt
*
* All the attributes must be scanned here to see what additional
* property element work is needed. No triples are generated
* until the end of this element, until it is clear if the
* element was empty.
*/
case RAPTOR_STATE_MEMBER_PROPERTYELT:
case RAPTOR_STATE_PROPERTYELT:
if(!element_name_uri) {
raptor_parser_error(rdf_parser, "Using property element '%s' without a namespace is forbidden.",
raptor_xml_element_get_name(element->parent->xml_element)->local_name);
raptor_rdfxml_update_document_locator(rdf_parser);
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* Handling rdf:li as a property, noting special processing */
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_li_URI(rdf_parser->world))) {
state = RAPTOR_STATE_MEMBER_PROPERTYELT;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_propertyElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a property element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
/* rdf:ID on a property element - reify a statement.
* Allowed on all property element forms
*/
if(element->rdf_attr[RDF_NS_ID]) {
raptor_uri *reified_uri;
element->reified_id = element->rdf_attr[RDF_NS_ID];
element->rdf_attr[RDF_NS_ID] = NULL;
reified_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
element->reified_id);
if(!reified_uri)
goto oom;
element->reified = raptor_new_term_from_uri(rdf_parser->world,
reified_uri);
raptor_free_uri(reified_uri);
if(!element->reified)
goto oom;
if(!raptor_valid_xml_ID(rdf_parser, element->reified_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:ID value '%s'",
element->reified_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, element->reified_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:ID value '%s'",
element->reified_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
}
/* rdf:datatype on a property element.
* Only allowed for
* http://www.w3.org/TR/rdf-syntax-grammar/#literalPropertyElt
*/
if(element->rdf_attr[RDF_NS_datatype]) {
raptor_uri *datatype_uri;
datatype_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
base_uri,
(const unsigned char*)element->rdf_attr[RDF_NS_datatype]);
element->object_literal_datatype = datatype_uri;
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_datatype]);
element->rdf_attr[RDF_NS_datatype] = NULL;
if(!element->object_literal_datatype)
goto oom;
}
if(element->rdf_attr[RDF_NS_bagID]) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
if(element->rdf_attr[RDF_NS_resource] ||
element->rdf_attr[RDF_NS_parseType]) {
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden on property element '%s' with an rdf:resource or rdf:parseType attribute.", el_name);
/* prevent this being used later either */
element->rdf_attr[RDF_NS_bagID] = NULL;
} else {
unsigned char* bag_id;
raptor_uri* bag_uri;
bag_id = (unsigned char*)element->rdf_attr[RDF_NS_bagID];
element->rdf_attr[RDF_NS_bagID] = NULL;
bag_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
bag_id);
if(!bag_uri) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
element->bag = raptor_new_term_from_uri(rdf_parser->world,
bag_uri);
raptor_free_uri(bag_uri);
if(!element->bag) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
if(!raptor_valid_xml_ID(rdf_parser, bag_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, bag_id)) {
raptor_parser_error(rdf_parser,
"Duplicated rdf:bagID value '%s'", bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
RAPTOR_FREE(char*, bag_id);
finished = 1;
break;
}
RAPTOR_FREE(char*, bag_id);
raptor_parser_warning(rdf_parser, "rdf:bagID is deprecated.");
}
} else {
/* bagID forbidden */
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden.");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
} /* if rdf:bagID on property element */
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT;
if(element->rdf_attr[RDF_NS_parseType]) {
const unsigned char *parse_type;
int i;
int is_parseType_Literal = 0;
parse_type = element->rdf_attr[RDF_NS_parseType];
if(raptor_rdfxml_element_has_property_attributes(element)) {
raptor_parser_error(rdf_parser, "Property attributes cannot be used with rdf:parseType='%s'", parse_type);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* Check for bad combinations of things with parseType */
for(i = 0; i <= RDF_NS_LAST; i++)
if(element->rdf_attr[i] && i != RDF_NS_parseType) {
raptor_parser_error(rdf_parser, "Attribute '%s' cannot be used with rdf:parseType='%s'", raptor_rdf_ns_terms_info[i].name, parse_type);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(!strcmp((char*)parse_type, "Literal"))
is_parseType_Literal = 1;
else if(!strcmp((char*)parse_type, "Resource")) {
unsigned char* subject_id;
state = RAPTOR_STATE_PARSETYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PROPERTYELT;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
/* create a node for the subject of the contained properties */
subject_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!element->subject)
goto oom;
} else if(!strcmp((char*)parse_type, "Collection")) {
/* An rdf:parseType="Collection" appears as a single node */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PARSETYPE_COLLECTION;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION;
} else {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_OTHER_PARSETYPES) &&
!raptor_strcasecmp((char*)parse_type, "daml:collection")) {
/* A DAML collection appears as a single node */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PARSETYPE_COLLECTION;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION;
} else {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_WARN_OTHER_PARSETYPES)) {
raptor_parser_warning(rdf_parser, "Unknown rdf:parseType value '%s' taken as 'Literal'", parse_type);
}
is_parseType_Literal = 1;
}
}
if(is_parseType_Literal) {
raptor_xml_writer* xml_writer;
/* rdf:parseType="Literal" - explicitly or default
* if the parseType value is not recognised
*/
rdf_xml_parser->xml_content = NULL;
rdf_xml_parser->xml_content_length = 0;
rdf_xml_parser->iostream =
raptor_new_iostream_to_string(rdf_parser->world,
&rdf_xml_parser->xml_content,
&rdf_xml_parser->xml_content_length,
raptor_alloc_memory);
if(!rdf_xml_parser->iostream)
goto oom;
xml_writer = raptor_new_xml_writer(rdf_parser->world, NULL,
rdf_xml_parser->iostream);
rdf_xml_parser->xml_writer = xml_writer;
if(!rdf_xml_parser->xml_writer)
goto oom;
raptor_xml_writer_set_option(rdf_xml_parser->xml_writer,
RAPTOR_OPTION_WRITER_XML_DECLARATION,
NULL, 0);
element->child_state = RAPTOR_STATE_PARSETYPE_LITERAL;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
}
} else {
/* Can only be the empty property element case
* http://www.w3.org/TR/rdf-syntax-grammar/#emptyPropertyElt
*/
/* The presence of the rdf:resource or rdf:nodeID
* attributes is checked at element close time
*/
/*
* Assign reified URI here so we don't reify property attributes
* using this id
*/
if(element->reified_id && !element->reified) {
raptor_uri* reified_uri;
reified_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
element->reified_id);
if(!reified_uri)
goto oom;
element->reified = raptor_new_term_from_uri(rdf_parser->world,
reified_uri);
raptor_free_uri(reified_uri);
if(!element->reified)
goto oom;
}
if(element->rdf_attr[RDF_NS_resource] ||
element->rdf_attr[RDF_NS_nodeID]) {
/* Done - wait for end of this element to end in order to
* check the element was empty as expected */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
} else {
/* Otherwise process content in obj (value) state */
element->child_state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT;
}
}
finished = 1;
break;
case RAPTOR_STATE_INVALID:
default:
raptor_parser_fatal_error(rdf_parser,
"%s Internal error - unexpected parser state %d - %s",
__func__,
state, raptor_rdfxml_state_as_string(state));
finished = 1;
} /* end switch */
if(state != element->state) {
element->state = state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Moved to state %d - %s\n", state,
raptor_rdfxml_state_as_string(state));
#endif
}
} /* end while */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
return;
oom:
raptor_parser_fatal_error(rdf_parser, "Out of memory, skipping");
element->state = RAPTOR_STATE_SKIPPING;
}
| +Info | 0 | raptor_rdfxml_start_element_grammar(raptor_parser *rdf_parser,
raptor_rdfxml_element *element)
{
raptor_rdfxml_parser *rdf_xml_parser;
int finished;
raptor_state state;
raptor_xml_element* xml_element;
raptor_qname* el_qname;
const unsigned char *el_name;
int element_in_rdf_ns;
int rc = 0;
raptor_uri* base_uri;
raptor_uri* element_name_uri;
rdf_xml_parser = (raptor_rdfxml_parser*)rdf_parser->context;
xml_element = element->xml_element;
el_qname = raptor_xml_element_get_name(xml_element);
el_name = el_qname->local_name;
element_in_rdf_ns = (el_qname->nspace && el_qname->nspace->is_rdf_ms);
base_uri = raptor_rdfxml_inscope_base_uri(rdf_parser);
element_name_uri = el_qname->uri;
state = element->state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Starting in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
finished = 0;
while(!finished) {
switch(state) {
case RAPTOR_STATE_SKIPPING:
element->child_state = state;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PRESERVED;
finished = 1;
break;
case RAPTOR_STATE_UNKNOWN:
/* found <rdf:RDF> ? */
if(element_in_rdf_ns) {
if(raptor_uri_equals(element_name_uri,
RAPTOR_RDF_RDF_URI(rdf_parser->world))) {
element->child_state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES;
/* Yes - need more content before can continue,
* so wait for another element
*/
finished = 1;
break;
}
if(raptor_uri_equals(element_name_uri,
RAPTOR_RDF_Description_URI(rdf_parser->world))) {
state = RAPTOR_STATE_DESCRIPTION;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
/* Yes - found something so move immediately to description */
break;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_nodeElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a node element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
}
/* If scanning for element, can continue */
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_SCANNING)) {
finished = 1;
break;
}
/* Otherwise the choice of the next state can be made
* from the current element by the OBJ state
*/
state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_NODES;
break;
case RAPTOR_STATE_NODE_ELEMENT_LIST:
/* Handling
* http://www.w3.org/TR/rdf-syntax-grammar/#nodeElementList
*
* Everything goes to nodeElement
*/
state = RAPTOR_STATE_NODE_ELEMENT;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
break;
case RAPTOR_STATE_DESCRIPTION:
case RAPTOR_STATE_NODE_ELEMENT:
case RAPTOR_STATE_PARSETYPE_RESOURCE:
case RAPTOR_STATE_PARSETYPE_COLLECTION:
/* Handling <rdf:Description> or other node element
* http://www.w3.org/TR/rdf-syntax-grammar/#nodeElement
*
* or a property element acting as a node element for
* rdf:parseType="Resource"
* http://www.w3.org/TR/rdf-syntax-grammar/#parseTypeResourcePropertyElt
* or rdf:parseType="Collection" (and daml:Collection)
* http://www.w3.org/TR/rdf-syntax-grammar/#parseTypeCollectionPropertyElt
*
* Only create a bag if bagID given
*/
if(!element_name_uri) {
/* We cannot handle this */
raptor_parser_warning(rdf_parser, "Using node element '%s' without a namespace is forbidden.",
el_qname->local_name);
raptor_rdfxml_update_document_locator(rdf_parser);
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_nodeElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a node element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
if(element->content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION &&
element->content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION &&
element->parent &&
(element->parent->state == RAPTOR_STATE_PROPERTYELT ||
element->parent->state == RAPTOR_STATE_MEMBER_PROPERTYELT) &&
element->parent->xml_element->content_element_seen > 1) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser, "The enclosing property already has an object");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(state == RAPTOR_STATE_NODE_ELEMENT ||
state == RAPTOR_STATE_DESCRIPTION ||
state == RAPTOR_STATE_PARSETYPE_COLLECTION) {
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_Description_URI(rdf_parser->world)))
state = RAPTOR_STATE_DESCRIPTION;
else
state = RAPTOR_STATE_NODE_ELEMENT;
}
if((element->rdf_attr[RDF_NS_ID]!=NULL) +
(element->rdf_attr[RDF_NS_about]!=NULL) +
(element->rdf_attr[RDF_NS_nodeID]!=NULL) > 1) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser, "Multiple attributes of rdf:ID, rdf:about and rdf:nodeID on element '%s' - only one allowed.", el_name);
}
if(element->rdf_attr[RDF_NS_ID]) {
unsigned char* subject_id;
raptor_uri* subject_uri;
subject_id = (unsigned char*)element->rdf_attr[RDF_NS_ID];
if(!raptor_valid_xml_ID(rdf_parser, subject_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:ID value '%s'",
subject_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, subject_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:ID value '%s'",
subject_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* after this, subject_id is the owner of the ID string */
element->rdf_attr[RDF_NS_ID] = NULL;
subject_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!subject_uri)
goto oom;
element->subject = raptor_new_term_from_uri(rdf_parser->world,
subject_uri);
raptor_free_uri(subject_uri);
if(!element->subject)
goto oom;
} else if(element->rdf_attr[RDF_NS_about]) {
raptor_uri* subject_uri;
subject_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
base_uri,
(const unsigned char*)element->rdf_attr[RDF_NS_about]);
if(!subject_uri)
goto oom;
element->subject = raptor_new_term_from_uri(rdf_parser->world,
subject_uri);
raptor_free_uri(subject_uri);
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_about]);
element->rdf_attr[RDF_NS_about] = NULL;
if(!element->subject)
goto oom;
} else if(element->rdf_attr[RDF_NS_nodeID]) {
unsigned char* subject_id;
subject_id = raptor_world_internal_generate_id(rdf_parser->world,
(unsigned char*)element->rdf_attr[RDF_NS_nodeID]);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
element->rdf_attr[RDF_NS_nodeID] = NULL;
if(!element->subject)
goto oom;
if(!raptor_valid_xml_ID(rdf_parser, element->subject->value.blank.string)) {
raptor_parser_error(rdf_parser, "Illegal rdf:nodeID value '%s'",
(const char*)element->subject->value.blank.string);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
} else if(element->parent &&
element->parent->child_content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION &&
element->parent->child_content_type != RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION &&
element->parent->object) {
/* copy from parent (property element), it has a URI for us */
element->subject = raptor_term_copy(element->parent->object);
} else {
unsigned char* subject_id;
subject_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!element->subject)
goto oom;
}
if(element->rdf_attr[RDF_NS_bagID]) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
unsigned char* bag_id;
raptor_uri* bag_uri = NULL;
bag_id = (unsigned char*)element->rdf_attr[RDF_NS_bagID];
element->rdf_attr[RDF_NS_bagID] = NULL;
bag_uri = raptor_new_uri_from_id(rdf_parser->world,
base_uri, bag_id);
if(!bag_uri) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
element->bag = raptor_new_term_from_uri(rdf_parser->world, bag_uri);
raptor_free_uri(bag_uri);
if(!raptor_valid_xml_ID(rdf_parser, bag_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, bag_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
RAPTOR_FREE(char*, bag_id);
raptor_parser_warning(rdf_parser, "rdf:bagID is deprecated.");
raptor_rdfxml_generate_statement(rdf_parser,
element->bag,
RAPTOR_RDF_type_URI(rdf_parser->world),
RAPTOR_RDF_Bag_term(rdf_parser->world),
NULL,
NULL);
} else {
/* bagID forbidden */
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden.");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
}
if(element->parent) {
/* In a rdf:parseType="Collection" the resources are appended
* to the list at the genid element->parent->tail_id
*/
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION ||
element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
/* <idList> rdf:type rdf:List */
const unsigned char * idList;
raptor_uri *predicate_uri;
raptor_term* idList_term;
raptor_term* object_term;
idList = raptor_world_generate_bnodeid(rdf_parser->world);
if(!idList)
goto oom;
/* idList string is saved below in element->parent->tail_id */
idList_term = raptor_new_term_from_blank(rdf_parser->world, idList);
if(!idList_term) {
RAPTOR_FREE(char*, idList);
goto oom;
}
if((element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ||
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_RDF_TYPE_RDF_LIST)) {
raptor_uri* class_uri = NULL;
if(element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) {
class_uri = RAPTOR_DAML_List_URI(rdf_xml_parser);
object_term = raptor_new_term_from_uri(rdf_parser->world,
class_uri);
} else
object_term = raptor_term_copy(RAPTOR_RDF_List_term(rdf_parser->world));
raptor_rdfxml_generate_statement(rdf_parser,
idList_term,
RAPTOR_RDF_type_URI(rdf_parser->world),
object_term,
NULL,
element);
raptor_free_term(object_term);
}
predicate_uri = (element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ? RAPTOR_DAML_first_URI(rdf_xml_parser) : RAPTOR_RDF_first_URI(rdf_parser->world);
/* <idList> rdf:first <element->uri> */
raptor_rdfxml_generate_statement(rdf_parser,
idList_term,
predicate_uri,
element->subject,
NULL,
NULL);
/* If there is no rdf:parseType="Collection" */
if(!element->parent->tail_id) {
/* Free any existing object still around.
* I suspect this can never happen.
*/
if(element->parent->object)
raptor_free_term(element->parent->object);
element->parent->object = raptor_new_term_from_blank(rdf_parser->world,
idList);
} else {
raptor_term* tail_id_term;
tail_id_term = raptor_new_term_from_blank(rdf_parser->world,
element->parent->tail_id);
predicate_uri = (element->content_type == RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION) ? RAPTOR_DAML_rest_URI(rdf_xml_parser) : RAPTOR_RDF_rest_URI(rdf_parser->world);
/* _:tail_id rdf:rest _:listRest */
raptor_rdfxml_generate_statement(rdf_parser,
tail_id_term,
predicate_uri,
idList_term,
NULL,
NULL);
raptor_free_term(tail_id_term);
}
/* update new tail */
if(element->parent->tail_id)
RAPTOR_FREE(char*, (char*)element->parent->tail_id);
element->parent->tail_id = idList;
raptor_free_term(idList_term);
} else if(element->parent->state != RAPTOR_STATE_UNKNOWN &&
element->state != RAPTOR_STATE_PARSETYPE_RESOURCE) {
/* If there is a parent element (property) containing this
* element (node) and it has no object, set it from this subject
*/
if(element->parent->object) {
raptor_rdfxml_update_document_locator(rdf_parser);
raptor_parser_error(rdf_parser,
"Tried to set multiple objects of a statement");
} else {
/* Store URI of this node in our parent as the property object */
element->parent->object = raptor_term_copy(element->subject);
element->parent->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
}
}
}
/* If this is a node element, generate the rdf:type statement
* from this node
*/
if(state == RAPTOR_STATE_NODE_ELEMENT) {
raptor_term* el_name_term;
el_name_term = raptor_new_term_from_uri(rdf_parser->world,
element_name_uri);
raptor_rdfxml_generate_statement(rdf_parser,
element->subject,
RAPTOR_RDF_type_URI(rdf_parser->world),
el_name_term,
element->reified,
element);
raptor_free_term(el_name_term);
}
if(raptor_rdfxml_process_property_attributes(rdf_parser, element,
element, NULL))
goto oom;
/* for both productions now need some more content or
* property elements before can do any more work.
*/
element->child_state = RAPTOR_STATE_PROPERTYELT;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
finished = 1;
break;
case RAPTOR_STATE_PARSETYPE_OTHER:
/* FALLTHROUGH */
case RAPTOR_STATE_PARSETYPE_LITERAL:
raptor_xml_writer_start_element(rdf_xml_parser->xml_writer, xml_element);
element->child_state = RAPTOR_STATE_PARSETYPE_LITERAL;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
finished = 1;
break;
/* Handle all the detail of the various options of property element
* http://www.w3.org/TR/rdf-syntax-grammar/#propertyElt
*
* All the attributes must be scanned here to see what additional
* property element work is needed. No triples are generated
* until the end of this element, until it is clear if the
* element was empty.
*/
case RAPTOR_STATE_MEMBER_PROPERTYELT:
case RAPTOR_STATE_PROPERTYELT:
if(!element_name_uri) {
raptor_parser_error(rdf_parser, "Using property element '%s' without a namespace is forbidden.",
raptor_xml_element_get_name(element->parent->xml_element)->local_name);
raptor_rdfxml_update_document_locator(rdf_parser);
element->state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* Handling rdf:li as a property, noting special processing */
if(element_in_rdf_ns &&
raptor_uri_equals(element_name_uri,
RAPTOR_RDF_li_URI(rdf_parser->world))) {
state = RAPTOR_STATE_MEMBER_PROPERTYELT;
}
if(element_in_rdf_ns) {
rc = raptor_rdfxml_check_propertyElement_name((const char*)el_name);
if(!rc) {
raptor_parser_error(rdf_parser,
"rdf:%s is forbidden as a property element.",
el_name);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
} else if(rc < 0) {
raptor_parser_warning(rdf_parser,
"rdf:%s is an unknown RDF namespaced element.",
el_name);
}
}
/* rdf:ID on a property element - reify a statement.
* Allowed on all property element forms
*/
if(element->rdf_attr[RDF_NS_ID]) {
raptor_uri *reified_uri;
element->reified_id = element->rdf_attr[RDF_NS_ID];
element->rdf_attr[RDF_NS_ID] = NULL;
reified_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
element->reified_id);
if(!reified_uri)
goto oom;
element->reified = raptor_new_term_from_uri(rdf_parser->world,
reified_uri);
raptor_free_uri(reified_uri);
if(!element->reified)
goto oom;
if(!raptor_valid_xml_ID(rdf_parser, element->reified_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:ID value '%s'",
element->reified_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, element->reified_id)) {
raptor_parser_error(rdf_parser, "Duplicated rdf:ID value '%s'",
element->reified_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
}
/* rdf:datatype on a property element.
* Only allowed for
* http://www.w3.org/TR/rdf-syntax-grammar/#literalPropertyElt
*/
if(element->rdf_attr[RDF_NS_datatype]) {
raptor_uri *datatype_uri;
datatype_uri = raptor_new_uri_relative_to_base(rdf_parser->world,
base_uri,
(const unsigned char*)element->rdf_attr[RDF_NS_datatype]);
element->object_literal_datatype = datatype_uri;
RAPTOR_FREE(char*, element->rdf_attr[RDF_NS_datatype]);
element->rdf_attr[RDF_NS_datatype] = NULL;
if(!element->object_literal_datatype)
goto oom;
}
if(element->rdf_attr[RDF_NS_bagID]) {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_BAGID)) {
if(element->rdf_attr[RDF_NS_resource] ||
element->rdf_attr[RDF_NS_parseType]) {
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden on property element '%s' with an rdf:resource or rdf:parseType attribute.", el_name);
/* prevent this being used later either */
element->rdf_attr[RDF_NS_bagID] = NULL;
} else {
unsigned char* bag_id;
raptor_uri* bag_uri;
bag_id = (unsigned char*)element->rdf_attr[RDF_NS_bagID];
element->rdf_attr[RDF_NS_bagID] = NULL;
bag_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
bag_id);
if(!bag_uri) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
element->bag = raptor_new_term_from_uri(rdf_parser->world,
bag_uri);
raptor_free_uri(bag_uri);
if(!element->bag) {
RAPTOR_FREE(char*, bag_id);
goto oom;
}
if(!raptor_valid_xml_ID(rdf_parser, bag_id)) {
raptor_parser_error(rdf_parser, "Illegal rdf:bagID value '%s'",
bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
RAPTOR_FREE(char*, bag_id);
break;
}
if(raptor_rdfxml_record_ID(rdf_parser, element, bag_id)) {
raptor_parser_error(rdf_parser,
"Duplicated rdf:bagID value '%s'", bag_id);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
RAPTOR_FREE(char*, bag_id);
finished = 1;
break;
}
RAPTOR_FREE(char*, bag_id);
raptor_parser_warning(rdf_parser, "rdf:bagID is deprecated.");
}
} else {
/* bagID forbidden */
raptor_parser_error(rdf_parser, "rdf:bagID is forbidden.");
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
} /* if rdf:bagID on property element */
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT;
if(element->rdf_attr[RDF_NS_parseType]) {
const unsigned char *parse_type;
int i;
int is_parseType_Literal = 0;
parse_type = element->rdf_attr[RDF_NS_parseType];
if(raptor_rdfxml_element_has_property_attributes(element)) {
raptor_parser_error(rdf_parser, "Property attributes cannot be used with rdf:parseType='%s'", parse_type);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
finished = 1;
break;
}
/* Check for bad combinations of things with parseType */
for(i = 0; i <= RDF_NS_LAST; i++)
if(element->rdf_attr[i] && i != RDF_NS_parseType) {
raptor_parser_error(rdf_parser, "Attribute '%s' cannot be used with rdf:parseType='%s'", raptor_rdf_ns_terms_info[i].name, parse_type);
state = RAPTOR_STATE_SKIPPING;
element->child_state = RAPTOR_STATE_SKIPPING;
break;
}
if(!strcmp((char*)parse_type, "Literal"))
is_parseType_Literal = 1;
else if(!strcmp((char*)parse_type, "Resource")) {
unsigned char* subject_id;
state = RAPTOR_STATE_PARSETYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PROPERTYELT;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTIES;
/* create a node for the subject of the contained properties */
subject_id = raptor_world_generate_bnodeid(rdf_parser->world);
if(!subject_id)
goto oom;
element->subject = raptor_new_term_from_blank(rdf_parser->world,
subject_id);
RAPTOR_FREE(char*, subject_id);
if(!element->subject)
goto oom;
} else if(!strcmp((char*)parse_type, "Collection")) {
/* An rdf:parseType="Collection" appears as a single node */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PARSETYPE_COLLECTION;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_COLLECTION;
} else {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_ALLOW_OTHER_PARSETYPES) &&
!raptor_strcasecmp((char*)parse_type, "daml:collection")) {
/* A DAML collection appears as a single node */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
element->child_state = RAPTOR_STATE_PARSETYPE_COLLECTION;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_DAML_COLLECTION;
} else {
if(RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_WARN_OTHER_PARSETYPES)) {
raptor_parser_warning(rdf_parser, "Unknown rdf:parseType value '%s' taken as 'Literal'", parse_type);
}
is_parseType_Literal = 1;
}
}
if(is_parseType_Literal) {
raptor_xml_writer* xml_writer;
/* rdf:parseType="Literal" - explicitly or default
* if the parseType value is not recognised
*/
rdf_xml_parser->xml_content = NULL;
rdf_xml_parser->xml_content_length = 0;
rdf_xml_parser->iostream =
raptor_new_iostream_to_string(rdf_parser->world,
&rdf_xml_parser->xml_content,
&rdf_xml_parser->xml_content_length,
raptor_alloc_memory);
if(!rdf_xml_parser->iostream)
goto oom;
xml_writer = raptor_new_xml_writer(rdf_parser->world, NULL,
rdf_xml_parser->iostream);
rdf_xml_parser->xml_writer = xml_writer;
if(!rdf_xml_parser->xml_writer)
goto oom;
raptor_xml_writer_set_option(rdf_xml_parser->xml_writer,
RAPTOR_OPTION_WRITER_XML_DECLARATION,
NULL, 0);
element->child_state = RAPTOR_STATE_PARSETYPE_LITERAL;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
element->child_content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_XML_LITERAL;
}
} else {
/* Can only be the empty property element case
* http://www.w3.org/TR/rdf-syntax-grammar/#emptyPropertyElt
*/
/* The presence of the rdf:resource or rdf:nodeID
* attributes is checked at element close time
*/
/*
* Assign reified URI here so we don't reify property attributes
* using this id
*/
if(element->reified_id && !element->reified) {
raptor_uri* reified_uri;
reified_uri = raptor_new_uri_from_id(rdf_parser->world, base_uri,
element->reified_id);
if(!reified_uri)
goto oom;
element->reified = raptor_new_term_from_uri(rdf_parser->world,
reified_uri);
raptor_free_uri(reified_uri);
if(!element->reified)
goto oom;
}
if(element->rdf_attr[RDF_NS_resource] ||
element->rdf_attr[RDF_NS_nodeID]) {
/* Done - wait for end of this element to end in order to
* check the element was empty as expected */
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_RESOURCE;
} else {
/* Otherwise process content in obj (value) state */
element->child_state = RAPTOR_STATE_NODE_ELEMENT_LIST;
element->content_type = RAPTOR_RDFXML_ELEMENT_CONTENT_TYPE_PROPERTY_CONTENT;
}
}
finished = 1;
break;
case RAPTOR_STATE_INVALID:
default:
raptor_parser_fatal_error(rdf_parser,
"%s Internal error - unexpected parser state %d - %s",
__func__,
state, raptor_rdfxml_state_as_string(state));
finished = 1;
} /* end switch */
if(state != element->state) {
element->state = state;
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG3("Moved to state %d - %s\n", state,
raptor_rdfxml_state_as_string(state));
#endif
}
} /* end while */
#ifdef RAPTOR_DEBUG_VERBOSE
RAPTOR_DEBUG2("Ending in state %s\n", raptor_rdfxml_state_as_string(state));
#endif
return;
oom:
raptor_parser_fatal_error(rdf_parser, "Out of memory, skipping");
element->state = RAPTOR_STATE_SKIPPING;
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,607 | static const char * raptor_rdfxml_state_as_string(raptor_state state)
{
if(state < 1 || state > RAPTOR_STATE_PARSETYPE_LAST)
state = (raptor_state)0;
return raptor_state_names[(int)state];
}
| +Info | 0 | static const char * raptor_rdfxml_state_as_string(raptor_state state)
{
if(state < 1 || state > RAPTOR_STATE_PARSETYPE_LAST)
state = (raptor_state)0;
return raptor_state_names[(int)state];
}
| @@ -1004,6 +1004,9 @@ raptor_rdfxml_parse_start(raptor_parser* rdf_parser)
raptor_sax2_set_option(rdf_xml_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rdf_xml_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rdf_xml_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,608 | raptor_free_rss_element(raptor_rss_element *rss_element)
{
if(rss_element->uri)
raptor_free_uri(rss_element->uri);
if(rss_element->type == RAPTOR_RSS_CONTENT_TYPE_XML) {
if(rss_element->xml_writer)
raptor_free_xml_writer(rss_element->xml_writer);
if(rss_element->iostream)
raptor_free_iostream(rss_element->iostream);
if(rss_element->xml_content)
raptor_free_memory(rss_element->xml_content);
}
if(rss_element->sb)
raptor_free_stringbuffer(rss_element->sb);
RAPTOR_FREE(raptor_rss_element, rss_element);
}
| +Info | 0 | raptor_free_rss_element(raptor_rss_element *rss_element)
{
if(rss_element->uri)
raptor_free_uri(rss_element->uri);
if(rss_element->type == RAPTOR_RSS_CONTENT_TYPE_XML) {
if(rss_element->xml_writer)
raptor_free_xml_writer(rss_element->xml_writer);
if(rss_element->iostream)
raptor_free_iostream(rss_element->iostream);
if(rss_element->xml_content)
raptor_free_memory(rss_element->xml_content);
}
if(rss_element->sb)
raptor_free_stringbuffer(rss_element->sb);
RAPTOR_FREE(raptor_rss_element, rss_element);
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,609 | raptor_init_parser_rss(raptor_world* world)
{
return !raptor_world_register_parser_factory(world,
&raptor_rss_parser_register_factory);
}
| +Info | 0 | raptor_init_parser_rss(raptor_world* world)
{
return !raptor_world_register_parser_factory(world,
&raptor_rss_parser_register_factory);
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,610 | raptor_rss_block_set_field(raptor_world *world, raptor_uri *base_uri,
raptor_rss_block *block,
const raptor_rss_block_field_info *bfi,
const char *string)
{
int attribute_type = bfi->attribute_type;
int offset = bfi->offset;
if(attribute_type == RSS_BLOCK_FIELD_TYPE_URL) {
raptor_uri* uri;
uri = raptor_new_uri_relative_to_base(world, base_uri,
(const unsigned char*)string);
if(!uri)
return 1;
block->urls[offset] = uri;
} else if(attribute_type == RSS_BLOCK_FIELD_TYPE_STRING) {
size_t len = strlen(string);
block->strings[offset] = RAPTOR_MALLOC(char*, len + 1);
if(!block->strings[offset])
return 1;
memcpy(block->strings[offset], string, len+1);
} else {
#ifdef RAPTOR_DEBUG
RAPTOR_FATAL2("Found unknown attribute_type %d\n", attribute_type);
#endif
return 1;
}
return 0;
}
| +Info | 0 | raptor_rss_block_set_field(raptor_world *world, raptor_uri *base_uri,
raptor_rss_block *block,
const raptor_rss_block_field_info *bfi,
const char *string)
{
int attribute_type = bfi->attribute_type;
int offset = bfi->offset;
if(attribute_type == RSS_BLOCK_FIELD_TYPE_URL) {
raptor_uri* uri;
uri = raptor_new_uri_relative_to_base(world, base_uri,
(const unsigned char*)string);
if(!uri)
return 1;
block->urls[offset] = uri;
} else if(attribute_type == RSS_BLOCK_FIELD_TYPE_STRING) {
size_t len = strlen(string);
block->strings[offset] = RAPTOR_MALLOC(char*, len + 1);
if(!block->strings[offset])
return 1;
memcpy(block->strings[offset], string, len+1);
} else {
#ifdef RAPTOR_DEBUG
RAPTOR_FATAL2("Found unknown attribute_type %d\n", attribute_type);
#endif
return 1;
}
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,611 | raptor_rss_copy_field(raptor_rss_parser* rss_parser,
raptor_rss_item* item,
const raptor_field_pair* pair)
{
raptor_rss_fields_type from_field = pair->from;
raptor_rss_fields_type to_field = pair->to;
raptor_rss_field* field = NULL;
if(!(item->fields[from_field] && item->fields[from_field]->value))
return 1;
if(from_field == to_field) {
field = item->fields[from_field];
} else {
if(item->fields[to_field] && item->fields[to_field]->value)
return 1;
field = raptor_rss_new_field(item->world);
field->is_mapped = 1;
raptor_rss_item_add_field(item, to_field, field);
}
/* Ensure output namespace is declared */
rss_parser->nspaces_seen[raptor_rss_fields_info[to_field].nspace] = 'Y';
if(!field->value) {
if(pair->conversion)
pair->conversion(item->fields[from_field], field);
else {
size_t len;
/* Otherwise default action is to copy from_field value */
len = strlen((const char*)item->fields[from_field]->value);
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value)
return 1;
memcpy(field->value, item->fields[from_field]->value, len + 1);
}
}
return 0;
}
| +Info | 0 | raptor_rss_copy_field(raptor_rss_parser* rss_parser,
raptor_rss_item* item,
const raptor_field_pair* pair)
{
raptor_rss_fields_type from_field = pair->from;
raptor_rss_fields_type to_field = pair->to;
raptor_rss_field* field = NULL;
if(!(item->fields[from_field] && item->fields[from_field]->value))
return 1;
if(from_field == to_field) {
field = item->fields[from_field];
} else {
if(item->fields[to_field] && item->fields[to_field]->value)
return 1;
field = raptor_rss_new_field(item->world);
field->is_mapped = 1;
raptor_rss_item_add_field(item, to_field, field);
}
/* Ensure output namespace is declared */
rss_parser->nspaces_seen[raptor_rss_fields_info[to_field].nspace] = 'Y';
if(!field->value) {
if(pair->conversion)
pair->conversion(item->fields[from_field], field);
else {
size_t len;
/* Otherwise default action is to copy from_field value */
len = strlen((const char*)item->fields[from_field]->value);
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value)
return 1;
memcpy(field->value, item->fields[from_field]->value, len + 1);
}
}
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,612 | raptor_rss_emit(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
int rc = 0;
if(!rss_parser->model.common[RAPTOR_RSS_CHANNEL]) {
raptor_parser_error(rdf_parser, "No RSS channel item present");
return 1;
}
if(!rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term) {
raptor_parser_error(rdf_parser, "RSS channel has no identifier");
return 1;
}
/* Emit start default graph mark */
raptor_parser_start_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph++;
/* Emit all the common type blocks (channel, author, ...) */
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
if(!item->fields_count)
continue;
RAPTOR_DEBUG3("Emitting type %i - %s\n", i, raptor_rss_items_info[i].name);
if(!item->term) {
raptor_parser_error(rdf_parser, "RSS %s has no identifier",
raptor_rss_items_info[i].name);
rc = 1;
goto tidy;
}
if(raptor_rss_emit_item(rdf_parser, item)) {
rc = 1;
goto tidy;
}
/* Add connections to channel */
if(i != RAPTOR_RSS_CHANNEL) {
if(raptor_rss_emit_connection(rdf_parser,
rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term,
rdf_parser->world->rss_types_info_uris[i], 0,
item->term)) {
rc = 1;
goto tidy;
}
}
}
}
/* Emit the feed item blocks */
if(rss_parser->model.items_count) {
const unsigned char* id;
raptor_term *items;
id = raptor_world_generate_bnodeid(rdf_parser->world);
/* make a new genid for the <rdf:Seq> node */
items = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
/* _:genid1 rdf:type rdf:Seq . */
if(raptor_rss_emit_type_triple(rdf_parser, items,
RAPTOR_RDF_Seq_URI(rdf_parser->world))) {
raptor_free_term(items);
rc = 1;
goto tidy;
}
/* <channelURI> rss:items _:genid1 . */
if(raptor_rss_emit_connection(rdf_parser,
rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term,
rdf_parser->world->rss_fields_info_uris[RAPTOR_RSS_FIELD_ITEMS], 0,
items)) {
raptor_free_term(items);
rc= 1;
goto tidy;
}
/* sequence of rss:item */
for(i = 1, item = rss_parser->model.items; item; item = item->next, i++) {
if(raptor_rss_emit_item(rdf_parser, item) ||
raptor_rss_emit_connection(rdf_parser, items, NULL, i,item->term)) {
raptor_free_term(items);
rc = 1;
goto tidy;
}
}
raptor_free_term(items);
}
tidy:
if(rdf_parser->emitted_default_graph) {
raptor_parser_end_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph--;
}
return rc;
}
| +Info | 0 | raptor_rss_emit(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
int rc = 0;
if(!rss_parser->model.common[RAPTOR_RSS_CHANNEL]) {
raptor_parser_error(rdf_parser, "No RSS channel item present");
return 1;
}
if(!rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term) {
raptor_parser_error(rdf_parser, "RSS channel has no identifier");
return 1;
}
/* Emit start default graph mark */
raptor_parser_start_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph++;
/* Emit all the common type blocks (channel, author, ...) */
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
if(!item->fields_count)
continue;
RAPTOR_DEBUG3("Emitting type %i - %s\n", i, raptor_rss_items_info[i].name);
if(!item->term) {
raptor_parser_error(rdf_parser, "RSS %s has no identifier",
raptor_rss_items_info[i].name);
rc = 1;
goto tidy;
}
if(raptor_rss_emit_item(rdf_parser, item)) {
rc = 1;
goto tidy;
}
/* Add connections to channel */
if(i != RAPTOR_RSS_CHANNEL) {
if(raptor_rss_emit_connection(rdf_parser,
rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term,
rdf_parser->world->rss_types_info_uris[i], 0,
item->term)) {
rc = 1;
goto tidy;
}
}
}
}
/* Emit the feed item blocks */
if(rss_parser->model.items_count) {
const unsigned char* id;
raptor_term *items;
id = raptor_world_generate_bnodeid(rdf_parser->world);
/* make a new genid for the <rdf:Seq> node */
items = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
/* _:genid1 rdf:type rdf:Seq . */
if(raptor_rss_emit_type_triple(rdf_parser, items,
RAPTOR_RDF_Seq_URI(rdf_parser->world))) {
raptor_free_term(items);
rc = 1;
goto tidy;
}
/* <channelURI> rss:items _:genid1 . */
if(raptor_rss_emit_connection(rdf_parser,
rss_parser->model.common[RAPTOR_RSS_CHANNEL]->term,
rdf_parser->world->rss_fields_info_uris[RAPTOR_RSS_FIELD_ITEMS], 0,
items)) {
raptor_free_term(items);
rc= 1;
goto tidy;
}
/* sequence of rss:item */
for(i = 1, item = rss_parser->model.items; item; item = item->next, i++) {
if(raptor_rss_emit_item(rdf_parser, item) ||
raptor_rss_emit_connection(rdf_parser, items, NULL, i,item->term)) {
raptor_free_term(items);
rc = 1;
goto tidy;
}
}
raptor_free_term(items);
}
tidy:
if(rdf_parser->emitted_default_graph) {
raptor_parser_end_graph(rdf_parser, NULL, 0);
rdf_parser->emitted_default_graph--;
}
return rc;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,613 | raptor_rss_emit_block(raptor_parser* rdf_parser,
raptor_term *resource,
raptor_rss_block *block)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_rss_type block_type = block->rss_type;
raptor_uri *predicate_uri;
raptor_term *predicate_term = NULL;
const raptor_rss_block_field_info *bfi;
raptor_rss_fields_type predicate_field;
if(!block->identifier) {
raptor_parser_error(rdf_parser, "Block has no identifier");
return 1;
}
predicate_field = raptor_rss_items_info[block_type].predicate;
predicate_uri = rdf_parser->world->rss_fields_info_uris[predicate_field];
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.subject = resource;
rss_parser->statement.predicate = predicate_term;
rss_parser->statement.object = block->identifier;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(predicate_term); predicate_term = NULL;
if(raptor_rss_emit_type_triple(rdf_parser, block->identifier,
block->node_type))
return 1;
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
int attribute_type;
int offset;
if(bfi->type != block_type || !bfi->attribute)
continue;
attribute_type = bfi->attribute_type;
offset = bfi->offset;
predicate_uri = rdf_parser->world->rss_fields_info_uris[bfi->field];
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.predicate = predicate_term;
if(attribute_type == RSS_BLOCK_FIELD_TYPE_URL) {
raptor_uri *uri = block->urls[offset];
if(uri) {
raptor_term* object_term;
object_term = raptor_new_term_from_uri(rdf_parser->world, uri);
rss_parser->statement.object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(object_term);
}
} else if(attribute_type == RSS_BLOCK_FIELD_TYPE_STRING) {
const char *str = block->strings[offset];
if(str) {
raptor_term* object_term;
object_term = raptor_new_term_from_literal(rdf_parser->world,
(const unsigned char*)str,
NULL, NULL);
rss_parser->statement.object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(object_term);
}
} else {
#ifdef RAPTOR_DEBUG
RAPTOR_FATAL2("Found unknown attribute_type %d\n", attribute_type);
#endif
}
raptor_free_term(predicate_term); predicate_term = NULL;
}
return 0;
}
| +Info | 0 | raptor_rss_emit_block(raptor_parser* rdf_parser,
raptor_term *resource,
raptor_rss_block *block)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_rss_type block_type = block->rss_type;
raptor_uri *predicate_uri;
raptor_term *predicate_term = NULL;
const raptor_rss_block_field_info *bfi;
raptor_rss_fields_type predicate_field;
if(!block->identifier) {
raptor_parser_error(rdf_parser, "Block has no identifier");
return 1;
}
predicate_field = raptor_rss_items_info[block_type].predicate;
predicate_uri = rdf_parser->world->rss_fields_info_uris[predicate_field];
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.subject = resource;
rss_parser->statement.predicate = predicate_term;
rss_parser->statement.object = block->identifier;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(predicate_term); predicate_term = NULL;
if(raptor_rss_emit_type_triple(rdf_parser, block->identifier,
block->node_type))
return 1;
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
int attribute_type;
int offset;
if(bfi->type != block_type || !bfi->attribute)
continue;
attribute_type = bfi->attribute_type;
offset = bfi->offset;
predicate_uri = rdf_parser->world->rss_fields_info_uris[bfi->field];
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.predicate = predicate_term;
if(attribute_type == RSS_BLOCK_FIELD_TYPE_URL) {
raptor_uri *uri = block->urls[offset];
if(uri) {
raptor_term* object_term;
object_term = raptor_new_term_from_uri(rdf_parser->world, uri);
rss_parser->statement.object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(object_term);
}
} else if(attribute_type == RSS_BLOCK_FIELD_TYPE_STRING) {
const char *str = block->strings[offset];
if(str) {
raptor_term* object_term;
object_term = raptor_new_term_from_literal(rdf_parser->world,
(const unsigned char*)str,
NULL, NULL);
rss_parser->statement.object = object_term;
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(object_term);
}
} else {
#ifdef RAPTOR_DEBUG
RAPTOR_FATAL2("Found unknown attribute_type %d\n", attribute_type);
#endif
}
raptor_free_term(predicate_term); predicate_term = NULL;
}
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,614 | raptor_rss_emit_connection(raptor_parser* rdf_parser,
raptor_term *subject_identifier,
raptor_uri* predicate_uri, int predicate_ordinal,
raptor_term *object_identifier)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_uri *puri = NULL;
raptor_term *predicate_term = NULL;
if(!subject_identifier) {
raptor_parser_error(rdf_parser, "Connection subject has no identifier");
return 1;
}
rss_parser->statement.subject = subject_identifier;
if(!predicate_uri) {
/* new URI object */
puri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, predicate_ordinal);
predicate_uri = puri;
}
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.predicate = predicate_term;
rss_parser->statement.object = object_identifier;
/* Generate the statement */
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(predicate_term);
if(puri)
raptor_free_uri(puri);
return 0;
}
| +Info | 0 | raptor_rss_emit_connection(raptor_parser* rdf_parser,
raptor_term *subject_identifier,
raptor_uri* predicate_uri, int predicate_ordinal,
raptor_term *object_identifier)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_uri *puri = NULL;
raptor_term *predicate_term = NULL;
if(!subject_identifier) {
raptor_parser_error(rdf_parser, "Connection subject has no identifier");
return 1;
}
rss_parser->statement.subject = subject_identifier;
if(!predicate_uri) {
/* new URI object */
puri = raptor_new_uri_from_rdf_ordinal(rdf_parser->world, predicate_ordinal);
predicate_uri = puri;
}
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
predicate_uri);
rss_parser->statement.predicate = predicate_term;
rss_parser->statement.object = object_identifier;
/* Generate the statement */
(*rdf_parser->statement_handler)(rdf_parser->user_data,
&rss_parser->statement);
raptor_free_term(predicate_term);
if(puri)
raptor_free_uri(puri);
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,615 | raptor_rss_emit_type_triple(raptor_parser* rdf_parser,
raptor_term *resource,
raptor_uri *type_uri)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_term *predicate_term;
raptor_term *object_term;
if(!resource) {
raptor_parser_error(rdf_parser, "RSS node has no identifier");
return 1;
}
rss_parser->statement.subject = resource;
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
RAPTOR_RDF_type_URI(rdf_parser->world));
rss_parser->statement.predicate = predicate_term;
object_term = raptor_new_term_from_uri(rdf_parser->world, type_uri);
rss_parser->statement.object = object_term;
/* Generate the statement */
(*rdf_parser->statement_handler)(rdf_parser->user_data, &rss_parser->statement);
raptor_free_term(predicate_term);
raptor_free_term(object_term);
return 0;
}
| +Info | 0 | raptor_rss_emit_type_triple(raptor_parser* rdf_parser,
raptor_term *resource,
raptor_uri *type_uri)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_term *predicate_term;
raptor_term *object_term;
if(!resource) {
raptor_parser_error(rdf_parser, "RSS node has no identifier");
return 1;
}
rss_parser->statement.subject = resource;
predicate_term = raptor_new_term_from_uri(rdf_parser->world,
RAPTOR_RDF_type_URI(rdf_parser->world));
rss_parser->statement.predicate = predicate_term;
object_term = raptor_new_term_from_uri(rdf_parser->world, type_uri);
rss_parser->statement.object = object_term;
/* Generate the statement */
(*rdf_parser->statement_handler)(rdf_parser->user_data, &rss_parser->statement);
raptor_free_term(predicate_term);
raptor_free_term(object_term);
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,616 | raptor_rss_end_element_handler(void *user_data,
raptor_xml_element* xml_element)
{
raptor_parser* rdf_parser;
raptor_rss_parser* rss_parser;
#ifdef RAPTOR_DEBUG
const unsigned char* name = raptor_xml_element_get_name(xml_element)->local_name;
#endif
raptor_rss_element* rss_element;
size_t cdata_len = 0;
unsigned char* cdata = NULL;
rss_element = (raptor_rss_element*)xml_element->user_data;
rdf_parser = (raptor_parser*)user_data;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
if(rss_element->xml_writer) {
if(rss_element->type != RAPTOR_RSS_CONTENT_TYPE_XML) {
raptor_xml_writer_end_element(rss_element->xml_writer, xml_element);
goto tidy_end_element;
}
/* otherwise we are done making XML */
raptor_free_iostream(rss_element->iostream);
rss_element->iostream = NULL;
cdata = (unsigned char*)rss_element->xml_content;
cdata_len = rss_element->xml_content_length;
}
if(rss_element->sb) {
cdata_len = raptor_stringbuffer_length(rss_element->sb);
cdata = raptor_stringbuffer_as_string(rss_element->sb);
}
if(cdata) {
raptor_uri* base_uri = NULL;
base_uri = raptor_sax2_inscope_base_uri(rss_parser->sax2);
if(rss_parser->current_block) {
const raptor_rss_block_field_info *bfi;
int handled = 0;
/* in a block, maybe store the CDATA there */
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
if(bfi->type != rss_parser->current_block->rss_type ||
bfi->attribute != NULL)
continue;
/* Set author name from element */
if(raptor_rss_block_set_field(rdf_parser->world, base_uri,
rss_parser->current_block,
bfi, (const char*)cdata)) {
rdf_parser->failed = 1;
return;
}
handled = 1;
break;
}
#ifdef RAPTOR_DEBUG
if(!handled) {
raptor_rss_type block_type = rss_parser->current_block->rss_type;
RAPTOR_DEBUG3("Ignoring cdata for block %d - %s\n",
block_type, raptor_rss_items_info[block_type].name);
}
#endif
rss_parser->current_block = NULL;
goto do_end_element;
}
if(rss_parser->current_type == RAPTOR_RSS_NONE ||
(rss_parser->current_field == RAPTOR_RSS_FIELD_NONE ||
rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN)) {
unsigned char *p = cdata;
size_t i;
for(i = cdata_len; i > 0 && *p; i--) {
if(!isspace(*p))
break;
p++;
}
if(i > 0 && *p) {
RAPTOR_DEBUG4("IGNORING non-whitespace text '%s' inside type %s, field %s\n", cdata,
raptor_rss_items_info[rss_parser->current_type].name,
raptor_rss_fields_info[rss_parser->current_field].name);
}
goto do_end_element;
}
if(rss_parser->current_type >= RAPTOR_RSS_COMMON_IGNORED) {
/* skipHours, skipDays common but IGNORED */
RAPTOR_DEBUG2("Ignoring fields for type %s\n", raptor_rss_items_info[rss_parser->current_type].name);
} else {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
/* if value is always an uri, make it so */
if(raptor_rss_fields_info[rss_parser->current_field].flags &
RAPTOR_RSS_INFO_FLAG_URI_VALUE) {
RAPTOR_DEBUG4("Added URI %s to field %s of type %s\n", cdata, raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri, cdata);
} else {
RAPTOR_DEBUG4("Added text '%s' to field %s of type %s\n", cdata, raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = NULL;
field->value = RAPTOR_MALLOC(unsigned char*, cdata_len + 1);
if(!field->value) {
rdf_parser->failed = 1;
return;
}
memcpy(field->value, cdata, cdata_len);
field->value[cdata_len] = '\0';
}
RAPTOR_DEBUG1("fa3 - ");
raptor_rss_item_add_field(update_item, rss_parser->current_field, field);
}
} /* end if contained cdata */
if(raptor_xml_element_is_empty(xml_element)) {
/* Empty element, so consider adding one of the attributes as
* literal or URI content
*/
if(rss_parser->current_type >= RAPTOR_RSS_COMMON_IGNORED) {
/* skipHours, skipDays common but IGNORED */
RAPTOR_DEBUG3("Ignoring empty element %s for type %s\n", name, raptor_rss_items_info[rss_parser->current_type].name);
} else if(rss_element->uri) {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
if(rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN) {
RAPTOR_DEBUG2("Cannot add URI from alternate attribute to type %s unknown field\n", raptor_rss_items_info[rss_parser->current_type].name);
raptor_rss_field_free(field);
} else {
RAPTOR_DEBUG3("Added URI to field %s of type %s\n", raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = rss_element->uri;
rss_element->uri = NULL;
RAPTOR_DEBUG1("fa2 - ");
raptor_rss_item_add_field(update_item, rss_parser->current_field, field);
}
}
}
do_end_element:
if(rss_parser->current_type != RAPTOR_RSS_NONE) {
if(rss_parser->current_field != RAPTOR_RSS_FIELD_NONE) {
RAPTOR_DEBUG3("Ending element %s field %s\n", name, raptor_rss_fields_info[rss_parser->current_field].name);
rss_parser->current_field = RAPTOR_RSS_FIELD_NONE;
} else {
RAPTOR_DEBUG3("Ending element %s type %s\n", name, raptor_rss_items_info[rss_parser->current_type].name);
if(rss_parser->prev_type != RAPTOR_RSS_NONE) {
rss_parser->current_type = rss_parser->prev_type;
rss_parser->prev_type = RAPTOR_RSS_NONE;
RAPTOR_DEBUG3("Returning to type %d - %s\n", rss_parser->current_type, raptor_rss_items_info[rss_parser->current_type].name);
} else
rss_parser->current_type = RAPTOR_RSS_NONE;
}
}
if(rss_parser->current_block) {
#ifdef RAPTOR_DEBUG
raptor_rss_type block_type = rss_parser->current_block->rss_type;
RAPTOR_DEBUG3("Ending current block %d - %s\n",
block_type, raptor_rss_items_info[block_type].name);
#endif
rss_parser->current_block = NULL;
}
tidy_end_element:
if(rss_element)
raptor_free_rss_element(rss_element);
}
| +Info | 0 | raptor_rss_end_element_handler(void *user_data,
raptor_xml_element* xml_element)
{
raptor_parser* rdf_parser;
raptor_rss_parser* rss_parser;
#ifdef RAPTOR_DEBUG
const unsigned char* name = raptor_xml_element_get_name(xml_element)->local_name;
#endif
raptor_rss_element* rss_element;
size_t cdata_len = 0;
unsigned char* cdata = NULL;
rss_element = (raptor_rss_element*)xml_element->user_data;
rdf_parser = (raptor_parser*)user_data;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
if(rss_element->xml_writer) {
if(rss_element->type != RAPTOR_RSS_CONTENT_TYPE_XML) {
raptor_xml_writer_end_element(rss_element->xml_writer, xml_element);
goto tidy_end_element;
}
/* otherwise we are done making XML */
raptor_free_iostream(rss_element->iostream);
rss_element->iostream = NULL;
cdata = (unsigned char*)rss_element->xml_content;
cdata_len = rss_element->xml_content_length;
}
if(rss_element->sb) {
cdata_len = raptor_stringbuffer_length(rss_element->sb);
cdata = raptor_stringbuffer_as_string(rss_element->sb);
}
if(cdata) {
raptor_uri* base_uri = NULL;
base_uri = raptor_sax2_inscope_base_uri(rss_parser->sax2);
if(rss_parser->current_block) {
const raptor_rss_block_field_info *bfi;
int handled = 0;
/* in a block, maybe store the CDATA there */
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
if(bfi->type != rss_parser->current_block->rss_type ||
bfi->attribute != NULL)
continue;
/* Set author name from element */
if(raptor_rss_block_set_field(rdf_parser->world, base_uri,
rss_parser->current_block,
bfi, (const char*)cdata)) {
rdf_parser->failed = 1;
return;
}
handled = 1;
break;
}
#ifdef RAPTOR_DEBUG
if(!handled) {
raptor_rss_type block_type = rss_parser->current_block->rss_type;
RAPTOR_DEBUG3("Ignoring cdata for block %d - %s\n",
block_type, raptor_rss_items_info[block_type].name);
}
#endif
rss_parser->current_block = NULL;
goto do_end_element;
}
if(rss_parser->current_type == RAPTOR_RSS_NONE ||
(rss_parser->current_field == RAPTOR_RSS_FIELD_NONE ||
rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN)) {
unsigned char *p = cdata;
size_t i;
for(i = cdata_len; i > 0 && *p; i--) {
if(!isspace(*p))
break;
p++;
}
if(i > 0 && *p) {
RAPTOR_DEBUG4("IGNORING non-whitespace text '%s' inside type %s, field %s\n", cdata,
raptor_rss_items_info[rss_parser->current_type].name,
raptor_rss_fields_info[rss_parser->current_field].name);
}
goto do_end_element;
}
if(rss_parser->current_type >= RAPTOR_RSS_COMMON_IGNORED) {
/* skipHours, skipDays common but IGNORED */
RAPTOR_DEBUG2("Ignoring fields for type %s\n", raptor_rss_items_info[rss_parser->current_type].name);
} else {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
/* if value is always an uri, make it so */
if(raptor_rss_fields_info[rss_parser->current_field].flags &
RAPTOR_RSS_INFO_FLAG_URI_VALUE) {
RAPTOR_DEBUG4("Added URI %s to field %s of type %s\n", cdata, raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri, cdata);
} else {
RAPTOR_DEBUG4("Added text '%s' to field %s of type %s\n", cdata, raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = NULL;
field->value = RAPTOR_MALLOC(unsigned char*, cdata_len + 1);
if(!field->value) {
rdf_parser->failed = 1;
return;
}
memcpy(field->value, cdata, cdata_len);
field->value[cdata_len] = '\0';
}
RAPTOR_DEBUG1("fa3 - ");
raptor_rss_item_add_field(update_item, rss_parser->current_field, field);
}
} /* end if contained cdata */
if(raptor_xml_element_is_empty(xml_element)) {
/* Empty element, so consider adding one of the attributes as
* literal or URI content
*/
if(rss_parser->current_type >= RAPTOR_RSS_COMMON_IGNORED) {
/* skipHours, skipDays common but IGNORED */
RAPTOR_DEBUG3("Ignoring empty element %s for type %s\n", name, raptor_rss_items_info[rss_parser->current_type].name);
} else if(rss_element->uri) {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
if(rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN) {
RAPTOR_DEBUG2("Cannot add URI from alternate attribute to type %s unknown field\n", raptor_rss_items_info[rss_parser->current_type].name);
raptor_rss_field_free(field);
} else {
RAPTOR_DEBUG3("Added URI to field %s of type %s\n", raptor_rss_fields_info[rss_parser->current_field].name, raptor_rss_items_info[rss_parser->current_type].name);
field->uri = rss_element->uri;
rss_element->uri = NULL;
RAPTOR_DEBUG1("fa2 - ");
raptor_rss_item_add_field(update_item, rss_parser->current_field, field);
}
}
}
do_end_element:
if(rss_parser->current_type != RAPTOR_RSS_NONE) {
if(rss_parser->current_field != RAPTOR_RSS_FIELD_NONE) {
RAPTOR_DEBUG3("Ending element %s field %s\n", name, raptor_rss_fields_info[rss_parser->current_field].name);
rss_parser->current_field = RAPTOR_RSS_FIELD_NONE;
} else {
RAPTOR_DEBUG3("Ending element %s type %s\n", name, raptor_rss_items_info[rss_parser->current_type].name);
if(rss_parser->prev_type != RAPTOR_RSS_NONE) {
rss_parser->current_type = rss_parser->prev_type;
rss_parser->prev_type = RAPTOR_RSS_NONE;
RAPTOR_DEBUG3("Returning to type %d - %s\n", rss_parser->current_type, raptor_rss_items_info[rss_parser->current_type].name);
} else
rss_parser->current_type = RAPTOR_RSS_NONE;
}
}
if(rss_parser->current_block) {
#ifdef RAPTOR_DEBUG
raptor_rss_type block_type = rss_parser->current_block->rss_type;
RAPTOR_DEBUG3("Ending current block %d - %s\n",
block_type, raptor_rss_items_info[block_type].name);
#endif
rss_parser->current_block = NULL;
}
tidy_end_element:
if(rss_element)
raptor_free_rss_element(rss_element);
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,617 | raptor_rss_get_current_item(raptor_rss_parser *rss_parser)
{
raptor_rss_item* item;
if(rss_parser->current_type == RAPTOR_RSS_ITEM)
item = rss_parser->model.last;
else
item = raptor_rss_model_get_common(&rss_parser->model,
rss_parser->current_type);
return item;
}
| +Info | 0 | raptor_rss_get_current_item(raptor_rss_parser *rss_parser)
{
raptor_rss_item* item;
if(rss_parser->current_type == RAPTOR_RSS_ITEM)
item = rss_parser->model.last;
else
item = raptor_rss_model_get_common(&rss_parser->model,
rss_parser->current_type);
return item;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,618 | raptor_rss_insert_identifiers(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
if(!item->fields_count)
continue;
RAPTOR_DEBUG3("Inserting identifiers in common type %d - %s\n", i, raptor_rss_items_info[i].name);
if(item->uri) {
item->term = raptor_new_term_from_uri(rdf_parser->world, item->uri);
} else {
int url_fields[2];
int url_fields_count = 1;
int f;
url_fields[0] = (i== RAPTOR_RSS_IMAGE) ? RAPTOR_RSS_FIELD_URL :
RAPTOR_RSS_FIELD_LINK;
if(i == RAPTOR_RSS_CHANNEL) {
url_fields[1] = RAPTOR_RSS_FIELD_ATOM_ID;
url_fields_count++;
}
for(f = 0; f < url_fields_count; f++) {
raptor_rss_field* field;
for(field = item->fields[url_fields[f]]; field; field = field->next) {
raptor_uri *new_uri = NULL;
if(field->value)
new_uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)field->value);
else if(field->uri)
new_uri = raptor_uri_copy(field->uri);
if(!new_uri)
return 1;
item->term = raptor_new_term_from_uri(rdf_parser->world, new_uri);
raptor_free_uri(new_uri);
if(!item->term)
return 1;
break;
}
}
if(!item->term) {
const unsigned char *id;
/* need to make bnode */
id = raptor_world_generate_bnodeid(rdf_parser->world);
item->term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
}
}
/* Try to add an rss:link if missing */
if(i == RAPTOR_RSS_CHANNEL && !item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(raptor_rss_insert_rss_link(rdf_parser, item))
return 1;
}
item->node_type = &raptor_rss_items_info[i];
item->node_typei = i;
}
}
/* sequence of rss:item */
for(item = rss_parser->model.items; item; item = item->next) {
raptor_rss_block *block;
raptor_uri* uri;
if(!item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(raptor_rss_insert_rss_link(rdf_parser, item))
return 1;
}
if(item->uri) {
uri = raptor_uri_copy(item->uri);
} else {
if(item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(item->fields[RAPTOR_RSS_FIELD_LINK]->value)
uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)item->fields[RAPTOR_RSS_FIELD_LINK]->value);
else if(item->fields[RAPTOR_RSS_FIELD_LINK]->uri)
uri = raptor_uri_copy(item->fields[RAPTOR_RSS_FIELD_LINK]->uri);
} else if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]) {
if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->value)
uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->value);
else if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->uri)
uri = raptor_uri_copy(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->uri);
}
}
item->term = raptor_new_term_from_uri(rdf_parser->world, uri);
raptor_free_uri(uri);
uri = NULL;
for(block = item->blocks; block; block = block->next) {
if(!block->identifier) {
const unsigned char *id;
/* need to make bnode */
id = raptor_world_generate_bnodeid(rdf_parser->world);
item->term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
}
}
item->node_type = &raptor_rss_items_info[RAPTOR_RSS_ITEM];
item->node_typei = RAPTOR_RSS_ITEM;
}
return 0;
}
| +Info | 0 | raptor_rss_insert_identifiers(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
if(!item->fields_count)
continue;
RAPTOR_DEBUG3("Inserting identifiers in common type %d - %s\n", i, raptor_rss_items_info[i].name);
if(item->uri) {
item->term = raptor_new_term_from_uri(rdf_parser->world, item->uri);
} else {
int url_fields[2];
int url_fields_count = 1;
int f;
url_fields[0] = (i== RAPTOR_RSS_IMAGE) ? RAPTOR_RSS_FIELD_URL :
RAPTOR_RSS_FIELD_LINK;
if(i == RAPTOR_RSS_CHANNEL) {
url_fields[1] = RAPTOR_RSS_FIELD_ATOM_ID;
url_fields_count++;
}
for(f = 0; f < url_fields_count; f++) {
raptor_rss_field* field;
for(field = item->fields[url_fields[f]]; field; field = field->next) {
raptor_uri *new_uri = NULL;
if(field->value)
new_uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)field->value);
else if(field->uri)
new_uri = raptor_uri_copy(field->uri);
if(!new_uri)
return 1;
item->term = raptor_new_term_from_uri(rdf_parser->world, new_uri);
raptor_free_uri(new_uri);
if(!item->term)
return 1;
break;
}
}
if(!item->term) {
const unsigned char *id;
/* need to make bnode */
id = raptor_world_generate_bnodeid(rdf_parser->world);
item->term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
}
}
/* Try to add an rss:link if missing */
if(i == RAPTOR_RSS_CHANNEL && !item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(raptor_rss_insert_rss_link(rdf_parser, item))
return 1;
}
item->node_type = &raptor_rss_items_info[i];
item->node_typei = i;
}
}
/* sequence of rss:item */
for(item = rss_parser->model.items; item; item = item->next) {
raptor_rss_block *block;
raptor_uri* uri;
if(!item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(raptor_rss_insert_rss_link(rdf_parser, item))
return 1;
}
if(item->uri) {
uri = raptor_uri_copy(item->uri);
} else {
if(item->fields[RAPTOR_RSS_FIELD_LINK]) {
if(item->fields[RAPTOR_RSS_FIELD_LINK]->value)
uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)item->fields[RAPTOR_RSS_FIELD_LINK]->value);
else if(item->fields[RAPTOR_RSS_FIELD_LINK]->uri)
uri = raptor_uri_copy(item->fields[RAPTOR_RSS_FIELD_LINK]->uri);
} else if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]) {
if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->value)
uri = raptor_new_uri(rdf_parser->world,
(const unsigned char*)item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->value);
else if(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->uri)
uri = raptor_uri_copy(item->fields[RAPTOR_RSS_FIELD_ATOM_ID]->uri);
}
}
item->term = raptor_new_term_from_uri(rdf_parser->world, uri);
raptor_free_uri(uri);
uri = NULL;
for(block = item->blocks; block; block = block->next) {
if(!block->identifier) {
const unsigned char *id;
/* need to make bnode */
id = raptor_world_generate_bnodeid(rdf_parser->world);
item->term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
}
}
item->node_type = &raptor_rss_items_info[RAPTOR_RSS_ITEM];
item->node_typei = RAPTOR_RSS_ITEM;
}
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,619 | raptor_rss_insert_rss_link(raptor_parser* rdf_parser,
raptor_rss_item* item)
{
raptor_rss_block *block;
raptor_rss_field* id_field;
raptor_rss_field* field = NULL;
/* Try atom:id first */
id_field = item->fields[RAPTOR_RSS_FIELD_ATOM_ID];
if(id_field && id_field->value) {
const char *value = (const char*)id_field->value;
size_t len = strlen(value);
field = raptor_rss_new_field(item->world);
if(!field)
return 1;
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value)
return 1;
memcpy(field->value, value, len + 1);
raptor_rss_item_add_field(item, RAPTOR_RSS_FIELD_LINK, field);
return 0;
}
for(block = item->blocks; block; block = block->next) {
if(block->rss_type != RAPTOR_ATOM_LINK)
continue;
/* <link @href> is url at offset RAPTOR_RSS_LINK_HREF_URL_OFFSET
* <link @rel> is string at offset RAPTOR_RSS_LINK_REL_STRING_OFFSET
* The raptor_rss_block_fields_info structure records this
*/
if(!block->urls[RAPTOR_RSS_LINK_HREF_URL_OFFSET] ||
(block->strings[RAPTOR_RSS_LINK_REL_STRING_OFFSET] &&
strcmp(block->strings[RAPTOR_RSS_LINK_REL_STRING_OFFSET], "self"))
)
continue;
/* set the field rss:link to the string value of the @href */
field = raptor_rss_new_field(item->world);
field->value = raptor_uri_to_string(block->urls[0]);
raptor_rss_item_add_field(item, RAPTOR_RSS_FIELD_LINK, field);
return 0;
}
return 0;
}
| +Info | 0 | raptor_rss_insert_rss_link(raptor_parser* rdf_parser,
raptor_rss_item* item)
{
raptor_rss_block *block;
raptor_rss_field* id_field;
raptor_rss_field* field = NULL;
/* Try atom:id first */
id_field = item->fields[RAPTOR_RSS_FIELD_ATOM_ID];
if(id_field && id_field->value) {
const char *value = (const char*)id_field->value;
size_t len = strlen(value);
field = raptor_rss_new_field(item->world);
if(!field)
return 1;
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value)
return 1;
memcpy(field->value, value, len + 1);
raptor_rss_item_add_field(item, RAPTOR_RSS_FIELD_LINK, field);
return 0;
}
for(block = item->blocks; block; block = block->next) {
if(block->rss_type != RAPTOR_ATOM_LINK)
continue;
/* <link @href> is url at offset RAPTOR_RSS_LINK_HREF_URL_OFFSET
* <link @rel> is string at offset RAPTOR_RSS_LINK_REL_STRING_OFFSET
* The raptor_rss_block_fields_info structure records this
*/
if(!block->urls[RAPTOR_RSS_LINK_HREF_URL_OFFSET] ||
(block->strings[RAPTOR_RSS_LINK_REL_STRING_OFFSET] &&
strcmp(block->strings[RAPTOR_RSS_LINK_REL_STRING_OFFSET], "self"))
)
continue;
/* set the field rss:link to the string value of the @href */
field = raptor_rss_new_field(item->world);
field->value = raptor_uri_to_string(block->urls[0]);
raptor_rss_item_add_field(item, RAPTOR_RSS_FIELD_LINK, field);
return 0;
}
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,620 | raptor_rss_parse_init(raptor_parser* rdf_parser, const char *name)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_sax2* sax2;
int n;
raptor_rss_common_init(rdf_parser->world);
raptor_rss_model_init(rdf_parser->world, &rss_parser->model);
rss_parser->prev_type = RAPTOR_RSS_NONE;
rss_parser->current_field = RAPTOR_RSS_FIELD_NONE;
rss_parser->current_type = RAPTOR_RSS_NONE;
rss_parser->current_block = NULL;
if(rss_parser->sax2) {
raptor_free_sax2(rss_parser->sax2);
rss_parser->sax2 = NULL;
}
rss_parser->nstack = raptor_new_namespaces(rdf_parser->world, 1);
/* Initialise the namespaces */
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
unsigned const char* prefix;
raptor_uri* uri;
raptor_namespace* nspace = NULL;
prefix = (unsigned const char*)raptor_rss_namespaces_info[n].prefix;
uri = rdf_parser->world->rss_namespaces_info_uris[n];
if(prefix && uri)
nspace = raptor_new_namespace_from_uri(rss_parser->nstack,
prefix, uri, 0);
rss_parser->nspaces[n] = nspace;
}
sax2 = raptor_new_sax2(rdf_parser->world, &rdf_parser->locator, rdf_parser);
rss_parser->sax2 = sax2;
raptor_sax2_set_start_element_handler(sax2, raptor_rss_start_element_handler);
raptor_sax2_set_end_element_handler(sax2, raptor_rss_end_element_handler);
raptor_sax2_set_characters_handler(sax2, raptor_rss_cdata_handler);
raptor_sax2_set_cdata_handler(sax2, raptor_rss_cdata_handler);
raptor_sax2_set_comment_handler(sax2, raptor_rss_comment_handler);
raptor_sax2_set_namespace_handler(sax2, raptor_rss_sax2_new_namespace_handler);
raptor_statement_init(&rss_parser->statement, rdf_parser->world);
return 0;
}
| +Info | 0 | raptor_rss_parse_init(raptor_parser* rdf_parser, const char *name)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
raptor_sax2* sax2;
int n;
raptor_rss_common_init(rdf_parser->world);
raptor_rss_model_init(rdf_parser->world, &rss_parser->model);
rss_parser->prev_type = RAPTOR_RSS_NONE;
rss_parser->current_field = RAPTOR_RSS_FIELD_NONE;
rss_parser->current_type = RAPTOR_RSS_NONE;
rss_parser->current_block = NULL;
if(rss_parser->sax2) {
raptor_free_sax2(rss_parser->sax2);
rss_parser->sax2 = NULL;
}
rss_parser->nstack = raptor_new_namespaces(rdf_parser->world, 1);
/* Initialise the namespaces */
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
unsigned const char* prefix;
raptor_uri* uri;
raptor_namespace* nspace = NULL;
prefix = (unsigned const char*)raptor_rss_namespaces_info[n].prefix;
uri = rdf_parser->world->rss_namespaces_info_uris[n];
if(prefix && uri)
nspace = raptor_new_namespace_from_uri(rss_parser->nstack,
prefix, uri, 0);
rss_parser->nspaces[n] = nspace;
}
sax2 = raptor_new_sax2(rdf_parser->world, &rdf_parser->locator, rdf_parser);
rss_parser->sax2 = sax2;
raptor_sax2_set_start_element_handler(sax2, raptor_rss_start_element_handler);
raptor_sax2_set_end_element_handler(sax2, raptor_rss_end_element_handler);
raptor_sax2_set_characters_handler(sax2, raptor_rss_cdata_handler);
raptor_sax2_set_cdata_handler(sax2, raptor_rss_cdata_handler);
raptor_sax2_set_comment_handler(sax2, raptor_rss_comment_handler);
raptor_sax2_set_namespace_handler(sax2, raptor_rss_sax2_new_namespace_handler);
raptor_statement_init(&rss_parser->statement, rdf_parser->world);
return 0;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,621 | raptor_rss_parse_recognise_syntax(raptor_parser_factory* factory,
const unsigned char *buffer, size_t len,
const unsigned char *identifier,
const unsigned char *suffix,
const char *mime_type)
{
int score = 0;
if(suffix) {
if(!strcmp((const char*)suffix, "rss"))
score = 7;
if(!strcmp((const char*)suffix, "atom"))
score = 5;
if(!strcmp((const char*)suffix, "xml"))
score = 4;
}
if(identifier) {
if(!strncmp((const char*)identifier, "http://feed", 11))
score += 5;
else if(strstr((const char*)identifier, "feed"))
score += 3;
if(strstr((const char*)identifier, "rss2"))
score += 5;
else if(!suffix && strstr((const char*)identifier, "rss"))
score += 4;
else if(!suffix && strstr((const char*)identifier, "atom"))
score += 4;
else if(strstr((const char*)identifier, "rss.xml"))
score += 4;
else if(strstr((const char*)identifier, "atom.xml"))
score += 4;
}
if(mime_type) {
if(!strstr((const char*)mime_type, "html")) {
if(strstr((const char*)mime_type, "rss"))
score += 4;
else if(strstr((const char*)mime_type, "xml"))
score += 4;
else if(strstr((const char*)mime_type, "atom"))
score += 4;
}
}
return score;
}
| +Info | 0 | raptor_rss_parse_recognise_syntax(raptor_parser_factory* factory,
const unsigned char *buffer, size_t len,
const unsigned char *identifier,
const unsigned char *suffix,
const char *mime_type)
{
int score = 0;
if(suffix) {
if(!strcmp((const char*)suffix, "rss"))
score = 7;
if(!strcmp((const char*)suffix, "atom"))
score = 5;
if(!strcmp((const char*)suffix, "xml"))
score = 4;
}
if(identifier) {
if(!strncmp((const char*)identifier, "http://feed", 11))
score += 5;
else if(strstr((const char*)identifier, "feed"))
score += 3;
if(strstr((const char*)identifier, "rss2"))
score += 5;
else if(!suffix && strstr((const char*)identifier, "rss"))
score += 4;
else if(!suffix && strstr((const char*)identifier, "atom"))
score += 4;
else if(strstr((const char*)identifier, "rss.xml"))
score += 4;
else if(strstr((const char*)identifier, "atom.xml"))
score += 4;
}
if(mime_type) {
if(!strstr((const char*)mime_type, "html")) {
if(strstr((const char*)mime_type, "rss"))
score += 4;
else if(strstr((const char*)mime_type, "xml"))
score += 4;
else if(strstr((const char*)mime_type, "atom"))
score += 4;
}
}
return score;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,622 | raptor_rss_parse_terminate(raptor_parser *rdf_parser)
{
raptor_rss_parser *rss_parser = (raptor_rss_parser*)rdf_parser->context;
int n;
if(rss_parser->sax2)
raptor_free_sax2(rss_parser->sax2);
raptor_rss_model_clear(&rss_parser->model);
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
if(rss_parser->nspaces[n])
raptor_free_namespace(rss_parser->nspaces[n]);
}
if(rss_parser->nstack)
raptor_free_namespaces(rss_parser->nstack);
raptor_rss_common_terminate(rdf_parser->world);
}
| +Info | 0 | raptor_rss_parse_terminate(raptor_parser *rdf_parser)
{
raptor_rss_parser *rss_parser = (raptor_rss_parser*)rdf_parser->context;
int n;
if(rss_parser->sax2)
raptor_free_sax2(rss_parser->sax2);
raptor_rss_model_clear(&rss_parser->model);
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
if(rss_parser->nspaces[n])
raptor_free_namespace(rss_parser->nspaces[n]);
}
if(rss_parser->nstack)
raptor_free_namespaces(rss_parser->nstack);
raptor_rss_common_terminate(rdf_parser->world);
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,623 | raptor_rss_parser_register_factory(raptor_parser_factory *factory)
{
int rc = 0;
factory->desc.names = rss_tag_soup_names;
factory->desc.mime_types = rss_tag_soup_types;
factory->desc.label = "RSS Tag Soup";
factory->desc.uri_strings = NULL;
factory->desc.flags = RAPTOR_SYNTAX_NEED_BASE_URI;
factory->context_length = sizeof(raptor_rss_parser);
factory->init = raptor_rss_parse_init;
factory->terminate = raptor_rss_parse_terminate;
factory->start = raptor_rss_parse_start;
factory->chunk = raptor_rss_parse_chunk;
factory->recognise_syntax = raptor_rss_parse_recognise_syntax;
return rc;
}
| +Info | 0 | raptor_rss_parser_register_factory(raptor_parser_factory *factory)
{
int rc = 0;
factory->desc.names = rss_tag_soup_names;
factory->desc.mime_types = rss_tag_soup_types;
factory->desc.label = "RSS Tag Soup";
factory->desc.uri_strings = NULL;
factory->desc.flags = RAPTOR_SYNTAX_NEED_BASE_URI;
factory->context_length = sizeof(raptor_rss_parser);
factory->init = raptor_rss_parse_init;
factory->terminate = raptor_rss_parse_terminate;
factory->start = raptor_rss_parse_start;
factory->chunk = raptor_rss_parse_chunk;
factory->recognise_syntax = raptor_rss_parse_recognise_syntax;
return rc;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,624 | raptor_rss_promote_namespace_uri(raptor_world *world, raptor_uri* nspace_URI)
{
/* RSS 0.9 and RSS 1.1 namespaces => RSS 1.0 namespace */
if((raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[RSS0_9_NS]) ||
raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[RSS1_1_NS]))) {
nspace_URI = world->rss_namespaces_info_uris[RSS1_0_NS];
}
/* Atom 0.3 namespace => Atom 1.0 namespace */
if(raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[ATOM0_3_NS])) {
nspace_URI = world->rss_namespaces_info_uris[ATOM1_0_NS];
}
return nspace_URI;
}
| +Info | 0 | raptor_rss_promote_namespace_uri(raptor_world *world, raptor_uri* nspace_URI)
{
/* RSS 0.9 and RSS 1.1 namespaces => RSS 1.0 namespace */
if((raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[RSS0_9_NS]) ||
raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[RSS1_1_NS]))) {
nspace_URI = world->rss_namespaces_info_uris[RSS1_0_NS];
}
/* Atom 0.3 namespace => Atom 1.0 namespace */
if(raptor_uri_equals(nspace_URI,
world->rss_namespaces_info_uris[ATOM0_3_NS])) {
nspace_URI = world->rss_namespaces_info_uris[ATOM1_0_NS];
}
return nspace_URI;
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,625 | raptor_rss_sax2_new_namespace_handler(void *user_data,
raptor_namespace* nspace)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rss_parser* rss_parser;
int n;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
raptor_uri* ns_uri = rdf_parser->world->rss_namespaces_info_uris[n];
if(!ns_uri)
continue;
if(!raptor_uri_equals(ns_uri, nspace->uri)) {
rss_parser->nspaces_seen[n] = 'Y';
break;
}
}
}
| +Info | 0 | raptor_rss_sax2_new_namespace_handler(void *user_data,
raptor_namespace* nspace)
{
raptor_parser* rdf_parser = (raptor_parser*)user_data;
raptor_rss_parser* rss_parser;
int n;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
raptor_uri* ns_uri = rdf_parser->world->rss_namespaces_info_uris[n];
if(!ns_uri)
continue;
if(!raptor_uri_equals(ns_uri, nspace->uri)) {
rss_parser->nspaces_seen[n] = 'Y';
break;
}
}
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,626 | raptor_rss_start_element_handler(void *user_data,
raptor_xml_element* xml_element)
{
raptor_parser *rdf_parser;
raptor_rss_parser *rss_parser;
raptor_rss_block *block = NULL;
raptor_uri* base_uri;
raptor_qname *el_qname;
const unsigned char *name;
int ns_attributes_count;
raptor_qname** named_attrs;
const raptor_namespace* el_nspace;
raptor_rss_element* rss_element;
int i;
rdf_parser = (raptor_parser*)user_data;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
rss_element = RAPTOR_CALLOC(raptor_rss_element*, 1, sizeof(*rss_element));
if(!rss_element) {
rdf_parser->failed = 1;
return;
}
rss_element->world = rdf_parser->world;
rss_element->sb = raptor_new_stringbuffer();
xml_element->user_data = rss_element;
if(xml_element->parent) {
raptor_rss_element* parent_rss_element;
parent_rss_element = (raptor_rss_element*)(xml_element->parent->user_data);
if(parent_rss_element->xml_writer)
rss_element->xml_writer = parent_rss_element->xml_writer;
}
if(rss_element->xml_writer) {
raptor_xml_writer_start_element(rss_element->xml_writer, xml_element);
return;
}
el_qname = raptor_xml_element_get_name(xml_element);
name = el_qname->local_name;
el_nspace = el_qname->nspace;
named_attrs = raptor_xml_element_get_attributes(xml_element);
ns_attributes_count = raptor_xml_element_get_attributes_count(xml_element);
base_uri = raptor_sax2_inscope_base_uri(rss_parser->sax2);
/* No container type - identify and record in rss_parser->current_type
* either as a top-level container or an inner-container */
if(!raptor_rss_add_container(rss_parser, (const char*)name)) {
#ifdef RAPTOR_DEBUG
if(1) {
raptor_rss_type old_type = rss_parser->prev_type;
if(old_type != rss_parser->current_type && old_type != RAPTOR_RSS_NONE)
RAPTOR_DEBUG5("FOUND inner container type %d - %s INSIDE current container type %d - %s\n", rss_parser->current_type,
raptor_rss_items_info[rss_parser->current_type].name,
old_type, raptor_rss_items_info[old_type].name);
else
RAPTOR_DEBUG3("FOUND container type %d - %s\n",
rss_parser->current_type,
raptor_rss_items_info[rss_parser->current_type].name);
}
#endif
/* check a few container attributes */
if(named_attrs) {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const char* attrName = (const char*)attr->local_name;
const unsigned char* attrValue = attr->value;
RAPTOR_DEBUG3(" container attribute %s=%s\n", attrName, attrValue);
if(!strcmp(attrName, "about")) {
if(update_item) {
update_item->uri = raptor_new_uri(rdf_parser->world, attrValue);
update_item->term = raptor_new_term_from_uri(rdf_parser->world,
update_item->uri);
}
}
}
}
return;
} else if(rss_parser->current_type == RAPTOR_RSS_NONE) {
RAPTOR_DEBUG2("Unknown container element named %s\n", name);
/* Nothing more that can be done with unknown element - skip it */
return;
}
/* have container (current_type) so this element is inside it is either:
* 1. a metadata block element (such as rss:enclosure)
* 2. a field (such as atom:title)
*/
/* Find field ID */
rss_parser->current_field = RAPTOR_RSS_FIELD_UNKNOWN;
for(i = 0; i < RAPTOR_RSS_FIELDS_SIZE; i++) {
raptor_uri* nspace_URI;
raptor_uri* field_nspace_URI;
rss_info_namespace nsid = raptor_rss_fields_info[i].nspace;
if(strcmp((const char*)name, raptor_rss_fields_info[i].name))
continue;
if(!el_nspace) {
if(nsid != RSS_NO_NS && nsid != RSS1_0_NS && nsid != RSS0_91_NS &&
nsid != RSS0_9_NS && nsid != RSS1_1_NS)
continue;
/* Matches if the element has no namespace and field is not atom */
rss_parser->current_field = (raptor_rss_fields_type)i;
break;
}
/* Promote element namespaces */
nspace_URI = raptor_rss_promote_namespace_uri(rdf_parser->world,
raptor_namespace_get_uri(el_nspace));
field_nspace_URI = rdf_parser->world->rss_namespaces_info_uris[raptor_rss_fields_info[i].nspace];
if(raptor_uri_equals(nspace_URI,
field_nspace_URI)) {
rss_parser->current_field = (raptor_rss_fields_type)i;
break;
}
}
if(rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN) {
RAPTOR_DEBUG3("Unknown field element named %s inside type %s\n", name,
raptor_rss_items_info[rss_parser->current_type].name);
return;
}
/* Found a block element to process */
if(raptor_rss_fields_info[rss_parser->current_field].flags &
RAPTOR_RSS_INFO_FLAG_BLOCK_VALUE) {
raptor_rss_type block_type;
raptor_rss_item* update_item;
const unsigned char *id;
raptor_term* block_term;
block_type = raptor_rss_fields_info[rss_parser->current_field].block_type;
RAPTOR_DEBUG3("FOUND new block type %d - %s\n", block_type,
raptor_rss_items_info[block_type].name);
update_item = raptor_rss_get_current_item(rss_parser);
id = raptor_world_generate_bnodeid(rdf_parser->world);
block_term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
block = raptor_new_rss_block(rdf_parser->world, block_type, block_term);
raptor_free_term(block_term);
raptor_rss_item_add_block(update_item, block);
rss_parser->current_block = block;
rss_parser->nspaces_seen[raptor_rss_items_info[block_type].nspace] = 'Y';
/* Now check block attributes */
if(named_attrs) {
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const char* attrName = (const char*)attr->local_name;
const unsigned char* attrValue = attr->value;
const raptor_rss_block_field_info *bfi;
int offset = -1;
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
if(!bfi->attribute)
continue;
if(bfi->type == block_type && !strcmp(attrName, bfi->attribute)) {
offset = bfi->offset;
break;
}
}
if(offset < 0)
continue;
/* Found attribute for this block type */
RAPTOR_DEBUG3(" found block attribute %s=%s\n", attrName, attrValue);
if(raptor_rss_block_set_field(rdf_parser->world, base_uri,
block, bfi, (const char*)attrValue)) {
rdf_parser->failed = 1;
return;
}
}
}
return;
}
/* Process field */
RAPTOR_DEBUG4("FOUND field %d - %s inside type %s\n",
rss_parser->current_field,
raptor_rss_fields_info[rss_parser->current_field].name,
raptor_rss_items_info[rss_parser->current_type].name);
/* Mark namespace seen in new field */
if(1) {
rss_info_namespace ns_index;
ns_index = raptor_rss_fields_info[rss_parser->current_field].nspace;
rss_parser->nspaces_seen[ns_index] = 'Y';
}
/* Now check for field attributes */
if(named_attrs) {
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const unsigned char* attrName = attr->local_name;
const unsigned char* attrValue = attr->value;
RAPTOR_DEBUG3(" attribute %s=%s\n", attrName, attrValue);
/* Pick a few attributes to care about */
if(!strcmp((const char*)attrName, "isPermaLink")) {
raptor_rss_item* update_item = rss_parser->model.last;
if(!strcmp((const char*)name, "guid")) {
/* <guid isPermaLink="..."> */
if(update_item) {
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
RAPTOR_DEBUG1("fa1 - ");
raptor_rss_item_add_field(update_item, RAPTOR_RSS_FIELD_GUID, field);
if(!strcmp((const char*)attrValue, "true")) {
RAPTOR_DEBUG2(" setting guid to URI '%s'\n", attrValue);
field->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri,
(const unsigned char*)attrValue);
} else {
size_t len = strlen((const char*)attrValue);
RAPTOR_DEBUG2(" setting guid to string '%s'\n", attrValue);
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value) {
rdf_parser->failed = 1;
return;
}
memcpy(field->value, attrValue, len + 1);
}
}
}
} else if(!strcmp((const char*)attrName, "href")) {
if(rss_parser->current_field == RAPTOR_RSS_FIELD_LINK ||
rss_parser->current_field == RAPTOR_RSS_FIELD_ATOM_LINK) {
RAPTOR_DEBUG2(" setting href as URI string for type %s\n", raptor_rss_items_info[rss_parser->current_type].name);
if(rss_element->uri)
raptor_free_uri(rss_element->uri);
rss_element->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri,
(const unsigned char*)attrValue);
}
} else if(!strcmp((const char*)attrName, "type")) {
if(rss_parser->current_field == RAPTOR_RSS_FIELD_ATOM_LINK) {
/* do nothing with atom link attribute type */
} else if(rss_parser->is_atom) {
/* Atom only typing */
if(!strcmp((const char*)attrValue, "xhtml") ||
!strcmp((const char*)attrValue, "xml") ||
strstr((const char*)attrValue, "+xml")) {
RAPTOR_DEBUG2(" found type '%s', making an XML writer\n",
attrValue);
rss_element->type = RAPTOR_RSS_CONTENT_TYPE_XML;
rss_element->iostream = raptor_new_iostream_to_string(rdf_parser->world,
&rss_element->xml_content,
&rss_element->xml_content_length,
raptor_alloc_memory);
rss_element->xml_writer = raptor_new_xml_writer(rdf_parser->world,
NULL,
rss_element->iostream);
raptor_xml_writer_set_option(rss_element->xml_writer,
RAPTOR_OPTION_WRITER_XML_DECLARATION,
NULL, 0);
raptor_free_stringbuffer(rss_element->sb);
rss_element->sb = NULL;
}
}
} else if(!strcmp((const char*)attrName, "version")) {
if(!raptor_strcasecmp((const char*)name, "feed")) {
if(!strcmp((const char*)attrValue, "0.3"))
rss_parser->is_atom = 1;
}
}
}
} /* if have field attributes */
}
| +Info | 0 | raptor_rss_start_element_handler(void *user_data,
raptor_xml_element* xml_element)
{
raptor_parser *rdf_parser;
raptor_rss_parser *rss_parser;
raptor_rss_block *block = NULL;
raptor_uri* base_uri;
raptor_qname *el_qname;
const unsigned char *name;
int ns_attributes_count;
raptor_qname** named_attrs;
const raptor_namespace* el_nspace;
raptor_rss_element* rss_element;
int i;
rdf_parser = (raptor_parser*)user_data;
rss_parser = (raptor_rss_parser*)rdf_parser->context;
rss_element = RAPTOR_CALLOC(raptor_rss_element*, 1, sizeof(*rss_element));
if(!rss_element) {
rdf_parser->failed = 1;
return;
}
rss_element->world = rdf_parser->world;
rss_element->sb = raptor_new_stringbuffer();
xml_element->user_data = rss_element;
if(xml_element->parent) {
raptor_rss_element* parent_rss_element;
parent_rss_element = (raptor_rss_element*)(xml_element->parent->user_data);
if(parent_rss_element->xml_writer)
rss_element->xml_writer = parent_rss_element->xml_writer;
}
if(rss_element->xml_writer) {
raptor_xml_writer_start_element(rss_element->xml_writer, xml_element);
return;
}
el_qname = raptor_xml_element_get_name(xml_element);
name = el_qname->local_name;
el_nspace = el_qname->nspace;
named_attrs = raptor_xml_element_get_attributes(xml_element);
ns_attributes_count = raptor_xml_element_get_attributes_count(xml_element);
base_uri = raptor_sax2_inscope_base_uri(rss_parser->sax2);
/* No container type - identify and record in rss_parser->current_type
* either as a top-level container or an inner-container */
if(!raptor_rss_add_container(rss_parser, (const char*)name)) {
#ifdef RAPTOR_DEBUG
if(1) {
raptor_rss_type old_type = rss_parser->prev_type;
if(old_type != rss_parser->current_type && old_type != RAPTOR_RSS_NONE)
RAPTOR_DEBUG5("FOUND inner container type %d - %s INSIDE current container type %d - %s\n", rss_parser->current_type,
raptor_rss_items_info[rss_parser->current_type].name,
old_type, raptor_rss_items_info[old_type].name);
else
RAPTOR_DEBUG3("FOUND container type %d - %s\n",
rss_parser->current_type,
raptor_rss_items_info[rss_parser->current_type].name);
}
#endif
/* check a few container attributes */
if(named_attrs) {
raptor_rss_item* update_item = raptor_rss_get_current_item(rss_parser);
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const char* attrName = (const char*)attr->local_name;
const unsigned char* attrValue = attr->value;
RAPTOR_DEBUG3(" container attribute %s=%s\n", attrName, attrValue);
if(!strcmp(attrName, "about")) {
if(update_item) {
update_item->uri = raptor_new_uri(rdf_parser->world, attrValue);
update_item->term = raptor_new_term_from_uri(rdf_parser->world,
update_item->uri);
}
}
}
}
return;
} else if(rss_parser->current_type == RAPTOR_RSS_NONE) {
RAPTOR_DEBUG2("Unknown container element named %s\n", name);
/* Nothing more that can be done with unknown element - skip it */
return;
}
/* have container (current_type) so this element is inside it is either:
* 1. a metadata block element (such as rss:enclosure)
* 2. a field (such as atom:title)
*/
/* Find field ID */
rss_parser->current_field = RAPTOR_RSS_FIELD_UNKNOWN;
for(i = 0; i < RAPTOR_RSS_FIELDS_SIZE; i++) {
raptor_uri* nspace_URI;
raptor_uri* field_nspace_URI;
rss_info_namespace nsid = raptor_rss_fields_info[i].nspace;
if(strcmp((const char*)name, raptor_rss_fields_info[i].name))
continue;
if(!el_nspace) {
if(nsid != RSS_NO_NS && nsid != RSS1_0_NS && nsid != RSS0_91_NS &&
nsid != RSS0_9_NS && nsid != RSS1_1_NS)
continue;
/* Matches if the element has no namespace and field is not atom */
rss_parser->current_field = (raptor_rss_fields_type)i;
break;
}
/* Promote element namespaces */
nspace_URI = raptor_rss_promote_namespace_uri(rdf_parser->world,
raptor_namespace_get_uri(el_nspace));
field_nspace_URI = rdf_parser->world->rss_namespaces_info_uris[raptor_rss_fields_info[i].nspace];
if(raptor_uri_equals(nspace_URI,
field_nspace_URI)) {
rss_parser->current_field = (raptor_rss_fields_type)i;
break;
}
}
if(rss_parser->current_field == RAPTOR_RSS_FIELD_UNKNOWN) {
RAPTOR_DEBUG3("Unknown field element named %s inside type %s\n", name,
raptor_rss_items_info[rss_parser->current_type].name);
return;
}
/* Found a block element to process */
if(raptor_rss_fields_info[rss_parser->current_field].flags &
RAPTOR_RSS_INFO_FLAG_BLOCK_VALUE) {
raptor_rss_type block_type;
raptor_rss_item* update_item;
const unsigned char *id;
raptor_term* block_term;
block_type = raptor_rss_fields_info[rss_parser->current_field].block_type;
RAPTOR_DEBUG3("FOUND new block type %d - %s\n", block_type,
raptor_rss_items_info[block_type].name);
update_item = raptor_rss_get_current_item(rss_parser);
id = raptor_world_generate_bnodeid(rdf_parser->world);
block_term = raptor_new_term_from_blank(rdf_parser->world, id);
RAPTOR_FREE(char*, id);
block = raptor_new_rss_block(rdf_parser->world, block_type, block_term);
raptor_free_term(block_term);
raptor_rss_item_add_block(update_item, block);
rss_parser->current_block = block;
rss_parser->nspaces_seen[raptor_rss_items_info[block_type].nspace] = 'Y';
/* Now check block attributes */
if(named_attrs) {
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const char* attrName = (const char*)attr->local_name;
const unsigned char* attrValue = attr->value;
const raptor_rss_block_field_info *bfi;
int offset = -1;
for(bfi = &raptor_rss_block_fields_info[0];
bfi->type != RAPTOR_RSS_NONE;
bfi++) {
if(!bfi->attribute)
continue;
if(bfi->type == block_type && !strcmp(attrName, bfi->attribute)) {
offset = bfi->offset;
break;
}
}
if(offset < 0)
continue;
/* Found attribute for this block type */
RAPTOR_DEBUG3(" found block attribute %s=%s\n", attrName, attrValue);
if(raptor_rss_block_set_field(rdf_parser->world, base_uri,
block, bfi, (const char*)attrValue)) {
rdf_parser->failed = 1;
return;
}
}
}
return;
}
/* Process field */
RAPTOR_DEBUG4("FOUND field %d - %s inside type %s\n",
rss_parser->current_field,
raptor_rss_fields_info[rss_parser->current_field].name,
raptor_rss_items_info[rss_parser->current_type].name);
/* Mark namespace seen in new field */
if(1) {
rss_info_namespace ns_index;
ns_index = raptor_rss_fields_info[rss_parser->current_field].nspace;
rss_parser->nspaces_seen[ns_index] = 'Y';
}
/* Now check for field attributes */
if(named_attrs) {
for(i = 0; i < ns_attributes_count; i++) {
raptor_qname* attr = named_attrs[i];
const unsigned char* attrName = attr->local_name;
const unsigned char* attrValue = attr->value;
RAPTOR_DEBUG3(" attribute %s=%s\n", attrName, attrValue);
/* Pick a few attributes to care about */
if(!strcmp((const char*)attrName, "isPermaLink")) {
raptor_rss_item* update_item = rss_parser->model.last;
if(!strcmp((const char*)name, "guid")) {
/* <guid isPermaLink="..."> */
if(update_item) {
raptor_rss_field* field = raptor_rss_new_field(rdf_parser->world);
RAPTOR_DEBUG1("fa1 - ");
raptor_rss_item_add_field(update_item, RAPTOR_RSS_FIELD_GUID, field);
if(!strcmp((const char*)attrValue, "true")) {
RAPTOR_DEBUG2(" setting guid to URI '%s'\n", attrValue);
field->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri,
(const unsigned char*)attrValue);
} else {
size_t len = strlen((const char*)attrValue);
RAPTOR_DEBUG2(" setting guid to string '%s'\n", attrValue);
field->value = RAPTOR_MALLOC(unsigned char*, len + 1);
if(!field->value) {
rdf_parser->failed = 1;
return;
}
memcpy(field->value, attrValue, len + 1);
}
}
}
} else if(!strcmp((const char*)attrName, "href")) {
if(rss_parser->current_field == RAPTOR_RSS_FIELD_LINK ||
rss_parser->current_field == RAPTOR_RSS_FIELD_ATOM_LINK) {
RAPTOR_DEBUG2(" setting href as URI string for type %s\n", raptor_rss_items_info[rss_parser->current_type].name);
if(rss_element->uri)
raptor_free_uri(rss_element->uri);
rss_element->uri = raptor_new_uri_relative_to_base(rdf_parser->world, base_uri,
(const unsigned char*)attrValue);
}
} else if(!strcmp((const char*)attrName, "type")) {
if(rss_parser->current_field == RAPTOR_RSS_FIELD_ATOM_LINK) {
/* do nothing with atom link attribute type */
} else if(rss_parser->is_atom) {
/* Atom only typing */
if(!strcmp((const char*)attrValue, "xhtml") ||
!strcmp((const char*)attrValue, "xml") ||
strstr((const char*)attrValue, "+xml")) {
RAPTOR_DEBUG2(" found type '%s', making an XML writer\n",
attrValue);
rss_element->type = RAPTOR_RSS_CONTENT_TYPE_XML;
rss_element->iostream = raptor_new_iostream_to_string(rdf_parser->world,
&rss_element->xml_content,
&rss_element->xml_content_length,
raptor_alloc_memory);
rss_element->xml_writer = raptor_new_xml_writer(rdf_parser->world,
NULL,
rss_element->iostream);
raptor_xml_writer_set_option(rss_element->xml_writer,
RAPTOR_OPTION_WRITER_XML_DECLARATION,
NULL, 0);
raptor_free_stringbuffer(rss_element->sb);
rss_element->sb = NULL;
}
}
} else if(!strcmp((const char*)attrName, "version")) {
if(!raptor_strcasecmp((const char*)name, "feed")) {
if(!strcmp((const char*)attrValue, "0.3"))
rss_parser->is_atom = 1;
}
}
}
} /* if have field attributes */
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,627 | raptor_rss_start_namespaces(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
int n;
/* for each item type (channel, item, ...) */
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
raptor_rss_item* item;
/* for each item instance of a type */
for(item = rss_parser->model.common[i]; item; item = item->next) {
int f;
if(!item->fields_count)
continue;
/* for each field */
for(f = 0; f< RAPTOR_RSS_FIELDS_SIZE; f++) {
raptor_rss_field* field;
/* for each field value */
for(field = item->fields[f]; field; field = field->next) {
rss_info_namespace ns_index = raptor_rss_fields_info[f].nspace;
rss_parser->nspaces_seen[ns_index] = 'Y';
/* knowing there is one value is enough */
break;
}
}
}
}
/* start the namespaces */
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
if(rss_parser->nspaces[n] && rss_parser->nspaces_seen[n] == 'Y')
raptor_parser_start_namespace(rdf_parser, rss_parser->nspaces[n]);
}
}
| +Info | 0 | raptor_rss_start_namespaces(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
int n;
/* for each item type (channel, item, ...) */
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
raptor_rss_item* item;
/* for each item instance of a type */
for(item = rss_parser->model.common[i]; item; item = item->next) {
int f;
if(!item->fields_count)
continue;
/* for each field */
for(f = 0; f< RAPTOR_RSS_FIELDS_SIZE; f++) {
raptor_rss_field* field;
/* for each field value */
for(field = item->fields[f]; field; field = field->next) {
rss_info_namespace ns_index = raptor_rss_fields_info[f].nspace;
rss_parser->nspaces_seen[ns_index] = 'Y';
/* knowing there is one value is enough */
break;
}
}
}
}
/* start the namespaces */
for(n = 0; n < RAPTOR_RSS_NAMESPACES_SIZE; n++) {
if(rss_parser->nspaces[n] && rss_parser->nspaces_seen[n] == 'Y')
raptor_parser_start_namespace(rdf_parser, rss_parser->nspaces[n]);
}
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,628 | raptor_rss_uplift_fields(raptor_rss_parser* rss_parser, raptor_rss_item* item)
{
int i;
/* COPY some fields from atom to rss/dc */
for(i = 0; raptor_atom_to_rss[i].from != RAPTOR_RSS_FIELD_UNKNOWN; i++) {
#ifdef RAPTOR_DEBUG
raptor_rss_fields_type from_field = raptor_atom_to_rss[i].from;
raptor_rss_fields_type to_field = raptor_atom_to_rss[i].to;
#endif
if(raptor_rss_copy_field(rss_parser, item, &raptor_atom_to_rss[i]))
continue;
RAPTOR_DEBUG3("Copied field %s to rss field %s\n",
raptor_rss_fields_info[from_field].name,
raptor_rss_fields_info[to_field].name);
}
}
| +Info | 0 | raptor_rss_uplift_fields(raptor_rss_parser* rss_parser, raptor_rss_item* item)
{
int i;
/* COPY some fields from atom to rss/dc */
for(i = 0; raptor_atom_to_rss[i].from != RAPTOR_RSS_FIELD_UNKNOWN; i++) {
#ifdef RAPTOR_DEBUG
raptor_rss_fields_type from_field = raptor_atom_to_rss[i].from;
raptor_rss_fields_type to_field = raptor_atom_to_rss[i].to;
#endif
if(raptor_rss_copy_field(rss_parser, item, &raptor_atom_to_rss[i]))
continue;
RAPTOR_DEBUG3("Copied field %s to rss field %s\n",
raptor_rss_fields_info[from_field].name,
raptor_rss_fields_info[to_field].name);
}
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,629 | raptor_rss_uplift_items(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
raptor_rss_uplift_fields(rss_parser, item);
}
}
for(item = rss_parser->model.items; item; item = item->next) {
raptor_rss_uplift_fields(rss_parser, item);
}
}
| +Info | 0 | raptor_rss_uplift_items(raptor_parser* rdf_parser)
{
raptor_rss_parser* rss_parser = (raptor_rss_parser*)rdf_parser->context;
int i;
raptor_rss_item* item;
for(i = 0; i< RAPTOR_RSS_COMMON_SIZE; i++) {
for(item = rss_parser->model.common[i]; item; item = item->next) {
raptor_rss_uplift_fields(rss_parser, item);
}
}
for(item = rss_parser->model.items; item; item = item->next) {
raptor_rss_uplift_fields(rss_parser, item);
}
}
| @@ -252,6 +252,9 @@ raptor_rss_parse_start(raptor_parser *rdf_parser)
raptor_sax2_set_option(rss_parser->sax2,
RAPTOR_OPTION_NO_FILE, NULL,
RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_NO_FILE));
+ raptor_sax2_set_option(rss_parser->sax2,
+ RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES, NULL,
+ RAPTOR_OPTIONS_GET_NUMERIC(rdf_parser, RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES));
if(rdf_parser->uri_filter)
raptor_sax2_set_uri_filter(rss_parser->sax2, rdf_parser->uri_filter,
rdf_parser->uri_filter_user_data); | CWE-200 | null | null |
17,630 | main(int argc, char *argv[])
{
raptor_world *world;
const char *program = raptor_basename(argv[0]);
raptor_iostream *iostr;
raptor_namespace_stack *nstack;
raptor_namespace* ex_ns;
raptor_turtle_writer* turtle_writer;
raptor_uri* base_uri;
raptor_qname* el_name;
unsigned long count;
raptor_uri* datatype;
/* for raptor_new_iostream_to_string */
void *string = NULL;
size_t string_len = 0;
world = raptor_new_world();
if(!world || raptor_world_open(world))
exit(1);
iostr = raptor_new_iostream_to_string(world, &string, &string_len, NULL);
if(!iostr) {
fprintf(stderr, "%s: Failed to create iostream to string\n", program);
exit(1);
}
nstack = raptor_new_namespaces(world, 1);
base_uri = raptor_new_uri(world, base_uri_string);
turtle_writer = raptor_new_turtle_writer(world, base_uri, 1, nstack, iostr);
if(!turtle_writer) {
fprintf(stderr, "%s: Failed to create turtle_writer to iostream\n", program);
exit(1);
}
raptor_turtle_writer_set_option(turtle_writer,
RAPTOR_OPTION_WRITER_AUTO_INDENT, 1);
ex_ns = raptor_new_namespace(nstack,
(const unsigned char*)"ex",
(const unsigned char*)"http://example.org/ns#",
0);
raptor_turtle_writer_namespace_prefix(turtle_writer, ex_ns);
raptor_turtle_writer_reference(turtle_writer, base_uri);
raptor_turtle_writer_increase_indent(turtle_writer);
raptor_turtle_writer_newline(turtle_writer);
raptor_turtle_writer_raw(turtle_writer, (const unsigned char*)"ex:foo ");
raptor_turtle_writer_quoted_counted_string(turtle_writer, longstr,
strlen((const char*)longstr));
raptor_turtle_writer_raw_counted(turtle_writer,
(const unsigned char*)" ;", 2);
raptor_turtle_writer_newline(turtle_writer);
el_name = raptor_new_qname_from_namespace_local_name(world,
ex_ns,
(const unsigned char*)"bar",
NULL);
raptor_turtle_writer_qname(turtle_writer, el_name);
raptor_free_qname(el_name);
raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)" ", 1);
datatype = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal");
raptor_turtle_writer_literal(turtle_writer, nstack,
(const unsigned char*)"10.0", NULL,
datatype);
raptor_free_uri(datatype);
raptor_turtle_writer_newline(turtle_writer);
raptor_turtle_writer_decrease_indent(turtle_writer);
raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)".", 1);
raptor_turtle_writer_newline(turtle_writer);
raptor_free_turtle_writer(turtle_writer);
raptor_free_namespace(ex_ns);
raptor_free_namespaces(nstack);
raptor_free_uri(base_uri);
count = raptor_iostream_tell(iostr);
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
fprintf(stderr, "%s: Freeing iostream\n", program);
#endif
raptor_free_iostream(iostr);
if(count != OUT_BYTES_COUNT) {
fprintf(stderr, "%s: I/O stream wrote %d bytes, expected %d\n", program,
(int)count, (int)OUT_BYTES_COUNT);
fputs("[[", stderr);
(void)fwrite(string, 1, string_len, stderr);
fputs("]]\n", stderr);
return 1;
}
if(!string) {
fprintf(stderr, "%s: I/O stream failed to create a string\n", program);
return 1;
}
string_len = strlen((const char*)string);
if(string_len != count) {
fprintf(stderr, "%s: I/O stream created a string length %d, expected %d\n", program, (int)string_len, (int)count);
return 1;
}
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
fprintf(stderr, "%s: Made Turtle string of %d bytes\n", program, (int)string_len);
fputs("[[", stderr);
(void)fwrite(string, 1, string_len, stderr);
fputs("]]\n", stderr);
#endif
raptor_free_memory(string);
raptor_free_world(world);
/* keep gcc -Wall happy */
return(0);
}
| +Info | 0 | main(int argc, char *argv[])
{
raptor_world *world;
const char *program = raptor_basename(argv[0]);
raptor_iostream *iostr;
raptor_namespace_stack *nstack;
raptor_namespace* ex_ns;
raptor_turtle_writer* turtle_writer;
raptor_uri* base_uri;
raptor_qname* el_name;
unsigned long count;
raptor_uri* datatype;
/* for raptor_new_iostream_to_string */
void *string = NULL;
size_t string_len = 0;
world = raptor_new_world();
if(!world || raptor_world_open(world))
exit(1);
iostr = raptor_new_iostream_to_string(world, &string, &string_len, NULL);
if(!iostr) {
fprintf(stderr, "%s: Failed to create iostream to string\n", program);
exit(1);
}
nstack = raptor_new_namespaces(world, 1);
base_uri = raptor_new_uri(world, base_uri_string);
turtle_writer = raptor_new_turtle_writer(world, base_uri, 1, nstack, iostr);
if(!turtle_writer) {
fprintf(stderr, "%s: Failed to create turtle_writer to iostream\n", program);
exit(1);
}
raptor_turtle_writer_set_option(turtle_writer,
RAPTOR_OPTION_WRITER_AUTO_INDENT, 1);
ex_ns = raptor_new_namespace(nstack,
(const unsigned char*)"ex",
(const unsigned char*)"http://example.org/ns#",
0);
raptor_turtle_writer_namespace_prefix(turtle_writer, ex_ns);
raptor_turtle_writer_reference(turtle_writer, base_uri);
raptor_turtle_writer_increase_indent(turtle_writer);
raptor_turtle_writer_newline(turtle_writer);
raptor_turtle_writer_raw(turtle_writer, (const unsigned char*)"ex:foo ");
raptor_turtle_writer_quoted_counted_string(turtle_writer, longstr,
strlen((const char*)longstr));
raptor_turtle_writer_raw_counted(turtle_writer,
(const unsigned char*)" ;", 2);
raptor_turtle_writer_newline(turtle_writer);
el_name = raptor_new_qname_from_namespace_local_name(world,
ex_ns,
(const unsigned char*)"bar",
NULL);
raptor_turtle_writer_qname(turtle_writer, el_name);
raptor_free_qname(el_name);
raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)" ", 1);
datatype = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal");
raptor_turtle_writer_literal(turtle_writer, nstack,
(const unsigned char*)"10.0", NULL,
datatype);
raptor_free_uri(datatype);
raptor_turtle_writer_newline(turtle_writer);
raptor_turtle_writer_decrease_indent(turtle_writer);
raptor_turtle_writer_raw_counted(turtle_writer, (const unsigned char*)".", 1);
raptor_turtle_writer_newline(turtle_writer);
raptor_free_turtle_writer(turtle_writer);
raptor_free_namespace(ex_ns);
raptor_free_namespaces(nstack);
raptor_free_uri(base_uri);
count = raptor_iostream_tell(iostr);
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
fprintf(stderr, "%s: Freeing iostream\n", program);
#endif
raptor_free_iostream(iostr);
if(count != OUT_BYTES_COUNT) {
fprintf(stderr, "%s: I/O stream wrote %d bytes, expected %d\n", program,
(int)count, (int)OUT_BYTES_COUNT);
fputs("[[", stderr);
(void)fwrite(string, 1, string_len, stderr);
fputs("]]\n", stderr);
return 1;
}
if(!string) {
fprintf(stderr, "%s: I/O stream failed to create a string\n", program);
return 1;
}
string_len = strlen((const char*)string);
if(string_len != count) {
fprintf(stderr, "%s: I/O stream created a string length %d, expected %d\n", program, (int)string_len, (int)count);
return 1;
}
#if defined(RAPTOR_DEBUG) && RAPTOR_DEBUG > 1
fprintf(stderr, "%s: Made Turtle string of %d bytes\n", program, (int)string_len);
fputs("[[", stderr);
(void)fwrite(string, 1, string_len, stderr);
fputs("]]\n", stderr);
#endif
raptor_free_memory(string);
raptor_free_world(world);
/* keep gcc -Wall happy */
return(0);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,631 | raptor_new_turtle_writer(raptor_world* world,
raptor_uri* base_uri, int write_base_uri,
raptor_namespace_stack *nstack,
raptor_iostream* iostr)
{
raptor_turtle_writer* turtle_writer;
RAPTOR_CHECK_CONSTRUCTOR_WORLD(world);
if(!nstack || !iostr)
return NULL;
raptor_world_open(world);
turtle_writer = RAPTOR_CALLOC(raptor_turtle_writer*, 1,
sizeof(*turtle_writer));
if(!turtle_writer)
return NULL;
turtle_writer->world = world;
turtle_writer->nstack_depth = 0;
turtle_writer->nstack = nstack;
if(!turtle_writer->nstack) {
turtle_writer->nstack = raptor_new_namespaces(world, 1);
turtle_writer->my_nstack = 1;
}
turtle_writer->iostr = iostr;
turtle_writer->flags = 0;
turtle_writer->indent = 2;
turtle_writer->base_uri = NULL;
/* Ensure any initial base URI is not written relative */
if(base_uri && write_base_uri)
raptor_turtle_writer_base(turtle_writer, base_uri);
turtle_writer->base_uri = base_uri;
turtle_writer->xsd_boolean_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#boolean");
turtle_writer->xsd_decimal_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal");
turtle_writer->xsd_double_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#double");
turtle_writer->xsd_integer_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#integer");
return turtle_writer;
}
| +Info | 0 | raptor_new_turtle_writer(raptor_world* world,
raptor_uri* base_uri, int write_base_uri,
raptor_namespace_stack *nstack,
raptor_iostream* iostr)
{
raptor_turtle_writer* turtle_writer;
RAPTOR_CHECK_CONSTRUCTOR_WORLD(world);
if(!nstack || !iostr)
return NULL;
raptor_world_open(world);
turtle_writer = RAPTOR_CALLOC(raptor_turtle_writer*, 1,
sizeof(*turtle_writer));
if(!turtle_writer)
return NULL;
turtle_writer->world = world;
turtle_writer->nstack_depth = 0;
turtle_writer->nstack = nstack;
if(!turtle_writer->nstack) {
turtle_writer->nstack = raptor_new_namespaces(world, 1);
turtle_writer->my_nstack = 1;
}
turtle_writer->iostr = iostr;
turtle_writer->flags = 0;
turtle_writer->indent = 2;
turtle_writer->base_uri = NULL;
/* Ensure any initial base URI is not written relative */
if(base_uri && write_base_uri)
raptor_turtle_writer_base(turtle_writer, base_uri);
turtle_writer->base_uri = base_uri;
turtle_writer->xsd_boolean_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#boolean");
turtle_writer->xsd_decimal_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#decimal");
turtle_writer->xsd_double_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#double");
turtle_writer->xsd_integer_uri = raptor_new_uri(world, (const unsigned char*)"http://www.w3.org/2001/XMLSchema#integer");
return turtle_writer;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,632 | raptor_string_python_write(const unsigned char *string,
size_t len,
const char delim,
int flags,
raptor_iostream *iostr)
{
unsigned char c;
int unichar_len;
raptor_unichar unichar;
if(flags < 0 || flags > 3)
return 1;
for(; (c=*string); string++, len--) {
if((delim && c == delim && (delim == '\'' || delim == '"')) ||
c == '\\') {
raptor_iostream_write_byte('\\', iostr);
raptor_iostream_write_byte(c, iostr);
continue;
}
if(delim && c == delim) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(c, 4, iostr);
continue;
}
if(flags != 2) {
/* N-Triples, Turtle or JSON */
/* Note: NTriples is ASCII */
if(c == 0x09) {
raptor_iostream_counted_string_write("\\t", 2, iostr);
continue;
} else if((flags == 3) && c == 0x08) {
/* JSON has \b for backspace */
raptor_iostream_counted_string_write("\\b", 2, iostr);
continue;
} else if(c == 0x0a) {
raptor_iostream_counted_string_write("\\n", 2, iostr);
continue;
} else if((flags == 3) && c == 0x0b) {
/* JSON has \f for formfeed */
raptor_iostream_counted_string_write("\\f", 2, iostr);
continue;
} else if(c == 0x0d) {
raptor_iostream_counted_string_write("\\r", 2, iostr);
continue;
} else if(c < 0x20|| c == 0x7f) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(c, 4, iostr);
continue;
} else if(c < 0x80) {
raptor_iostream_write_byte(c, iostr);
continue;
}
} else if(c < 0x80) {
/* Turtle long string has no escapes except delim */
raptor_iostream_write_byte(c, iostr);
continue;
}
/* It is unicode */
unichar_len = raptor_unicode_utf8_string_get_char(string, len, NULL);
if(unichar_len < 0 || RAPTOR_GOOD_CAST(size_t, unichar_len) > len)
/* UTF-8 encoding had an error or ended in the middle of a string */
return 1;
if(flags >= 1 && flags <= 3) {
/* Turtle and JSON are UTF-8 - no need to escape */
raptor_iostream_counted_string_write(string, unichar_len, iostr);
} else {
unichar_len = raptor_unicode_utf8_string_get_char(string, len, &unichar);
if(unichar_len < 0)
return 1;
if(unichar < 0x10000) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(RAPTOR_GOOD_CAST(unsigned int, unichar), 4, iostr);
} else {
raptor_iostream_counted_string_write("\\U", 2, iostr);
raptor_iostream_hexadecimal_write(RAPTOR_GOOD_CAST(unsigned int, unichar), 8, iostr);
}
}
unichar_len--; /* since loop does len-- */
string += unichar_len; len -= unichar_len;
}
return 0;
}
| +Info | 0 | raptor_string_python_write(const unsigned char *string,
size_t len,
const char delim,
int flags,
raptor_iostream *iostr)
{
unsigned char c;
int unichar_len;
raptor_unichar unichar;
if(flags < 0 || flags > 3)
return 1;
for(; (c=*string); string++, len--) {
if((delim && c == delim && (delim == '\'' || delim == '"')) ||
c == '\\') {
raptor_iostream_write_byte('\\', iostr);
raptor_iostream_write_byte(c, iostr);
continue;
}
if(delim && c == delim) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(c, 4, iostr);
continue;
}
if(flags != 2) {
/* N-Triples, Turtle or JSON */
/* Note: NTriples is ASCII */
if(c == 0x09) {
raptor_iostream_counted_string_write("\\t", 2, iostr);
continue;
} else if((flags == 3) && c == 0x08) {
/* JSON has \b for backspace */
raptor_iostream_counted_string_write("\\b", 2, iostr);
continue;
} else if(c == 0x0a) {
raptor_iostream_counted_string_write("\\n", 2, iostr);
continue;
} else if((flags == 3) && c == 0x0b) {
/* JSON has \f for formfeed */
raptor_iostream_counted_string_write("\\f", 2, iostr);
continue;
} else if(c == 0x0d) {
raptor_iostream_counted_string_write("\\r", 2, iostr);
continue;
} else if(c < 0x20|| c == 0x7f) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(c, 4, iostr);
continue;
} else if(c < 0x80) {
raptor_iostream_write_byte(c, iostr);
continue;
}
} else if(c < 0x80) {
/* Turtle long string has no escapes except delim */
raptor_iostream_write_byte(c, iostr);
continue;
}
/* It is unicode */
unichar_len = raptor_unicode_utf8_string_get_char(string, len, NULL);
if(unichar_len < 0 || RAPTOR_GOOD_CAST(size_t, unichar_len) > len)
/* UTF-8 encoding had an error or ended in the middle of a string */
return 1;
if(flags >= 1 && flags <= 3) {
/* Turtle and JSON are UTF-8 - no need to escape */
raptor_iostream_counted_string_write(string, unichar_len, iostr);
} else {
unichar_len = raptor_unicode_utf8_string_get_char(string, len, &unichar);
if(unichar_len < 0)
return 1;
if(unichar < 0x10000) {
raptor_iostream_counted_string_write("\\u", 2, iostr);
raptor_iostream_hexadecimal_write(RAPTOR_GOOD_CAST(unsigned int, unichar), 4, iostr);
} else {
raptor_iostream_counted_string_write("\\U", 2, iostr);
raptor_iostream_hexadecimal_write(RAPTOR_GOOD_CAST(unsigned int, unichar), 8, iostr);
}
}
unichar_len--; /* since loop does len-- */
string += unichar_len; len -= unichar_len;
}
return 0;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,633 | raptor_turtle_writer_base(raptor_turtle_writer* turtle_writer,
raptor_uri* base_uri)
{
if(base_uri) {
raptor_iostream_counted_string_write("@base ", 6, turtle_writer->iostr);
raptor_turtle_writer_reference(turtle_writer, base_uri);
raptor_iostream_counted_string_write(" .\n", 3, turtle_writer->iostr);
}
}
| +Info | 0 | raptor_turtle_writer_base(raptor_turtle_writer* turtle_writer,
raptor_uri* base_uri)
{
if(base_uri) {
raptor_iostream_counted_string_write("@base ", 6, turtle_writer->iostr);
raptor_turtle_writer_reference(turtle_writer, base_uri);
raptor_iostream_counted_string_write(" .\n", 3, turtle_writer->iostr);
}
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,634 | raptor_turtle_writer_bnodeid(raptor_turtle_writer* turtle_writer,
const unsigned char *bnodeid, size_t len)
{
raptor_bnodeid_ntriples_write(bnodeid, len,
turtle_writer->iostr);
}
| +Info | 0 | raptor_turtle_writer_bnodeid(raptor_turtle_writer* turtle_writer,
const unsigned char *bnodeid, size_t len)
{
raptor_bnodeid_ntriples_write(bnodeid, len,
turtle_writer->iostr);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,635 | raptor_turtle_writer_comment(raptor_turtle_writer* turtle_writer,
const unsigned char *string)
{
unsigned char c;
size_t len = strlen((const char*)string);
raptor_iostream_counted_string_write((const unsigned char*)"# ", 2,
turtle_writer->iostr);
for(; (c=*string); string++, len--) {
if(c == '\n') {
raptor_turtle_writer_newline(turtle_writer);
raptor_iostream_counted_string_write((const unsigned char*)"# ", 2,
turtle_writer->iostr);
} else if(c != '\r') {
/* skip carriage returns (windows... *sigh*) */
raptor_iostream_write_byte(c, turtle_writer->iostr);
}
}
raptor_turtle_writer_newline(turtle_writer);
}
| +Info | 0 | raptor_turtle_writer_comment(raptor_turtle_writer* turtle_writer,
const unsigned char *string)
{
unsigned char c;
size_t len = strlen((const char*)string);
raptor_iostream_counted_string_write((const unsigned char*)"# ", 2,
turtle_writer->iostr);
for(; (c=*string); string++, len--) {
if(c == '\n') {
raptor_turtle_writer_newline(turtle_writer);
raptor_iostream_counted_string_write((const unsigned char*)"# ", 2,
turtle_writer->iostr);
} else if(c != '\r') {
/* skip carriage returns (windows... *sigh*) */
raptor_iostream_write_byte(c, turtle_writer->iostr);
}
}
raptor_turtle_writer_newline(turtle_writer);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,636 | raptor_turtle_writer_decrease_indent(raptor_turtle_writer *turtle_writer)
{
turtle_writer->depth -= turtle_writer->indent;
}
| +Info | 0 | raptor_turtle_writer_decrease_indent(raptor_turtle_writer *turtle_writer)
{
turtle_writer->depth -= turtle_writer->indent;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,637 | raptor_turtle_writer_get_option_string(raptor_turtle_writer *turtle_writer,
raptor_option option)
{
return NULL;
}
| +Info | 0 | raptor_turtle_writer_get_option_string(raptor_turtle_writer *turtle_writer,
raptor_option option)
{
return NULL;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,638 | raptor_turtle_writer_literal(raptor_turtle_writer* turtle_writer,
raptor_namespace_stack *nstack,
const unsigned char* s, const unsigned char* lang,
raptor_uri* datatype)
{
/* DBL_MAX = 309 decimal digits */
#define INT_MAX_LEN 309
/* DBL_EPSILON = 52 digits */
#define FRAC_MAX_LEN 52
char* endptr = (char *)s;
int written = 0;
/* typed literal special cases */
if(datatype) {
/* integer */
if(raptor_uri_equals(datatype, turtle_writer->xsd_integer_uri)) {
/* FIXME. Work around that gcc < 4.5 cannot disable warn_unused_result */
long gcc_is_stupid = strtol((const char*)s, &endptr, 10);
if(endptr != (char*)s && !*endptr) {
raptor_iostream_string_write(s, turtle_writer->iostr);
/* More gcc madness to 'use' the variable I didn't want */
written = 1 + 0 * (int)gcc_is_stupid;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:integer literal.");
}
/* double, decimal */
} else if(raptor_uri_equals(datatype, turtle_writer->xsd_double_uri) ||
raptor_uri_equals(datatype, turtle_writer->xsd_decimal_uri)) {
/* FIXME. Work around that gcc < 4.5 cannot disable warn_unused_result */
double gcc_is_doubly_stupid = strtod((const char*)s, &endptr);
if(endptr != (char*)s && !*endptr) {
raptor_iostream_string_write(s, turtle_writer->iostr);
/* More gcc madness to 'use' the variable I didn't want */
written = 1 + 0 * (int)gcc_is_doubly_stupid;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:double or xsd:decimal literal.");
}
/* boolean */
} else if(raptor_uri_equals(datatype, turtle_writer->xsd_boolean_uri)) {
if(!strcmp((const char*)s, "0") || !strcmp((const char*)s, "false")) {
raptor_iostream_string_write("false", turtle_writer->iostr);
written = 1;
} else if(!strcmp((const char*)s, "1") || !strcmp((const char*)s, "true")) {
raptor_iostream_string_write("true", turtle_writer->iostr);
written = 1;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:boolean literal.");
}
}
}
if(written)
return 0;
if(raptor_turtle_writer_quoted_counted_string(turtle_writer, s,
strlen((const char*)s)))
return 1;
/* typed literal, not a special case */
if(datatype) {
raptor_qname* qname;
raptor_iostream_string_write("^^", turtle_writer->iostr);
qname = raptor_new_qname_from_namespace_uri(nstack, datatype, 10);
if(qname) {
raptor_turtle_writer_qname(turtle_writer, qname);
raptor_free_qname(qname);
} else
raptor_turtle_writer_reference(turtle_writer, datatype);
} else if(lang) {
/* literal with language tag */
raptor_iostream_write_byte('@', turtle_writer->iostr);
raptor_iostream_string_write(lang, turtle_writer->iostr);
}
return 0;
}
| +Info | 0 | raptor_turtle_writer_literal(raptor_turtle_writer* turtle_writer,
raptor_namespace_stack *nstack,
const unsigned char* s, const unsigned char* lang,
raptor_uri* datatype)
{
/* DBL_MAX = 309 decimal digits */
#define INT_MAX_LEN 309
/* DBL_EPSILON = 52 digits */
#define FRAC_MAX_LEN 52
char* endptr = (char *)s;
int written = 0;
/* typed literal special cases */
if(datatype) {
/* integer */
if(raptor_uri_equals(datatype, turtle_writer->xsd_integer_uri)) {
/* FIXME. Work around that gcc < 4.5 cannot disable warn_unused_result */
long gcc_is_stupid = strtol((const char*)s, &endptr, 10);
if(endptr != (char*)s && !*endptr) {
raptor_iostream_string_write(s, turtle_writer->iostr);
/* More gcc madness to 'use' the variable I didn't want */
written = 1 + 0 * (int)gcc_is_stupid;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:integer literal.");
}
/* double, decimal */
} else if(raptor_uri_equals(datatype, turtle_writer->xsd_double_uri) ||
raptor_uri_equals(datatype, turtle_writer->xsd_decimal_uri)) {
/* FIXME. Work around that gcc < 4.5 cannot disable warn_unused_result */
double gcc_is_doubly_stupid = strtod((const char*)s, &endptr);
if(endptr != (char*)s && !*endptr) {
raptor_iostream_string_write(s, turtle_writer->iostr);
/* More gcc madness to 'use' the variable I didn't want */
written = 1 + 0 * (int)gcc_is_doubly_stupid;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:double or xsd:decimal literal.");
}
/* boolean */
} else if(raptor_uri_equals(datatype, turtle_writer->xsd_boolean_uri)) {
if(!strcmp((const char*)s, "0") || !strcmp((const char*)s, "false")) {
raptor_iostream_string_write("false", turtle_writer->iostr);
written = 1;
} else if(!strcmp((const char*)s, "1") || !strcmp((const char*)s, "true")) {
raptor_iostream_string_write("true", turtle_writer->iostr);
written = 1;
} else {
raptor_log_error(turtle_writer->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Illegal value for xsd:boolean literal.");
}
}
}
if(written)
return 0;
if(raptor_turtle_writer_quoted_counted_string(turtle_writer, s,
strlen((const char*)s)))
return 1;
/* typed literal, not a special case */
if(datatype) {
raptor_qname* qname;
raptor_iostream_string_write("^^", turtle_writer->iostr);
qname = raptor_new_qname_from_namespace_uri(nstack, datatype, 10);
if(qname) {
raptor_turtle_writer_qname(turtle_writer, qname);
raptor_free_qname(qname);
} else
raptor_turtle_writer_reference(turtle_writer, datatype);
} else if(lang) {
/* literal with language tag */
raptor_iostream_write_byte('@', turtle_writer->iostr);
raptor_iostream_string_write(lang, turtle_writer->iostr);
}
return 0;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,639 | raptor_turtle_writer_namespace_prefix(raptor_turtle_writer* turtle_writer,
raptor_namespace* ns)
{
raptor_iostream_string_write("@prefix ", turtle_writer->iostr);
if(ns->prefix)
raptor_iostream_string_write(raptor_namespace_get_prefix(ns),
turtle_writer->iostr);
raptor_iostream_counted_string_write(": ", 2, turtle_writer->iostr);
raptor_turtle_writer_reference(turtle_writer, raptor_namespace_get_uri(ns));
raptor_iostream_counted_string_write(" .\n", 3, turtle_writer->iostr);
}
| +Info | 0 | raptor_turtle_writer_namespace_prefix(raptor_turtle_writer* turtle_writer,
raptor_namespace* ns)
{
raptor_iostream_string_write("@prefix ", turtle_writer->iostr);
if(ns->prefix)
raptor_iostream_string_write(raptor_namespace_get_prefix(ns),
turtle_writer->iostr);
raptor_iostream_counted_string_write(": ", 2, turtle_writer->iostr);
raptor_turtle_writer_reference(turtle_writer, raptor_namespace_get_uri(ns));
raptor_iostream_counted_string_write(" .\n", 3, turtle_writer->iostr);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,640 | raptor_turtle_writer_newline(raptor_turtle_writer *turtle_writer)
{
int num_spaces;
raptor_iostream_write_byte('\n', turtle_writer->iostr);
if(!TURTLE_WRITER_AUTO_INDENT(turtle_writer))
return;
num_spaces = turtle_writer->depth * turtle_writer->indent;
while(num_spaces > 0) {
int count;
count = (num_spaces > RAPTOR_GOOD_CAST(int, SPACES_BUFFER_SIZE)) ?
RAPTOR_GOOD_CAST(int, SPACES_BUFFER_SIZE) : num_spaces;
raptor_iostream_counted_string_write(spaces_buffer, count, turtle_writer->iostr);
num_spaces -= count;
}
return;
}
| +Info | 0 | raptor_turtle_writer_newline(raptor_turtle_writer *turtle_writer)
{
int num_spaces;
raptor_iostream_write_byte('\n', turtle_writer->iostr);
if(!TURTLE_WRITER_AUTO_INDENT(turtle_writer))
return;
num_spaces = turtle_writer->depth * turtle_writer->indent;
while(num_spaces > 0) {
int count;
count = (num_spaces > RAPTOR_GOOD_CAST(int, SPACES_BUFFER_SIZE)) ?
RAPTOR_GOOD_CAST(int, SPACES_BUFFER_SIZE) : num_spaces;
raptor_iostream_counted_string_write(spaces_buffer, count, turtle_writer->iostr);
num_spaces -= count;
}
return;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,641 | raptor_turtle_writer_qname(raptor_turtle_writer* turtle_writer,
raptor_qname* qname)
{
raptor_iostream* iostr = turtle_writer->iostr;
if(qname->nspace && qname->nspace->prefix_length > 0)
raptor_iostream_counted_string_write(qname->nspace->prefix,
qname->nspace->prefix_length,
iostr);
raptor_iostream_write_byte(':', iostr);
raptor_iostream_counted_string_write(qname->local_name,
qname->local_name_length,
iostr);
return;
}
| +Info | 0 | raptor_turtle_writer_qname(raptor_turtle_writer* turtle_writer,
raptor_qname* qname)
{
raptor_iostream* iostr = turtle_writer->iostr;
if(qname->nspace && qname->nspace->prefix_length > 0)
raptor_iostream_counted_string_write(qname->nspace->prefix,
qname->nspace->prefix_length,
iostr);
raptor_iostream_write_byte(':', iostr);
raptor_iostream_counted_string_write(qname->local_name,
qname->local_name_length,
iostr);
return;
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,642 | raptor_turtle_writer_raw(raptor_turtle_writer* turtle_writer,
const unsigned char *s)
{
raptor_iostream_string_write(s, turtle_writer->iostr);
}
| +Info | 0 | raptor_turtle_writer_raw(raptor_turtle_writer* turtle_writer,
const unsigned char *s)
{
raptor_iostream_string_write(s, turtle_writer->iostr);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,643 | raptor_turtle_writer_reference(raptor_turtle_writer* turtle_writer,
raptor_uri* uri)
{
unsigned char* uri_str;
size_t length;
uri_str = raptor_uri_to_relative_counted_uri_string(turtle_writer->base_uri, uri, &length);
raptor_iostream_write_byte('<', turtle_writer->iostr);
if(uri_str)
raptor_string_ntriples_write(uri_str, length, '>', turtle_writer->iostr);
raptor_iostream_write_byte('>', turtle_writer->iostr);
RAPTOR_FREE(char*, uri_str);
}
| +Info | 0 | raptor_turtle_writer_reference(raptor_turtle_writer* turtle_writer,
raptor_uri* uri)
{
unsigned char* uri_str;
size_t length;
uri_str = raptor_uri_to_relative_counted_uri_string(turtle_writer->base_uri, uri, &length);
raptor_iostream_write_byte('<', turtle_writer->iostr);
if(uri_str)
raptor_string_ntriples_write(uri_str, length, '>', turtle_writer->iostr);
raptor_iostream_write_byte('>', turtle_writer->iostr);
RAPTOR_FREE(char*, uri_str);
}
| @@ -705,6 +705,7 @@ raptor_turtle_writer_set_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS:
@@ -829,6 +830,7 @@ raptor_turtle_writer_get_option(raptor_turtle_writer *turtle_writer,
/* Shared */
case RAPTOR_OPTION_NO_NET:
case RAPTOR_OPTION_NO_FILE:
+ case RAPTOR_OPTION_LOAD_EXTERNAL_ENTITIES:
/* XML writer options */
case RAPTOR_OPTION_RELATIVE_URIS: | CWE-200 | null | null |
17,644 | static bool Curl_isunreserved(unsigned char in)
{
switch (in) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
case '-': case '.': case '_': case '~':
return TRUE;
default:
break;
}
return FALSE;
}
| Sql | 0 | static bool Curl_isunreserved(unsigned char in)
{
switch (in) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case 'a': case 'b': case 'c': case 'd': case 'e':
case 'f': case 'g': case 'h': case 'i': case 'j':
case 'k': case 'l': case 'm': case 'n': case 'o':
case 'p': case 'q': case 'r': case 's': case 't':
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
case 'A': case 'B': case 'C': case 'D': case 'E':
case 'F': case 'G': case 'H': case 'I': case 'J':
case 'K': case 'L': case 'M': case 'N': case 'O':
case 'P': case 'Q': case 'R': case 'S': case 'T':
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
case '-': case '.': case '_': case '~':
return TRUE;
default:
break;
}
return FALSE;
}
| @@ -31,6 +31,7 @@
#include "urldata.h"
#include "warnless.h"
#include "non-ascii.h"
+#include "escape.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -84,7 +85,7 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
char *testing_ptr = NULL;
unsigned char in; /* we need to treat the characters unsigned */
size_t newlen = alloc;
- int strindex=0;
+ size_t strindex=0;
size_t length;
CURLcode res;
@@ -132,23 +133,29 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
}
/*
- * Unescapes the given URL escaped string of given length. Returns a
- * pointer to a malloced string with length given in *olen.
- * If length == 0, the length is assumed to be strlen(string).
- * If olen == NULL, no output length is stored.
+ * Curl_urldecode() URL decodes the given string.
+ *
+ * Optionally detects control characters (byte codes lower than 32) in the
+ * data and rejects such data.
+ *
+ * Returns a pointer to a malloced string in *ostring with length given in
+ * *olen. If length == 0, the length is assumed to be strlen(string).
+ *
*/
-char *curl_easy_unescape(CURL *handle, const char *string, int length,
- int *olen)
+CURLcode Curl_urldecode(struct SessionHandle *data,
+ const char *string, size_t length,
+ char **ostring, size_t *olen,
+ bool reject_ctrl)
{
- int alloc = (length?length:(int)strlen(string))+1;
+ size_t alloc = (length?length:strlen(string))+1;
char *ns = malloc(alloc);
unsigned char in;
- int strindex=0;
+ size_t strindex=0;
unsigned long hex;
CURLcode res;
if(!ns)
- return NULL;
+ return CURLE_OUT_OF_MEMORY;
while(--alloc > 0) {
in = *string;
@@ -164,16 +171,20 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
in = curlx_ultouc(hex); /* this long is never bigger than 255 anyway */
- res = Curl_convert_from_network(handle, &in, 1);
+ res = Curl_convert_from_network(data, &in, 1);
if(res) {
/* Curl_convert_from_network calls failf if unsuccessful */
free(ns);
- return NULL;
+ return res;
}
string+=2;
alloc-=2;
}
+ if(reject_ctrl && (in < 0x20)) {
+ free(ns);
+ return CURLE_URL_MALFORMAT;
+ }
ns[strindex++] = in;
string++;
@@ -183,7 +194,33 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
if(olen)
/* store output size */
*olen = strindex;
- return ns;
+
+ if(ostring)
+ /* store output string */
+ *ostring = ns;
+
+ return CURLE_OK;
+}
+
+/*
+ * Unescapes the given URL escaped string of given length. Returns a
+ * pointer to a malloced string with length given in *olen.
+ * If length == 0, the length is assumed to be strlen(string).
+ * If olen == NULL, no output length is stored.
+ */
+char *curl_easy_unescape(CURL *handle, const char *string, int length,
+ int *olen)
+{
+ char *str = NULL;
+ size_t inputlen = length;
+ size_t outputlen;
+ CURLcode res = Curl_urldecode(handle, string, inputlen, &str, &outputlen,
+ FALSE);
+ if(res)
+ return NULL;
+ if(olen)
+ *olen = curlx_uztosi(outputlen);
+ return str;
}
/* For operating systems/environments that use different malloc/free | CWE-89 | null | null |
17,645 | void curl_free(void *p)
{
if(p)
free(p);
}
| Sql | 0 | void curl_free(void *p)
{
if(p)
free(p);
}
| @@ -31,6 +31,7 @@
#include "urldata.h"
#include "warnless.h"
#include "non-ascii.h"
+#include "escape.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -84,7 +85,7 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
char *testing_ptr = NULL;
unsigned char in; /* we need to treat the characters unsigned */
size_t newlen = alloc;
- int strindex=0;
+ size_t strindex=0;
size_t length;
CURLcode res;
@@ -132,23 +133,29 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
}
/*
- * Unescapes the given URL escaped string of given length. Returns a
- * pointer to a malloced string with length given in *olen.
- * If length == 0, the length is assumed to be strlen(string).
- * If olen == NULL, no output length is stored.
+ * Curl_urldecode() URL decodes the given string.
+ *
+ * Optionally detects control characters (byte codes lower than 32) in the
+ * data and rejects such data.
+ *
+ * Returns a pointer to a malloced string in *ostring with length given in
+ * *olen. If length == 0, the length is assumed to be strlen(string).
+ *
*/
-char *curl_easy_unescape(CURL *handle, const char *string, int length,
- int *olen)
+CURLcode Curl_urldecode(struct SessionHandle *data,
+ const char *string, size_t length,
+ char **ostring, size_t *olen,
+ bool reject_ctrl)
{
- int alloc = (length?length:(int)strlen(string))+1;
+ size_t alloc = (length?length:strlen(string))+1;
char *ns = malloc(alloc);
unsigned char in;
- int strindex=0;
+ size_t strindex=0;
unsigned long hex;
CURLcode res;
if(!ns)
- return NULL;
+ return CURLE_OUT_OF_MEMORY;
while(--alloc > 0) {
in = *string;
@@ -164,16 +171,20 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
in = curlx_ultouc(hex); /* this long is never bigger than 255 anyway */
- res = Curl_convert_from_network(handle, &in, 1);
+ res = Curl_convert_from_network(data, &in, 1);
if(res) {
/* Curl_convert_from_network calls failf if unsuccessful */
free(ns);
- return NULL;
+ return res;
}
string+=2;
alloc-=2;
}
+ if(reject_ctrl && (in < 0x20)) {
+ free(ns);
+ return CURLE_URL_MALFORMAT;
+ }
ns[strindex++] = in;
string++;
@@ -183,7 +194,33 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
if(olen)
/* store output size */
*olen = strindex;
- return ns;
+
+ if(ostring)
+ /* store output string */
+ *ostring = ns;
+
+ return CURLE_OK;
+}
+
+/*
+ * Unescapes the given URL escaped string of given length. Returns a
+ * pointer to a malloced string with length given in *olen.
+ * If length == 0, the length is assumed to be strlen(string).
+ * If olen == NULL, no output length is stored.
+ */
+char *curl_easy_unescape(CURL *handle, const char *string, int length,
+ int *olen)
+{
+ char *str = NULL;
+ size_t inputlen = length;
+ size_t outputlen;
+ CURLcode res = Curl_urldecode(handle, string, inputlen, &str, &outputlen,
+ FALSE);
+ if(res)
+ return NULL;
+ if(olen)
+ *olen = curlx_uztosi(outputlen);
+ return str;
}
/* For operating systems/environments that use different malloc/free | CWE-89 | null | null |
17,646 | static CURLcode imap_connect(struct connectdata *conn,
bool *done) /* see description above */
{
CURLcode result;
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data=conn->data;
struct pingpong *pp = &imapc->pp;
*done = FALSE; /* default to not done yet */
/* If there already is a protocol-specific struct allocated for this
sessionhandle, deal with it */
Curl_reset_reqproto(conn);
result = imap_init(conn);
if(CURLE_OK != result)
return result;
/* We always support persistent connections on imap */
conn->bits.close = FALSE;
pp->response_time = RESP_TIMEOUT; /* set default response time-out */
pp->statemach_act = imap_statemach_act;
pp->endofresp = imap_endofresp;
pp->conn = conn;
if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
/* for IMAP over HTTP proxy */
struct HTTP http_proxy;
struct FTP *imap_save;
/* BLOCKING */
/* We want "seamless" IMAP operations through HTTP proxy tunnel */
/* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member
* conn->proto.http; we want IMAP through HTTP and we have to change the
* member temporarily for connecting to the HTTP proxy. After
* Curl_proxyCONNECT we have to set back the member to the original struct
* IMAP pointer
*/
imap_save = data->state.proto.imap;
memset(&http_proxy, 0, sizeof(http_proxy));
data->state.proto.http = &http_proxy;
result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
conn->host.name, conn->remote_port);
data->state.proto.imap = imap_save;
if(CURLE_OK != result)
return result;
}
if((conn->handler->flags & PROTOPT_SSL) &&
data->state.used_interface != Curl_if_multi) {
/* BLOCKING */
result = Curl_ssl_connect(conn, FIRSTSOCKET);
if(result)
return result;
}
Curl_pp_init(pp); /* init generic pingpong data */
/* When we connect, we start in the state where we await the server greeting
response */
state(conn, IMAP_SERVERGREET);
imapc->idstr = "*"; /* we start off waiting for a '*' response */
if(data->state.used_interface == Curl_if_multi)
result = imap_multi_statemach(conn, done);
else {
result = imap_easy_statemach(conn);
if(!result)
*done = TRUE;
}
return result;
}
| Sql | 0 | static CURLcode imap_connect(struct connectdata *conn,
bool *done) /* see description above */
{
CURLcode result;
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data=conn->data;
struct pingpong *pp = &imapc->pp;
*done = FALSE; /* default to not done yet */
/* If there already is a protocol-specific struct allocated for this
sessionhandle, deal with it */
Curl_reset_reqproto(conn);
result = imap_init(conn);
if(CURLE_OK != result)
return result;
/* We always support persistent connections on imap */
conn->bits.close = FALSE;
pp->response_time = RESP_TIMEOUT; /* set default response time-out */
pp->statemach_act = imap_statemach_act;
pp->endofresp = imap_endofresp;
pp->conn = conn;
if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
/* for IMAP over HTTP proxy */
struct HTTP http_proxy;
struct FTP *imap_save;
/* BLOCKING */
/* We want "seamless" IMAP operations through HTTP proxy tunnel */
/* Curl_proxyCONNECT is based on a pointer to a struct HTTP at the member
* conn->proto.http; we want IMAP through HTTP and we have to change the
* member temporarily for connecting to the HTTP proxy. After
* Curl_proxyCONNECT we have to set back the member to the original struct
* IMAP pointer
*/
imap_save = data->state.proto.imap;
memset(&http_proxy, 0, sizeof(http_proxy));
data->state.proto.http = &http_proxy;
result = Curl_proxyCONNECT(conn, FIRSTSOCKET,
conn->host.name, conn->remote_port);
data->state.proto.imap = imap_save;
if(CURLE_OK != result)
return result;
}
if((conn->handler->flags & PROTOPT_SSL) &&
data->state.used_interface != Curl_if_multi) {
/* BLOCKING */
result = Curl_ssl_connect(conn, FIRSTSOCKET);
if(result)
return result;
}
Curl_pp_init(pp); /* init generic pingpong data */
/* When we connect, we start in the state where we await the server greeting
response */
state(conn, IMAP_SERVERGREET);
imapc->idstr = "*"; /* we start off waiting for a '*' response */
if(data->state.used_interface == Curl_if_multi)
result = imap_multi_statemach(conn, done);
else {
result = imap_easy_statemach(conn);
if(!result)
*done = TRUE;
}
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,647 | static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
{
struct imap_conn *imapc= &conn->proto.imapc;
/* The IMAP session may or may not have been allocated/setup at this
point! */
if(!dead_connection && imapc->pp.conn)
(void)imap_logout(conn); /* ignore errors on the LOGOUT */
Curl_pp_disconnect(&imapc->pp);
Curl_safefree(imapc->mailbox);
return CURLE_OK;
}
| Sql | 0 | static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection)
{
struct imap_conn *imapc= &conn->proto.imapc;
/* The IMAP session may or may not have been allocated/setup at this
point! */
if(!dead_connection && imapc->pp.conn)
(void)imap_logout(conn); /* ignore errors on the LOGOUT */
Curl_pp_disconnect(&imapc->pp);
Curl_safefree(imapc->mailbox);
return CURLE_OK;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,648 | static CURLcode imap_do(struct connectdata *conn, bool *done)
{
CURLcode retcode = CURLE_OK;
*done = FALSE; /* default to false */
/*
Since connections can be re-used between SessionHandles, this might be a
connection already existing but on a fresh SessionHandle struct so we must
make sure we have a good 'struct IMAP' to play with. For new connections,
the struct IMAP is allocated and setup in the imap_connect() function.
*/
Curl_reset_reqproto(conn);
retcode = imap_init(conn);
if(retcode)
return retcode;
retcode = imap_parse_url_path(conn);
if(retcode)
return retcode;
retcode = imap_regular_transfer(conn, done);
return retcode;
}
| Sql | 0 | static CURLcode imap_do(struct connectdata *conn, bool *done)
{
CURLcode retcode = CURLE_OK;
*done = FALSE; /* default to false */
/*
Since connections can be re-used between SessionHandles, this might be a
connection already existing but on a fresh SessionHandle struct so we must
make sure we have a good 'struct IMAP' to play with. For new connections,
the struct IMAP is allocated and setup in the imap_connect() function.
*/
Curl_reset_reqproto(conn);
retcode = imap_init(conn);
if(retcode)
return retcode;
retcode = imap_parse_url_path(conn);
if(retcode)
return retcode;
retcode = imap_regular_transfer(conn, done);
return retcode;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,649 | static CURLcode imap_doing(struct connectdata *conn,
bool *dophase_done)
{
CURLcode result;
result = imap_multi_statemach(conn, dophase_done);
if(*dophase_done) {
result = imap_dophase_done(conn, FALSE /* not connected */);
DEBUGF(infof(conn->data, "DO phase is complete\n"));
}
return result;
}
| Sql | 0 | static CURLcode imap_doing(struct connectdata *conn,
bool *dophase_done)
{
CURLcode result;
result = imap_multi_statemach(conn, dophase_done);
if(*dophase_done) {
result = imap_dophase_done(conn, FALSE /* not connected */);
DEBUGF(infof(conn->data, "DO phase is complete\n"));
}
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,650 | static CURLcode imap_done(struct connectdata *conn, CURLcode status,
bool premature)
{
struct SessionHandle *data = conn->data;
struct FTP *imap = data->state.proto.imap;
CURLcode result=CURLE_OK;
(void)premature;
if(!imap)
/* When the easy handle is removed from the multi while libcurl is still
* trying to resolve the host name, it seems that the imap struct is not
* yet initialized, but the removal action calls Curl_done() which calls
* this function. So we simply return success if no imap pointer is set.
*/
return CURLE_OK;
if(status) {
conn->bits.close = TRUE; /* marked for closure */
result = status; /* use the already set error code */
}
/* clear these for next connection */
imap->transfer = FTPTRANSFER_BODY;
return result;
}
| Sql | 0 | static CURLcode imap_done(struct connectdata *conn, CURLcode status,
bool premature)
{
struct SessionHandle *data = conn->data;
struct FTP *imap = data->state.proto.imap;
CURLcode result=CURLE_OK;
(void)premature;
if(!imap)
/* When the easy handle is removed from the multi while libcurl is still
* trying to resolve the host name, it seems that the imap struct is not
* yet initialized, but the removal action calls Curl_done() which calls
* this function. So we simply return success if no imap pointer is set.
*/
return CURLE_OK;
if(status) {
conn->bits.close = TRUE; /* marked for closure */
result = status; /* use the already set error code */
}
/* clear these for next connection */
imap->transfer = FTPTRANSFER_BODY;
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,651 | static CURLcode imap_dophase_done(struct connectdata *conn,
bool connected)
{
struct FTP *imap = conn->data->state.proto.imap;
(void)connected;
if(imap->transfer != FTPTRANSFER_BODY)
/* no data to transfer */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
return CURLE_OK;
}
| Sql | 0 | static CURLcode imap_dophase_done(struct connectdata *conn,
bool connected)
{
struct FTP *imap = conn->data->state.proto.imap;
(void)connected;
if(imap->transfer != FTPTRANSFER_BODY)
/* no data to transfer */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);
return CURLE_OK;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,652 | static int imap_endofresp(struct pingpong *pp, int *resp)
{
char *line = pp->linestart_resp;
size_t len = pp->nread_resp;
struct imap_conn *imapc = &pp->conn->proto.imapc;
const char *id = imapc->idstr;
size_t id_len = strlen(id);
if(len >= id_len + 3) {
if(!memcmp(id, line, id_len) && (line[id_len] == ' ') ) {
/* end of response */
*resp = line[id_len+1]; /* O, N or B */
return TRUE;
}
else if((imapc->state == IMAP_FETCH) &&
!memcmp("* ", line, 2) ) {
/* FETCH response we're interested in */
*resp = '*';
return TRUE;
}
}
return FALSE; /* nothing for us */
}
| Sql | 0 | static int imap_endofresp(struct pingpong *pp, int *resp)
{
char *line = pp->linestart_resp;
size_t len = pp->nread_resp;
struct imap_conn *imapc = &pp->conn->proto.imapc;
const char *id = imapc->idstr;
size_t id_len = strlen(id);
if(len >= id_len + 3) {
if(!memcmp(id, line, id_len) && (line[id_len] == ' ') ) {
/* end of response */
*resp = line[id_len+1]; /* O, N or B */
return TRUE;
}
else if((imapc->state == IMAP_FETCH) &&
!memcmp("* ", line, 2) ) {
/* FETCH response we're interested in */
*resp = '*';
return TRUE;
}
}
return FALSE; /* nothing for us */
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,653 | static CURLcode imap_fetch(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
const char *str;
str = getcmdid(conn);
/* TODO: make this select the correct mail
* Use "1 body[text]" to get the full mail body of mail 1
*/
result = imapsendf(conn, str, "%s FETCH 1 BODY[TEXT]", str);
if(result)
return result;
/*
* When issued, the server will respond with a single line similar to
* '* 1 FETCH (BODY[TEXT] {2021}'
*
* Identifying the fetch and how many bytes of contents we can expect. We
* must extract that number before continuing to "download as usual".
*/
state(conn, IMAP_FETCH);
return result;
}
| Sql | 0 | static CURLcode imap_fetch(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
const char *str;
str = getcmdid(conn);
/* TODO: make this select the correct mail
* Use "1 body[text]" to get the full mail body of mail 1
*/
result = imapsendf(conn, str, "%s FETCH 1 BODY[TEXT]", str);
if(result)
return result;
/*
* When issued, the server will respond with a single line similar to
* '* 1 FETCH (BODY[TEXT] {2021}'
*
* Identifying the fetch and how many bytes of contents we can expect. We
* must extract that number before continuing to "download as usual".
*/
state(conn, IMAP_FETCH);
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,654 | static int imap_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks)
{
return Curl_pp_getsock(&conn->proto.imapc.pp, socks, numsocks);
}
| Sql | 0 | static int imap_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks)
{
return Curl_pp_getsock(&conn->proto.imapc.pp, socks, numsocks);
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,655 | static CURLcode imap_logout(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
const char *str;
str = getcmdid(conn);
result = imapsendf(conn, str, "%s LOGOUT", str, NULL);
if(result)
return result;
state(conn, IMAP_LOGOUT);
result = imap_easy_statemach(conn);
return result;
}
| Sql | 0 | static CURLcode imap_logout(struct connectdata *conn)
{
CURLcode result = CURLE_OK;
const char *str;
str = getcmdid(conn);
result = imapsendf(conn, str, "%s LOGOUT", str, NULL);
if(result)
return result;
state(conn, IMAP_LOGOUT);
result = imap_easy_statemach(conn);
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,656 | static CURLcode imap_multi_statemach(struct connectdata *conn,
bool *done)
{
struct imap_conn *imapc = &conn->proto.imapc;
CURLcode result;
if((conn->handler->flags & PROTOPT_SSL) && !imapc->ssldone)
result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone);
else
result = Curl_pp_multi_statemach(&imapc->pp);
*done = (imapc->state == IMAP_STOP) ? TRUE : FALSE;
return result;
}
| Sql | 0 | static CURLcode imap_multi_statemach(struct connectdata *conn,
bool *done)
{
struct imap_conn *imapc = &conn->proto.imapc;
CURLcode result;
if((conn->handler->flags & PROTOPT_SSL) && !imapc->ssldone)
result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone);
else
result = Curl_pp_multi_statemach(&imapc->pp);
*done = (imapc->state == IMAP_STOP) ? TRUE : FALSE;
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,657 | CURLcode imap_perform(struct connectdata *conn,
bool *connected, /* connect status after PASV / PORT */
bool *dophase_done)
{
/* this is IMAP and no proxy */
CURLcode result=CURLE_OK;
DEBUGF(infof(conn->data, "DO phase starts\n"));
if(conn->data->set.opt_no_body) {
/* requested no body means no transfer... */
struct FTP *imap = conn->data->state.proto.imap;
imap->transfer = FTPTRANSFER_INFO;
}
*dophase_done = FALSE; /* not done yet */
/* start the first command in the DO phase */
result = imap_select(conn);
if(result)
return result;
/* run the state-machine */
if(conn->data->state.used_interface == Curl_if_multi)
result = imap_multi_statemach(conn, dophase_done);
else {
result = imap_easy_statemach(conn);
*dophase_done = TRUE; /* with the easy interface we are done here */
}
*connected = conn->bits.tcpconnect[FIRSTSOCKET];
if(*dophase_done)
DEBUGF(infof(conn->data, "DO phase is complete\n"));
return result;
}
| Sql | 0 | CURLcode imap_perform(struct connectdata *conn,
bool *connected, /* connect status after PASV / PORT */
bool *dophase_done)
{
/* this is IMAP and no proxy */
CURLcode result=CURLE_OK;
DEBUGF(infof(conn->data, "DO phase starts\n"));
if(conn->data->set.opt_no_body) {
/* requested no body means no transfer... */
struct FTP *imap = conn->data->state.proto.imap;
imap->transfer = FTPTRANSFER_INFO;
}
*dophase_done = FALSE; /* not done yet */
/* start the first command in the DO phase */
result = imap_select(conn);
if(result)
return result;
/* run the state-machine */
if(conn->data->state.used_interface == Curl_if_multi)
result = imap_multi_statemach(conn, dophase_done);
else {
result = imap_easy_statemach(conn);
*dophase_done = TRUE; /* with the easy interface we are done here */
}
*connected = conn->bits.tcpconnect[FIRSTSOCKET];
if(*dophase_done)
DEBUGF(infof(conn->data, "DO phase is complete\n"));
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,658 | CURLcode imap_regular_transfer(struct connectdata *conn,
bool *dophase_done)
{
CURLcode result=CURLE_OK;
bool connected=FALSE;
struct SessionHandle *data = conn->data;
data->req.size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
Curl_pgrsSetUploadSize(data, 0);
Curl_pgrsSetDownloadSize(data, 0);
result = imap_perform(conn,
&connected, /* have we connected after PASV/PORT */
dophase_done); /* all commands in the DO-phase done? */
if(CURLE_OK == result) {
if(!*dophase_done)
/* the DO phase has not completed yet */
return CURLE_OK;
result = imap_dophase_done(conn, connected);
if(result)
return result;
}
return result;
}
| Sql | 0 | CURLcode imap_regular_transfer(struct connectdata *conn,
bool *dophase_done)
{
CURLcode result=CURLE_OK;
bool connected=FALSE;
struct SessionHandle *data = conn->data;
data->req.size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
Curl_pgrsSetUploadSize(data, 0);
Curl_pgrsSetDownloadSize(data, 0);
result = imap_perform(conn,
&connected, /* have we connected after PASV/PORT */
dophase_done); /* all commands in the DO-phase done? */
if(CURLE_OK == result) {
if(!*dophase_done)
/* the DO phase has not completed yet */
return CURLE_OK;
result = imap_dophase_done(conn, connected);
if(result)
return result;
}
return result;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,659 | static CURLcode imap_setup_connection(struct connectdata * conn)
{
struct SessionHandle *data = conn->data;
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel imap operations through the proxy, we
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
if(conn->handler == &Curl_handler_imap)
conn->handler = &Curl_handler_imap_proxy;
else {
#ifdef USE_SSL
conn->handler = &Curl_handler_imaps_proxy;
#else
failf(data, "IMAPS not supported!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}
/*
* We explicitly mark this connection as persistent here as we're doing
* IMAP over HTTP and thus we accidentally avoid setting this value
* otherwise.
*/
conn->bits.close = FALSE;
#else
failf(data, "IMAP over http proxy requires HTTP support built-in!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}
data->state.path++; /* don't include the initial slash */
return CURLE_OK;
}
| Sql | 0 | static CURLcode imap_setup_connection(struct connectdata * conn)
{
struct SessionHandle *data = conn->data;
if(conn->bits.httpproxy && !data->set.tunnel_thru_httpproxy) {
/* Unless we have asked to tunnel imap operations through the proxy, we
switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP
if(conn->handler == &Curl_handler_imap)
conn->handler = &Curl_handler_imap_proxy;
else {
#ifdef USE_SSL
conn->handler = &Curl_handler_imaps_proxy;
#else
failf(data, "IMAPS not supported!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}
/*
* We explicitly mark this connection as persistent here as we're doing
* IMAP over HTTP and thus we accidentally avoid setting this value
* otherwise.
*/
conn->bits.close = FALSE;
#else
failf(data, "IMAP over http proxy requires HTTP support built-in!");
return CURLE_UNSUPPORTED_PROTOCOL;
#endif
}
data->state.path++; /* don't include the initial slash */
return CURLE_OK;
}
| @@ -953,17 +953,12 @@ static CURLcode imap_parse_url_path(struct connectdata *conn)
struct imap_conn *imapc = &conn->proto.imapc;
struct SessionHandle *data = conn->data;
const char *path = data->state.path;
- int len;
if(!*path)
path = "INBOX";
/* url decode the path and use this mailbox */
- imapc->mailbox = curl_easy_unescape(data, path, 0, &len);
- if(!imapc->mailbox)
- return CURLE_OUT_OF_MEMORY;
-
- return CURLE_OK;
+ return Curl_urldecode(data, path, 0, &imapc->mailbox, NULL, TRUE);
}
/* call this when the DO phase has completed */ | CWE-89 | null | null |
17,660 | static void __exit_signal(struct task_struct *tsk)
{
struct signal_struct *sig = tsk->signal;
struct sighand_struct *sighand;
BUG_ON(!sig);
BUG_ON(!atomic_read(&sig->count));
sighand = rcu_dereference(tsk->sighand);
spin_lock(&sighand->siglock);
posix_cpu_timers_exit(tsk);
if (atomic_dec_and_test(&sig->count))
posix_cpu_timers_exit_group(tsk);
else {
/*
* If there is any task waiting for the group exit
* then notify it:
*/
if (sig->group_exit_task && atomic_read(&sig->count) == sig->notify_count)
wake_up_process(sig->group_exit_task);
if (tsk == sig->curr_target)
sig->curr_target = next_thread(tsk);
/*
* Accumulate here the counters for all threads but the
* group leader as they die, so they can be added into
* the process-wide totals when those are taken.
* The group leader stays around as a zombie as long
* as there are other threads. When it gets reaped,
* the exit.c code will add its counts into these totals.
* We won't ever get here for the group leader, since it
* will have been the last reference on the signal_struct.
*/
sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
sig->min_flt += tsk->min_flt;
sig->maj_flt += tsk->maj_flt;
sig->nvcsw += tsk->nvcsw;
sig->nivcsw += tsk->nivcsw;
sig->inblock += task_io_get_inblock(tsk);
sig->oublock += task_io_get_oublock(tsk);
task_io_accounting_add(&sig->ioac, &tsk->ioac);
sig = NULL; /* Marker for below. */
}
__unhash_process(tsk);
/*
* Do this under ->siglock, we can race with another thread
* doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
*/
flush_sigqueue(&tsk->pending);
tsk->signal = NULL;
tsk->sighand = NULL;
spin_unlock(&sighand->siglock);
__cleanup_sighand(sighand);
clear_tsk_thread_flag(tsk,TIF_SIGPENDING);
if (sig) {
flush_sigqueue(&sig->shared_pending);
taskstats_tgid_free(sig);
/*
* Make sure ->signal can't go away under rq->lock,
* see account_group_exec_runtime().
*/
task_rq_unlock_wait(tsk);
__cleanup_signal(sig);
}
}
| DoS +Priv | 0 | static void __exit_signal(struct task_struct *tsk)
{
struct signal_struct *sig = tsk->signal;
struct sighand_struct *sighand;
BUG_ON(!sig);
BUG_ON(!atomic_read(&sig->count));
sighand = rcu_dereference(tsk->sighand);
spin_lock(&sighand->siglock);
posix_cpu_timers_exit(tsk);
if (atomic_dec_and_test(&sig->count))
posix_cpu_timers_exit_group(tsk);
else {
/*
* If there is any task waiting for the group exit
* then notify it:
*/
if (sig->group_exit_task && atomic_read(&sig->count) == sig->notify_count)
wake_up_process(sig->group_exit_task);
if (tsk == sig->curr_target)
sig->curr_target = next_thread(tsk);
/*
* Accumulate here the counters for all threads but the
* group leader as they die, so they can be added into
* the process-wide totals when those are taken.
* The group leader stays around as a zombie as long
* as there are other threads. When it gets reaped,
* the exit.c code will add its counts into these totals.
* We won't ever get here for the group leader, since it
* will have been the last reference on the signal_struct.
*/
sig->gtime = cputime_add(sig->gtime, task_gtime(tsk));
sig->min_flt += tsk->min_flt;
sig->maj_flt += tsk->maj_flt;
sig->nvcsw += tsk->nvcsw;
sig->nivcsw += tsk->nivcsw;
sig->inblock += task_io_get_inblock(tsk);
sig->oublock += task_io_get_oublock(tsk);
task_io_accounting_add(&sig->ioac, &tsk->ioac);
sig = NULL; /* Marker for below. */
}
__unhash_process(tsk);
/*
* Do this under ->siglock, we can race with another thread
* doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
*/
flush_sigqueue(&tsk->pending);
tsk->signal = NULL;
tsk->sighand = NULL;
spin_unlock(&sighand->siglock);
__cleanup_sighand(sighand);
clear_tsk_thread_flag(tsk,TIF_SIGPENDING);
if (sig) {
flush_sigqueue(&sig->shared_pending);
taskstats_tgid_free(sig);
/*
* Make sure ->signal can't go away under rq->lock,
* see account_group_exec_runtime().
*/
task_rq_unlock_wait(tsk);
__cleanup_signal(sig);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,661 | void __set_special_pids(struct pid *pid)
{
struct task_struct *curr = current->group_leader;
pid_t nr = pid_nr(pid);
if (task_session(curr) != pid) {
change_pid(curr, PIDTYPE_SID, pid);
set_task_session(curr, nr);
}
if (task_pgrp(curr) != pid) {
change_pid(curr, PIDTYPE_PGID, pid);
set_task_pgrp(curr, nr);
}
}
| DoS +Priv | 0 | void __set_special_pids(struct pid *pid)
{
struct task_struct *curr = current->group_leader;
pid_t nr = pid_nr(pid);
if (task_session(curr) != pid) {
change_pid(curr, PIDTYPE_SID, pid);
set_task_session(curr, nr);
}
if (task_pgrp(curr) != pid) {
change_pid(curr, PIDTYPE_PGID, pid);
set_task_pgrp(curr, nr);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,662 | static void __unhash_process(struct task_struct *p)
{
nr_threads--;
detach_pid(p, PIDTYPE_PID);
if (thread_group_leader(p)) {
detach_pid(p, PIDTYPE_PGID);
detach_pid(p, PIDTYPE_SID);
list_del_rcu(&p->tasks);
__get_cpu_var(process_counts)--;
}
list_del_rcu(&p->thread_group);
list_del_init(&p->sibling);
}
| DoS +Priv | 0 | static void __unhash_process(struct task_struct *p)
{
nr_threads--;
detach_pid(p, PIDTYPE_PID);
if (thread_group_leader(p)) {
detach_pid(p, PIDTYPE_PGID);
detach_pid(p, PIDTYPE_SID);
list_del_rcu(&p->tasks);
__get_cpu_var(process_counts)--;
}
list_del_rcu(&p->thread_group);
list_del_init(&p->sibling);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,663 | int allow_signal(int sig)
{
if (!valid_signal(sig) || sig < 1)
return -EINVAL;
spin_lock_irq(¤t->sighand->siglock);
sigdelset(¤t->blocked, sig);
if (!current->mm) {
/* Kernel threads handle their own signals.
Let the signal code know it'll be handled, so
that they don't get converted to SIGKILL or
just silently dropped */
current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
}
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
return 0;
}
| DoS +Priv | 0 | int allow_signal(int sig)
{
if (!valid_signal(sig) || sig < 1)
return -EINVAL;
spin_lock_irq(¤t->sighand->siglock);
sigdelset(¤t->blocked, sig);
if (!current->mm) {
/* Kernel threads handle their own signals.
Let the signal code know it'll be handled, so
that they don't get converted to SIGKILL or
just silently dropped */
current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
}
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
return 0;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,664 | static void check_stack_usage(void)
{
static DEFINE_SPINLOCK(low_water_lock);
static int lowest_to_date = THREAD_SIZE;
unsigned long *n = end_of_stack(current);
unsigned long free;
while (*n == 0)
n++;
free = (unsigned long)n - (unsigned long)end_of_stack(current);
if (free >= lowest_to_date)
return;
spin_lock(&low_water_lock);
if (free < lowest_to_date) {
printk(KERN_WARNING "%s used greatest stack depth: %lu bytes "
"left\n",
current->comm, free);
lowest_to_date = free;
}
spin_unlock(&low_water_lock);
}
| DoS +Priv | 0 | static void check_stack_usage(void)
{
static DEFINE_SPINLOCK(low_water_lock);
static int lowest_to_date = THREAD_SIZE;
unsigned long *n = end_of_stack(current);
unsigned long free;
while (*n == 0)
n++;
free = (unsigned long)n - (unsigned long)end_of_stack(current);
if (free >= lowest_to_date)
return;
spin_lock(&low_water_lock);
if (free < lowest_to_date) {
printk(KERN_WARNING "%s used greatest stack depth: %lu bytes "
"left\n",
current->comm, free);
lowest_to_date = free;
}
spin_unlock(&low_water_lock);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,665 | static void close_files(struct files_struct * files)
{
int i, j;
struct fdtable *fdt;
j = 0;
/*
* It is safe to dereference the fd table without RCU or
* ->file_lock because this is the last reference to the
* files structure.
*/
fdt = files_fdtable(files);
for (;;) {
unsigned long set;
i = j * __NFDBITS;
if (i >= fdt->max_fds)
break;
set = fdt->open_fds->fds_bits[j++];
while (set) {
if (set & 1) {
struct file * file = xchg(&fdt->fd[i], NULL);
if (file) {
filp_close(file, files);
cond_resched();
}
}
i++;
set >>= 1;
}
}
}
| DoS +Priv | 0 | static void close_files(struct files_struct * files)
{
int i, j;
struct fdtable *fdt;
j = 0;
/*
* It is safe to dereference the fd table without RCU or
* ->file_lock because this is the last reference to the
* files structure.
*/
fdt = files_fdtable(files);
for (;;) {
unsigned long set;
i = j * __NFDBITS;
if (i >= fdt->max_fds)
break;
set = fdt->open_fds->fds_bits[j++];
while (set) {
if (set & 1) {
struct file * file = xchg(&fdt->fd[i], NULL);
if (file) {
filp_close(file, files);
cond_resched();
}
}
i++;
set >>= 1;
}
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,666 | NORET_TYPE void complete_and_exit(struct completion *comp, long code)
{
if (comp)
complete(comp);
do_exit(code);
}
| DoS +Priv | 0 | NORET_TYPE void complete_and_exit(struct completion *comp, long code)
{
if (comp)
complete(comp);
do_exit(code);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,667 | static void delayed_put_task_struct(struct rcu_head *rhp)
{
struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
trace_sched_process_free(tsk);
put_task_struct(tsk);
}
| DoS +Priv | 0 | static void delayed_put_task_struct(struct rcu_head *rhp)
{
struct task_struct *tsk = container_of(rhp, struct task_struct, rcu);
trace_sched_process_free(tsk);
put_task_struct(tsk);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,668 | int disallow_signal(int sig)
{
if (!valid_signal(sig) || sig < 1)
return -EINVAL;
spin_lock_irq(¤t->sighand->siglock);
current->sighand->action[(sig)-1].sa.sa_handler = SIG_IGN;
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
return 0;
}
| DoS +Priv | 0 | int disallow_signal(int sig)
{
if (!valid_signal(sig) || sig < 1)
return -EINVAL;
spin_lock_irq(¤t->sighand->siglock);
current->sighand->action[(sig)-1].sa.sa_handler = SIG_IGN;
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
return 0;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,669 | do_group_exit(int exit_code)
{
struct signal_struct *sig = current->signal;
BUG_ON(exit_code & 0x80); /* core dumps don't get here */
if (signal_group_exit(sig))
exit_code = sig->group_exit_code;
else if (!thread_group_empty(current)) {
struct sighand_struct *const sighand = current->sighand;
spin_lock_irq(&sighand->siglock);
if (signal_group_exit(sig))
/* Another thread got here before we took the lock. */
exit_code = sig->group_exit_code;
else {
sig->group_exit_code = exit_code;
sig->flags = SIGNAL_GROUP_EXIT;
zap_other_threads(current);
}
spin_unlock_irq(&sighand->siglock);
}
do_exit(exit_code);
/* NOTREACHED */
}
| DoS +Priv | 0 | do_group_exit(int exit_code)
{
struct signal_struct *sig = current->signal;
BUG_ON(exit_code & 0x80); /* core dumps don't get here */
if (signal_group_exit(sig))
exit_code = sig->group_exit_code;
else if (!thread_group_empty(current)) {
struct sighand_struct *const sighand = current->sighand;
spin_lock_irq(&sighand->siglock);
if (signal_group_exit(sig))
/* Another thread got here before we took the lock. */
exit_code = sig->group_exit_code;
else {
sig->group_exit_code = exit_code;
sig->flags = SIGNAL_GROUP_EXIT;
zap_other_threads(current);
}
spin_unlock_irq(&sighand->siglock);
}
do_exit(exit_code);
/* NOTREACHED */
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,670 | static int do_wait_thread(struct task_struct *tsk, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop, int __user *stat_addr,
struct rusage __user *ru)
{
struct task_struct *p;
list_for_each_entry(p, &tsk->children, sibling) {
/*
* Do not consider detached threads.
*/
if (!task_detached(p)) {
int ret = wait_consider_task(tsk, 0, p, notask_error,
type, pid, options,
infop, stat_addr, ru);
if (ret)
return ret;
}
}
return 0;
}
| DoS +Priv | 0 | static int do_wait_thread(struct task_struct *tsk, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop, int __user *stat_addr,
struct rusage __user *ru)
{
struct task_struct *p;
list_for_each_entry(p, &tsk->children, sibling) {
/*
* Do not consider detached threads.
*/
if (!task_detached(p)) {
int ret = wait_consider_task(tsk, 0, p, notask_error,
type, pid, options,
infop, stat_addr, ru);
if (ret)
return ret;
}
}
return 0;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,671 | static int eligible_child(enum pid_type type, struct pid *pid, int options,
struct task_struct *p)
{
int err;
if (type < PIDTYPE_MAX) {
if (task_pid_type(p, type) != pid)
return 0;
}
/* Wait for all children (clone and not) if __WALL is set;
* otherwise, wait for clone children *only* if __WCLONE is
* set; otherwise, wait for non-clone children *only*. (Note:
* A "clone" child here is one that reports to its parent
* using a signal other than SIGCHLD.) */
if (((p->exit_signal != SIGCHLD) ^ ((options & __WCLONE) != 0))
&& !(options & __WALL))
return 0;
err = security_task_wait(p);
if (err)
return err;
return 1;
}
| DoS +Priv | 0 | static int eligible_child(enum pid_type type, struct pid *pid, int options,
struct task_struct *p)
{
int err;
if (type < PIDTYPE_MAX) {
if (task_pid_type(p, type) != pid)
return 0;
}
/* Wait for all children (clone and not) if __WALL is set;
* otherwise, wait for clone children *only* if __WCLONE is
* set; otherwise, wait for non-clone children *only*. (Note:
* A "clone" child here is one that reports to its parent
* using a signal other than SIGCHLD.) */
if (((p->exit_signal != SIGCHLD) ^ ((options & __WCLONE) != 0))
&& !(options & __WALL))
return 0;
err = security_task_wait(p);
if (err)
return err;
return 1;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,672 | void exit_files(struct task_struct *tsk)
{
struct files_struct * files = tsk->files;
if (files) {
task_lock(tsk);
tsk->files = NULL;
task_unlock(tsk);
put_files_struct(files);
}
}
| DoS +Priv | 0 | void exit_files(struct task_struct *tsk)
{
struct files_struct * files = tsk->files;
if (files) {
task_lock(tsk);
tsk->files = NULL;
task_unlock(tsk);
put_files_struct(files);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,673 | void exit_fs(struct task_struct *tsk)
{
struct fs_struct * fs = tsk->fs;
if (fs) {
task_lock(tsk);
tsk->fs = NULL;
task_unlock(tsk);
put_fs_struct(fs);
}
}
| DoS +Priv | 0 | void exit_fs(struct task_struct *tsk)
{
struct fs_struct * fs = tsk->fs;
if (fs) {
task_lock(tsk);
tsk->fs = NULL;
task_unlock(tsk);
put_fs_struct(fs);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,674 | static void exit_mm(struct task_struct * tsk)
{
struct mm_struct *mm = tsk->mm;
struct core_state *core_state;
mm_release(tsk, mm);
if (!mm)
return;
/*
* Serialize with any possible pending coredump.
* We must hold mmap_sem around checking core_state
* and clearing tsk->mm. The core-inducing thread
* will increment ->nr_threads for each thread in the
* group with ->mm != NULL.
*/
down_read(&mm->mmap_sem);
core_state = mm->core_state;
if (core_state) {
struct core_thread self;
up_read(&mm->mmap_sem);
self.task = tsk;
self.next = xchg(&core_state->dumper.next, &self);
/*
* Implies mb(), the result of xchg() must be visible
* to core_state->dumper.
*/
if (atomic_dec_and_test(&core_state->nr_threads))
complete(&core_state->startup);
for (;;) {
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
if (!self.task) /* see coredump_finish() */
break;
schedule();
}
__set_task_state(tsk, TASK_RUNNING);
down_read(&mm->mmap_sem);
}
atomic_inc(&mm->mm_count);
BUG_ON(mm != tsk->active_mm);
/* more a memory barrier than a real lock */
task_lock(tsk);
tsk->mm = NULL;
up_read(&mm->mmap_sem);
enter_lazy_tlb(mm, current);
/* We don't want this task to be frozen prematurely */
clear_freeze_flag(tsk);
task_unlock(tsk);
mm_update_next_owner(mm);
mmput(mm);
}
| DoS +Priv | 0 | static void exit_mm(struct task_struct * tsk)
{
struct mm_struct *mm = tsk->mm;
struct core_state *core_state;
mm_release(tsk, mm);
if (!mm)
return;
/*
* Serialize with any possible pending coredump.
* We must hold mmap_sem around checking core_state
* and clearing tsk->mm. The core-inducing thread
* will increment ->nr_threads for each thread in the
* group with ->mm != NULL.
*/
down_read(&mm->mmap_sem);
core_state = mm->core_state;
if (core_state) {
struct core_thread self;
up_read(&mm->mmap_sem);
self.task = tsk;
self.next = xchg(&core_state->dumper.next, &self);
/*
* Implies mb(), the result of xchg() must be visible
* to core_state->dumper.
*/
if (atomic_dec_and_test(&core_state->nr_threads))
complete(&core_state->startup);
for (;;) {
set_task_state(tsk, TASK_UNINTERRUPTIBLE);
if (!self.task) /* see coredump_finish() */
break;
schedule();
}
__set_task_state(tsk, TASK_RUNNING);
down_read(&mm->mmap_sem);
}
atomic_inc(&mm->mm_count);
BUG_ON(mm != tsk->active_mm);
/* more a memory barrier than a real lock */
task_lock(tsk);
tsk->mm = NULL;
up_read(&mm->mmap_sem);
enter_lazy_tlb(mm, current);
/* We don't want this task to be frozen prematurely */
clear_freeze_flag(tsk);
task_unlock(tsk);
mm_update_next_owner(mm);
mmput(mm);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,675 | static void exit_notify(struct task_struct *tsk, int group_dead)
{
int signal;
void *cookie;
/*
* This does two things:
*
* A. Make init inherit all the child processes
* B. Check to see if any process groups have become orphaned
* as a result of our exiting, and if they have any stopped
* jobs, send them a SIGHUP and then a SIGCONT. (POSIX 3.2.2.2)
*/
forget_original_parent(tsk);
exit_task_namespaces(tsk);
write_lock_irq(&tasklist_lock);
if (group_dead)
kill_orphaned_pgrp(tsk->group_leader, NULL);
/* Let father know we died
*
* Thread signals are configurable, but you aren't going to use
* that to send signals to arbitary processes.
* That stops right now.
*
* If the parent exec id doesn't match the exec id we saved
* when we started then we know the parent has changed security
* domain.
*
* If our self_exec id doesn't match our parent_exec_id then
* we have changed execution domain as these two values started
* the same after a fork.
*/
if (tsk->exit_signal != SIGCHLD && !task_detached(tsk) &&
(tsk->parent_exec_id != tsk->real_parent->self_exec_id ||
tsk->self_exec_id != tsk->parent_exec_id) &&
!capable(CAP_KILL))
tsk->exit_signal = SIGCHLD;
signal = tracehook_notify_death(tsk, &cookie, group_dead);
if (signal >= 0)
signal = do_notify_parent(tsk, signal);
tsk->exit_state = signal == DEATH_REAP ? EXIT_DEAD : EXIT_ZOMBIE;
/* mt-exec, de_thread() is waiting for us */
if (thread_group_leader(tsk) &&
tsk->signal->group_exit_task &&
tsk->signal->notify_count < 0)
wake_up_process(tsk->signal->group_exit_task);
write_unlock_irq(&tasklist_lock);
tracehook_report_death(tsk, signal, cookie, group_dead);
/* If the process is dead, release it - nobody will wait for it */
if (signal == DEATH_REAP)
release_task(tsk);
}
| DoS +Priv | 0 | static void exit_notify(struct task_struct *tsk, int group_dead)
{
int signal;
void *cookie;
/*
* This does two things:
*
* A. Make init inherit all the child processes
* B. Check to see if any process groups have become orphaned
* as a result of our exiting, and if they have any stopped
* jobs, send them a SIGHUP and then a SIGCONT. (POSIX 3.2.2.2)
*/
forget_original_parent(tsk);
exit_task_namespaces(tsk);
write_lock_irq(&tasklist_lock);
if (group_dead)
kill_orphaned_pgrp(tsk->group_leader, NULL);
/* Let father know we died
*
* Thread signals are configurable, but you aren't going to use
* that to send signals to arbitary processes.
* That stops right now.
*
* If the parent exec id doesn't match the exec id we saved
* when we started then we know the parent has changed security
* domain.
*
* If our self_exec id doesn't match our parent_exec_id then
* we have changed execution domain as these two values started
* the same after a fork.
*/
if (tsk->exit_signal != SIGCHLD && !task_detached(tsk) &&
(tsk->parent_exec_id != tsk->real_parent->self_exec_id ||
tsk->self_exec_id != tsk->parent_exec_id) &&
!capable(CAP_KILL))
tsk->exit_signal = SIGCHLD;
signal = tracehook_notify_death(tsk, &cookie, group_dead);
if (signal >= 0)
signal = do_notify_parent(tsk, signal);
tsk->exit_state = signal == DEATH_REAP ? EXIT_DEAD : EXIT_ZOMBIE;
/* mt-exec, de_thread() is waiting for us */
if (thread_group_leader(tsk) &&
tsk->signal->group_exit_task &&
tsk->signal->notify_count < 0)
wake_up_process(tsk->signal->group_exit_task);
write_unlock_irq(&tasklist_lock);
tracehook_report_death(tsk, signal, cookie, group_dead);
/* If the process is dead, release it - nobody will wait for it */
if (signal == DEATH_REAP)
release_task(tsk);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,676 | struct files_struct *get_files_struct(struct task_struct *task)
{
struct files_struct *files;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
return files;
}
| DoS +Priv | 0 | struct files_struct *get_files_struct(struct task_struct *task)
{
struct files_struct *files;
task_lock(task);
files = task->files;
if (files)
atomic_inc(&files->count);
task_unlock(task);
return files;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,677 | static int has_stopped_jobs(struct pid *pgrp)
{
int retval = 0;
struct task_struct *p;
do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
if (!task_is_stopped(p))
continue;
retval = 1;
break;
} while_each_pid_task(pgrp, PIDTYPE_PGID, p);
return retval;
}
| DoS +Priv | 0 | static int has_stopped_jobs(struct pid *pgrp)
{
int retval = 0;
struct task_struct *p;
do_each_pid_task(pgrp, PIDTYPE_PGID, p) {
if (!task_is_stopped(p))
continue;
retval = 1;
break;
} while_each_pid_task(pgrp, PIDTYPE_PGID, p);
return retval;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,678 | int is_current_pgrp_orphaned(void)
{
int retval;
read_lock(&tasklist_lock);
retval = will_become_orphaned_pgrp(task_pgrp(current), NULL);
read_unlock(&tasklist_lock);
return retval;
}
| DoS +Priv | 0 | int is_current_pgrp_orphaned(void)
{
int retval;
read_lock(&tasklist_lock);
retval = will_become_orphaned_pgrp(task_pgrp(current), NULL);
read_unlock(&tasklist_lock);
return retval;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,679 | kill_orphaned_pgrp(struct task_struct *tsk, struct task_struct *parent)
{
struct pid *pgrp = task_pgrp(tsk);
struct task_struct *ignored_task = tsk;
if (!parent)
/* exit: our father is in a different pgrp than
* we are and we were the only connection outside.
*/
parent = tsk->real_parent;
else
/* reparent: our child is in a different pgrp than
* we are, and it was the only connection outside.
*/
ignored_task = NULL;
if (task_pgrp(parent) != pgrp &&
task_session(parent) == task_session(tsk) &&
will_become_orphaned_pgrp(pgrp, ignored_task) &&
has_stopped_jobs(pgrp)) {
__kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp);
__kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp);
}
}
| DoS +Priv | 0 | kill_orphaned_pgrp(struct task_struct *tsk, struct task_struct *parent)
{
struct pid *pgrp = task_pgrp(tsk);
struct task_struct *ignored_task = tsk;
if (!parent)
/* exit: our father is in a different pgrp than
* we are and we were the only connection outside.
*/
parent = tsk->real_parent;
else
/* reparent: our child is in a different pgrp than
* we are, and it was the only connection outside.
*/
ignored_task = NULL;
if (task_pgrp(parent) != pgrp &&
task_session(parent) == task_session(tsk) &&
will_become_orphaned_pgrp(pgrp, ignored_task) &&
has_stopped_jobs(pgrp)) {
__kill_pgrp_info(SIGHUP, SEND_SIG_PRIV, pgrp);
__kill_pgrp_info(SIGCONT, SEND_SIG_PRIV, pgrp);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,680 | mm_need_new_owner(struct mm_struct *mm, struct task_struct *p)
{
/*
* If there are other users of the mm and the owner (us) is exiting
* we need to find a new owner to take on the responsibility.
*/
if (atomic_read(&mm->mm_users) <= 1)
return 0;
if (mm->owner != p)
return 0;
return 1;
}
| DoS +Priv | 0 | mm_need_new_owner(struct mm_struct *mm, struct task_struct *p)
{
/*
* If there are other users of the mm and the owner (us) is exiting
* we need to find a new owner to take on the responsibility.
*/
if (atomic_read(&mm->mm_users) <= 1)
return 0;
if (mm->owner != p)
return 0;
return 1;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,681 | void mm_update_next_owner(struct mm_struct *mm)
{
struct task_struct *c, *g, *p = current;
retry:
if (!mm_need_new_owner(mm, p))
return;
read_lock(&tasklist_lock);
/*
* Search in the children
*/
list_for_each_entry(c, &p->children, sibling) {
if (c->mm == mm)
goto assign_new_owner;
}
/*
* Search in the siblings
*/
list_for_each_entry(c, &p->parent->children, sibling) {
if (c->mm == mm)
goto assign_new_owner;
}
/*
* Search through everything else. We should not get
* here often
*/
do_each_thread(g, c) {
if (c->mm == mm)
goto assign_new_owner;
} while_each_thread(g, c);
read_unlock(&tasklist_lock);
/*
* We found no owner yet mm_users > 1: this implies that we are
* most likely racing with swapoff (try_to_unuse()) or /proc or
* ptrace or page migration (get_task_mm()). Mark owner as NULL,
* so that subsystems can understand the callback and take action.
*/
down_write(&mm->mmap_sem);
cgroup_mm_owner_callbacks(mm->owner, NULL);
mm->owner = NULL;
up_write(&mm->mmap_sem);
return;
assign_new_owner:
BUG_ON(c == p);
get_task_struct(c);
read_unlock(&tasklist_lock);
down_write(&mm->mmap_sem);
/*
* The task_lock protects c->mm from changing.
* We always want mm->owner->mm == mm
*/
task_lock(c);
if (c->mm != mm) {
task_unlock(c);
up_write(&mm->mmap_sem);
put_task_struct(c);
goto retry;
}
cgroup_mm_owner_callbacks(mm->owner, c);
mm->owner = c;
task_unlock(c);
up_write(&mm->mmap_sem);
put_task_struct(c);
}
| DoS +Priv | 0 | void mm_update_next_owner(struct mm_struct *mm)
{
struct task_struct *c, *g, *p = current;
retry:
if (!mm_need_new_owner(mm, p))
return;
read_lock(&tasklist_lock);
/*
* Search in the children
*/
list_for_each_entry(c, &p->children, sibling) {
if (c->mm == mm)
goto assign_new_owner;
}
/*
* Search in the siblings
*/
list_for_each_entry(c, &p->parent->children, sibling) {
if (c->mm == mm)
goto assign_new_owner;
}
/*
* Search through everything else. We should not get
* here often
*/
do_each_thread(g, c) {
if (c->mm == mm)
goto assign_new_owner;
} while_each_thread(g, c);
read_unlock(&tasklist_lock);
/*
* We found no owner yet mm_users > 1: this implies that we are
* most likely racing with swapoff (try_to_unuse()) or /proc or
* ptrace or page migration (get_task_mm()). Mark owner as NULL,
* so that subsystems can understand the callback and take action.
*/
down_write(&mm->mmap_sem);
cgroup_mm_owner_callbacks(mm->owner, NULL);
mm->owner = NULL;
up_write(&mm->mmap_sem);
return;
assign_new_owner:
BUG_ON(c == p);
get_task_struct(c);
read_unlock(&tasklist_lock);
down_write(&mm->mmap_sem);
/*
* The task_lock protects c->mm from changing.
* We always want mm->owner->mm == mm
*/
task_lock(c);
if (c->mm != mm) {
task_unlock(c);
up_write(&mm->mmap_sem);
put_task_struct(c);
goto retry;
}
cgroup_mm_owner_callbacks(mm->owner, c);
mm->owner = c;
task_unlock(c);
up_write(&mm->mmap_sem);
put_task_struct(c);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,682 | static int ptrace_do_wait(struct task_struct *tsk, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop, int __user *stat_addr,
struct rusage __user *ru)
{
struct task_struct *p;
/*
* Traditionally we see ptrace'd stopped tasks regardless of options.
*/
options |= WUNTRACED;
list_for_each_entry(p, &tsk->ptraced, ptrace_entry) {
int ret = wait_consider_task(tsk, 1, p, notask_error,
type, pid, options,
infop, stat_addr, ru);
if (ret)
return ret;
}
return 0;
}
| DoS +Priv | 0 | static int ptrace_do_wait(struct task_struct *tsk, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop, int __user *stat_addr,
struct rusage __user *ru)
{
struct task_struct *p;
/*
* Traditionally we see ptrace'd stopped tasks regardless of options.
*/
options |= WUNTRACED;
list_for_each_entry(p, &tsk->ptraced, ptrace_entry) {
int ret = wait_consider_task(tsk, 1, p, notask_error,
type, pid, options,
infop, stat_addr, ru);
if (ret)
return ret;
}
return 0;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,683 | static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
{
struct task_struct *p, *n;
int ign = -1;
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
__ptrace_unlink(p);
if (p->exit_state != EXIT_ZOMBIE)
continue;
/*
* If it's a zombie, our attachedness prevented normal
* parent notification or self-reaping. Do notification
* now if it would have happened earlier. If it should
* reap itself, add it to the @dead list. We can't call
* release_task() here because we already hold tasklist_lock.
*
* If it's our own child, there is no notification to do.
* But if our normal children self-reap, then this child
* was prevented by ptrace and we must reap it now.
*/
if (!task_detached(p) && thread_group_empty(p)) {
if (!same_thread_group(p->real_parent, parent))
do_notify_parent(p, p->exit_signal);
else {
if (ign < 0)
ign = ignoring_children(parent);
if (ign)
p->exit_signal = -1;
}
}
if (task_detached(p)) {
/*
* Mark it as in the process of being reaped.
*/
p->exit_state = EXIT_DEAD;
list_add(&p->ptrace_entry, dead);
}
}
}
| DoS +Priv | 0 | static void ptrace_exit(struct task_struct *parent, struct list_head *dead)
{
struct task_struct *p, *n;
int ign = -1;
list_for_each_entry_safe(p, n, &parent->ptraced, ptrace_entry) {
__ptrace_unlink(p);
if (p->exit_state != EXIT_ZOMBIE)
continue;
/*
* If it's a zombie, our attachedness prevented normal
* parent notification or self-reaping. Do notification
* now if it would have happened earlier. If it should
* reap itself, add it to the @dead list. We can't call
* release_task() here because we already hold tasklist_lock.
*
* If it's our own child, there is no notification to do.
* But if our normal children self-reap, then this child
* was prevented by ptrace and we must reap it now.
*/
if (!task_detached(p) && thread_group_empty(p)) {
if (!same_thread_group(p->real_parent, parent))
do_notify_parent(p, p->exit_signal);
else {
if (ign < 0)
ign = ignoring_children(parent);
if (ign)
p->exit_signal = -1;
}
}
if (task_detached(p)) {
/*
* Mark it as in the process of being reaped.
*/
p->exit_state = EXIT_DEAD;
list_add(&p->ptrace_entry, dead);
}
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,684 | static void ptrace_exit_finish(struct task_struct *parent,
struct list_head *dead)
{
struct task_struct *p, *n;
BUG_ON(!list_empty(&parent->ptraced));
list_for_each_entry_safe(p, n, dead, ptrace_entry) {
list_del_init(&p->ptrace_entry);
release_task(p);
}
}
| DoS +Priv | 0 | static void ptrace_exit_finish(struct task_struct *parent,
struct list_head *dead)
{
struct task_struct *p, *n;
BUG_ON(!list_empty(&parent->ptraced));
list_for_each_entry_safe(p, n, dead, ptrace_entry) {
list_del_init(&p->ptrace_entry);
release_task(p);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,685 | void put_files_struct(struct files_struct *files)
{
struct fdtable *fdt;
if (atomic_dec_and_test(&files->count)) {
close_files(files);
/*
* Free the fd and fdset arrays if we expanded them.
* If the fdtable was embedded, pass files for freeing
* at the end of the RCU grace period. Otherwise,
* you can free files immediately.
*/
fdt = files_fdtable(files);
if (fdt != &files->fdtab)
kmem_cache_free(files_cachep, files);
free_fdtable(fdt);
}
}
| DoS +Priv | 0 | void put_files_struct(struct files_struct *files)
{
struct fdtable *fdt;
if (atomic_dec_and_test(&files->count)) {
close_files(files);
/*
* Free the fd and fdset arrays if we expanded them.
* If the fdtable was embedded, pass files for freeing
* at the end of the RCU grace period. Otherwise,
* you can free files immediately.
*/
fdt = files_fdtable(files);
if (fdt != &files->fdtab)
kmem_cache_free(files_cachep, files);
free_fdtable(fdt);
}
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,686 | void release_task(struct task_struct * p)
{
struct task_struct *leader;
int zap_leader;
repeat:
tracehook_prepare_release_task(p);
atomic_dec(&p->user->processes);
proc_flush_task(p);
write_lock_irq(&tasklist_lock);
tracehook_finish_release_task(p);
__exit_signal(p);
/*
* If we are the last non-leader member of the thread
* group, and the leader is zombie, then notify the
* group leader's parent process. (if it wants notification.)
*/
zap_leader = 0;
leader = p->group_leader;
if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) {
BUG_ON(task_detached(leader));
do_notify_parent(leader, leader->exit_signal);
/*
* If we were the last child thread and the leader has
* exited already, and the leader's parent ignores SIGCHLD,
* then we are the one who should release the leader.
*
* do_notify_parent() will have marked it self-reaping in
* that case.
*/
zap_leader = task_detached(leader);
/*
* This maintains the invariant that release_task()
* only runs on a task in EXIT_DEAD, just for sanity.
*/
if (zap_leader)
leader->exit_state = EXIT_DEAD;
}
write_unlock_irq(&tasklist_lock);
release_thread(p);
call_rcu(&p->rcu, delayed_put_task_struct);
p = leader;
if (unlikely(zap_leader))
goto repeat;
}
| DoS +Priv | 0 | void release_task(struct task_struct * p)
{
struct task_struct *leader;
int zap_leader;
repeat:
tracehook_prepare_release_task(p);
atomic_dec(&p->user->processes);
proc_flush_task(p);
write_lock_irq(&tasklist_lock);
tracehook_finish_release_task(p);
__exit_signal(p);
/*
* If we are the last non-leader member of the thread
* group, and the leader is zombie, then notify the
* group leader's parent process. (if it wants notification.)
*/
zap_leader = 0;
leader = p->group_leader;
if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) {
BUG_ON(task_detached(leader));
do_notify_parent(leader, leader->exit_signal);
/*
* If we were the last child thread and the leader has
* exited already, and the leader's parent ignores SIGCHLD,
* then we are the one who should release the leader.
*
* do_notify_parent() will have marked it self-reaping in
* that case.
*/
zap_leader = task_detached(leader);
/*
* This maintains the invariant that release_task()
* only runs on a task in EXIT_DEAD, just for sanity.
*/
if (zap_leader)
leader->exit_state = EXIT_DEAD;
}
write_unlock_irq(&tasklist_lock);
release_thread(p);
call_rcu(&p->rcu, delayed_put_task_struct);
p = leader;
if (unlikely(zap_leader))
goto repeat;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,687 | static void reparent_thread(struct task_struct *p, struct task_struct *father)
{
if (p->pdeath_signal)
/* We already hold the tasklist_lock here. */
group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
list_move_tail(&p->sibling, &p->real_parent->children);
/* If this is a threaded reparent there is no need to
* notify anyone anything has happened.
*/
if (same_thread_group(p->real_parent, father))
return;
/* We don't want people slaying init. */
if (!task_detached(p))
p->exit_signal = SIGCHLD;
/* If we'd notified the old parent about this child's death,
* also notify the new parent.
*/
if (!ptrace_reparented(p) &&
p->exit_state == EXIT_ZOMBIE &&
!task_detached(p) && thread_group_empty(p))
do_notify_parent(p, p->exit_signal);
kill_orphaned_pgrp(p, father);
}
| DoS +Priv | 0 | static void reparent_thread(struct task_struct *p, struct task_struct *father)
{
if (p->pdeath_signal)
/* We already hold the tasklist_lock here. */
group_send_sig_info(p->pdeath_signal, SEND_SIG_NOINFO, p);
list_move_tail(&p->sibling, &p->real_parent->children);
/* If this is a threaded reparent there is no need to
* notify anyone anything has happened.
*/
if (same_thread_group(p->real_parent, father))
return;
/* We don't want people slaying init. */
if (!task_detached(p))
p->exit_signal = SIGCHLD;
/* If we'd notified the old parent about this child's death,
* also notify the new parent.
*/
if (!ptrace_reparented(p) &&
p->exit_state == EXIT_ZOMBIE &&
!task_detached(p) && thread_group_empty(p))
do_notify_parent(p, p->exit_signal);
kill_orphaned_pgrp(p, father);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,688 | void reset_files_struct(struct files_struct *files)
{
struct task_struct *tsk = current;
struct files_struct *old;
old = tsk->files;
task_lock(tsk);
tsk->files = files;
task_unlock(tsk);
put_files_struct(old);
}
| DoS +Priv | 0 | void reset_files_struct(struct files_struct *files)
{
struct task_struct *tsk = current;
struct files_struct *old;
old = tsk->files;
task_lock(tsk);
tsk->files = files;
task_unlock(tsk);
put_files_struct(old);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,689 | struct pid *session_of_pgrp(struct pid *pgrp)
{
struct task_struct *p;
struct pid *sid = NULL;
p = pid_task(pgrp, PIDTYPE_PGID);
if (p == NULL)
p = pid_task(pgrp, PIDTYPE_PID);
if (p != NULL)
sid = task_session(p);
return sid;
}
| DoS +Priv | 0 | struct pid *session_of_pgrp(struct pid *pgrp)
{
struct task_struct *p;
struct pid *sid = NULL;
p = pid_task(pgrp, PIDTYPE_PGID);
if (p == NULL)
p = pid_task(pgrp, PIDTYPE_PID);
if (p != NULL)
sid = task_session(p);
return sid;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,690 | asmlinkage long sys_exit(int error_code)
{
do_exit((error_code&0xff)<<8);
}
| DoS +Priv | 0 | asmlinkage long sys_exit(int error_code)
{
do_exit((error_code&0xff)<<8);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,691 | asmlinkage void sys_exit_group(int error_code)
{
do_group_exit((error_code & 0xff) << 8);
}
| DoS +Priv | 0 | asmlinkage void sys_exit_group(int error_code)
{
do_group_exit((error_code & 0xff) << 8);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,692 | asmlinkage long sys_waitid(int which, pid_t upid,
struct siginfo __user *infop, int options,
struct rusage __user *ru)
{
struct pid *pid = NULL;
enum pid_type type;
long ret;
if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED))
return -EINVAL;
if (!(options & (WEXITED|WSTOPPED|WCONTINUED)))
return -EINVAL;
switch (which) {
case P_ALL:
type = PIDTYPE_MAX;
break;
case P_PID:
type = PIDTYPE_PID;
if (upid <= 0)
return -EINVAL;
break;
case P_PGID:
type = PIDTYPE_PGID;
if (upid <= 0)
return -EINVAL;
break;
default:
return -EINVAL;
}
if (type < PIDTYPE_MAX)
pid = find_get_pid(upid);
ret = do_wait(type, pid, options, infop, NULL, ru);
put_pid(pid);
/* avoid REGPARM breakage on x86: */
asmlinkage_protect(5, ret, which, upid, infop, options, ru);
return ret;
}
| DoS +Priv | 0 | asmlinkage long sys_waitid(int which, pid_t upid,
struct siginfo __user *infop, int options,
struct rusage __user *ru)
{
struct pid *pid = NULL;
enum pid_type type;
long ret;
if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED))
return -EINVAL;
if (!(options & (WEXITED|WSTOPPED|WCONTINUED)))
return -EINVAL;
switch (which) {
case P_ALL:
type = PIDTYPE_MAX;
break;
case P_PID:
type = PIDTYPE_PID;
if (upid <= 0)
return -EINVAL;
break;
case P_PGID:
type = PIDTYPE_PGID;
if (upid <= 0)
return -EINVAL;
break;
default:
return -EINVAL;
}
if (type < PIDTYPE_MAX)
pid = find_get_pid(upid);
ret = do_wait(type, pid, options, infop, NULL, ru);
put_pid(pid);
/* avoid REGPARM breakage on x86: */
asmlinkage_protect(5, ret, which, upid, infop, options, ru);
return ret;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,693 | asmlinkage long sys_waitpid(pid_t pid, int __user *stat_addr, int options)
{
return sys_wait4(pid, stat_addr, options, NULL);
}
| DoS +Priv | 0 | asmlinkage long sys_waitpid(pid_t pid, int __user *stat_addr, int options)
{
return sys_wait4(pid, stat_addr, options, NULL);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,694 | static inline int task_detached(struct task_struct *p)
{
return p->exit_signal == -1;
}
| DoS +Priv | 0 | static inline int task_detached(struct task_struct *p)
{
return p->exit_signal == -1;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,695 | static struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
{
struct pid *pid = NULL;
if (type == PIDTYPE_PID)
pid = task->pids[type].pid;
else if (type < PIDTYPE_MAX)
pid = task->group_leader->pids[type].pid;
return pid;
}
| DoS +Priv | 0 | static struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
{
struct pid *pid = NULL;
if (type == PIDTYPE_PID)
pid = task->pids[type].pid;
else if (type < PIDTYPE_MAX)
pid = task->group_leader->pids[type].pid;
return pid;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,696 | static int wait_consider_task(struct task_struct *parent, int ptrace,
struct task_struct *p, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int ret = eligible_child(type, pid, options, p);
if (!ret)
return ret;
if (unlikely(ret < 0)) {
/*
* If we have not yet seen any eligible child,
* then let this error code replace -ECHILD.
* A permission error will give the user a clue
* to look for security policy problems, rather
* than for mysterious wait bugs.
*/
if (*notask_error)
*notask_error = ret;
}
if (likely(!ptrace) && unlikely(p->ptrace)) {
/*
* This child is hidden by ptrace.
* We aren't allowed to see it now, but eventually we will.
*/
*notask_error = 0;
return 0;
}
if (p->exit_state == EXIT_DEAD)
return 0;
/*
* We don't reap group leaders with subthreads.
*/
if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p))
return wait_task_zombie(p, options, infop, stat_addr, ru);
/*
* It's stopped or running now, so it might
* later continue, exit, or stop again.
*/
*notask_error = 0;
if (task_is_stopped_or_traced(p))
return wait_task_stopped(ptrace, p, options,
infop, stat_addr, ru);
return wait_task_continued(p, options, infop, stat_addr, ru);
}
| DoS +Priv | 0 | static int wait_consider_task(struct task_struct *parent, int ptrace,
struct task_struct *p, int *notask_error,
enum pid_type type, struct pid *pid, int options,
struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int ret = eligible_child(type, pid, options, p);
if (!ret)
return ret;
if (unlikely(ret < 0)) {
/*
* If we have not yet seen any eligible child,
* then let this error code replace -ECHILD.
* A permission error will give the user a clue
* to look for security policy problems, rather
* than for mysterious wait bugs.
*/
if (*notask_error)
*notask_error = ret;
}
if (likely(!ptrace) && unlikely(p->ptrace)) {
/*
* This child is hidden by ptrace.
* We aren't allowed to see it now, but eventually we will.
*/
*notask_error = 0;
return 0;
}
if (p->exit_state == EXIT_DEAD)
return 0;
/*
* We don't reap group leaders with subthreads.
*/
if (p->exit_state == EXIT_ZOMBIE && !delay_group_leader(p))
return wait_task_zombie(p, options, infop, stat_addr, ru);
/*
* It's stopped or running now, so it might
* later continue, exit, or stop again.
*/
*notask_error = 0;
if (task_is_stopped_or_traced(p))
return wait_task_stopped(ptrace, p, options,
infop, stat_addr, ru);
return wait_task_continued(p, options, infop, stat_addr, ru);
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,697 | static int wait_noreap_copyout(struct task_struct *p, pid_t pid, uid_t uid,
int why, int status,
struct siginfo __user *infop,
struct rusage __user *rusagep)
{
int retval = rusagep ? getrusage(p, RUSAGE_BOTH, rusagep) : 0;
put_task_struct(p);
if (!retval)
retval = put_user(SIGCHLD, &infop->si_signo);
if (!retval)
retval = put_user(0, &infop->si_errno);
if (!retval)
retval = put_user((short)why, &infop->si_code);
if (!retval)
retval = put_user(pid, &infop->si_pid);
if (!retval)
retval = put_user(uid, &infop->si_uid);
if (!retval)
retval = put_user(status, &infop->si_status);
if (!retval)
retval = pid;
return retval;
}
| DoS +Priv | 0 | static int wait_noreap_copyout(struct task_struct *p, pid_t pid, uid_t uid,
int why, int status,
struct siginfo __user *infop,
struct rusage __user *rusagep)
{
int retval = rusagep ? getrusage(p, RUSAGE_BOTH, rusagep) : 0;
put_task_struct(p);
if (!retval)
retval = put_user(SIGCHLD, &infop->si_signo);
if (!retval)
retval = put_user(0, &infop->si_errno);
if (!retval)
retval = put_user((short)why, &infop->si_code);
if (!retval)
retval = put_user(pid, &infop->si_pid);
if (!retval)
retval = put_user(uid, &infop->si_uid);
if (!retval)
retval = put_user(status, &infop->si_status);
if (!retval)
retval = pid;
return retval;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,698 | static int wait_task_continued(struct task_struct *p, int options,
struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int retval;
pid_t pid;
uid_t uid;
if (!unlikely(options & WCONTINUED))
return 0;
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
return 0;
spin_lock_irq(&p->sighand->siglock);
/* Re-check with the lock held. */
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED)) {
spin_unlock_irq(&p->sighand->siglock);
return 0;
}
if (!unlikely(options & WNOWAIT))
p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
spin_unlock_irq(&p->sighand->siglock);
pid = task_pid_vnr(p);
uid = p->uid;
get_task_struct(p);
read_unlock(&tasklist_lock);
if (!infop) {
retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
put_task_struct(p);
if (!retval && stat_addr)
retval = put_user(0xffff, stat_addr);
if (!retval)
retval = pid;
} else {
retval = wait_noreap_copyout(p, pid, uid,
CLD_CONTINUED, SIGCONT,
infop, ru);
BUG_ON(retval == 0);
}
return retval;
}
| DoS +Priv | 0 | static int wait_task_continued(struct task_struct *p, int options,
struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int retval;
pid_t pid;
uid_t uid;
if (!unlikely(options & WCONTINUED))
return 0;
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
return 0;
spin_lock_irq(&p->sighand->siglock);
/* Re-check with the lock held. */
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED)) {
spin_unlock_irq(&p->sighand->siglock);
return 0;
}
if (!unlikely(options & WNOWAIT))
p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
spin_unlock_irq(&p->sighand->siglock);
pid = task_pid_vnr(p);
uid = p->uid;
get_task_struct(p);
read_unlock(&tasklist_lock);
if (!infop) {
retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
put_task_struct(p);
if (!retval && stat_addr)
retval = put_user(0xffff, stat_addr);
if (!retval)
retval = pid;
} else {
retval = wait_noreap_copyout(p, pid, uid,
CLD_CONTINUED, SIGCONT,
infop, ru);
BUG_ON(retval == 0);
}
return retval;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
17,699 | static int wait_task_stopped(int ptrace, struct task_struct *p,
int options, struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int retval, exit_code, why;
uid_t uid = 0; /* unneeded, required by compiler */
pid_t pid;
if (!(options & WUNTRACED))
return 0;
exit_code = 0;
spin_lock_irq(&p->sighand->siglock);
if (unlikely(!task_is_stopped_or_traced(p)))
goto unlock_sig;
if (!ptrace && p->signal->group_stop_count > 0)
/*
* A group stop is in progress and this is the group leader.
* We won't report until all threads have stopped.
*/
goto unlock_sig;
exit_code = p->exit_code;
if (!exit_code)
goto unlock_sig;
if (!unlikely(options & WNOWAIT))
p->exit_code = 0;
uid = p->uid;
unlock_sig:
spin_unlock_irq(&p->sighand->siglock);
if (!exit_code)
return 0;
/*
* Now we are pretty sure this task is interesting.
* Make sure it doesn't get reaped out from under us while we
* give up the lock and then examine it below. We don't want to
* keep holding onto the tasklist_lock while we call getrusage and
* possibly take page faults for user memory.
*/
get_task_struct(p);
pid = task_pid_vnr(p);
why = ptrace ? CLD_TRAPPED : CLD_STOPPED;
read_unlock(&tasklist_lock);
if (unlikely(options & WNOWAIT))
return wait_noreap_copyout(p, pid, uid,
why, exit_code,
infop, ru);
retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
if (!retval && stat_addr)
retval = put_user((exit_code << 8) | 0x7f, stat_addr);
if (!retval && infop)
retval = put_user(SIGCHLD, &infop->si_signo);
if (!retval && infop)
retval = put_user(0, &infop->si_errno);
if (!retval && infop)
retval = put_user((short)why, &infop->si_code);
if (!retval && infop)
retval = put_user(exit_code, &infop->si_status);
if (!retval && infop)
retval = put_user(pid, &infop->si_pid);
if (!retval && infop)
retval = put_user(uid, &infop->si_uid);
if (!retval)
retval = pid;
put_task_struct(p);
BUG_ON(!retval);
return retval;
}
| DoS +Priv | 0 | static int wait_task_stopped(int ptrace, struct task_struct *p,
int options, struct siginfo __user *infop,
int __user *stat_addr, struct rusage __user *ru)
{
int retval, exit_code, why;
uid_t uid = 0; /* unneeded, required by compiler */
pid_t pid;
if (!(options & WUNTRACED))
return 0;
exit_code = 0;
spin_lock_irq(&p->sighand->siglock);
if (unlikely(!task_is_stopped_or_traced(p)))
goto unlock_sig;
if (!ptrace && p->signal->group_stop_count > 0)
/*
* A group stop is in progress and this is the group leader.
* We won't report until all threads have stopped.
*/
goto unlock_sig;
exit_code = p->exit_code;
if (!exit_code)
goto unlock_sig;
if (!unlikely(options & WNOWAIT))
p->exit_code = 0;
uid = p->uid;
unlock_sig:
spin_unlock_irq(&p->sighand->siglock);
if (!exit_code)
return 0;
/*
* Now we are pretty sure this task is interesting.
* Make sure it doesn't get reaped out from under us while we
* give up the lock and then examine it below. We don't want to
* keep holding onto the tasklist_lock while we call getrusage and
* possibly take page faults for user memory.
*/
get_task_struct(p);
pid = task_pid_vnr(p);
why = ptrace ? CLD_TRAPPED : CLD_STOPPED;
read_unlock(&tasklist_lock);
if (unlikely(options & WNOWAIT))
return wait_noreap_copyout(p, pid, uid,
why, exit_code,
infop, ru);
retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
if (!retval && stat_addr)
retval = put_user((exit_code << 8) | 0x7f, stat_addr);
if (!retval && infop)
retval = put_user(SIGCHLD, &infop->si_signo);
if (!retval && infop)
retval = put_user(0, &infop->si_errno);
if (!retval && infop)
retval = put_user((short)why, &infop->si_code);
if (!retval && infop)
retval = put_user(exit_code, &infop->si_status);
if (!retval && infop)
retval = put_user(pid, &infop->si_pid);
if (!retval && infop)
retval = put_user(uid, &infop->si_uid);
if (!retval)
retval = pid;
put_task_struct(p);
BUG_ON(!retval);
return retval;
}
| @@ -40,7 +40,6 @@
#include <linux/cn_proc.h>
#include <linux/mutex.h>
#include <linux/futex.h>
-#include <linux/compat.h>
#include <linux/pipe_fs_i.h>
#include <linux/audit.h> /* for audit_free() */
#include <linux/resource.h>
@@ -1059,14 +1058,6 @@ NORET_TYPE void do_exit(long code)
exit_itimers(tsk->signal);
}
acct_collect(code, group_dead);
-#ifdef CONFIG_FUTEX
- if (unlikely(tsk->robust_list))
- exit_robust_list(tsk);
-#ifdef CONFIG_COMPAT
- if (unlikely(tsk->compat_robust_list))
- compat_exit_robust_list(tsk);
-#endif
-#endif
if (group_dead)
tty_audit_exit();
if (unlikely(tsk->audit_context)) | CWE-264 | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.