mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2024-10-26 12:25:09 +03:00
Fix a race in xmlNewInputStream
For https://bugzilla.gnome.org/show_bug.cgi?id=643148 Reported by Bill Clarke <llib@computer.org>, it used a global variable as a counter for the input id and this was not thread safe. To avoid the race without adding unneeded locking in the parser path, move the id to the parser context instead.
This commit is contained in:
parent
9313ae8517
commit
0d51cfebc9
@ -308,6 +308,8 @@ struct _xmlParserCtxt {
|
||||
int nodeInfoNr; /* Depth of the parsing stack */
|
||||
int nodeInfoMax; /* Max depth of the parsing stack */
|
||||
xmlParserNodeInfo *nodeInfoTab; /* array of nodeInfos */
|
||||
|
||||
int input_id; /* we need to label inputs */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1372,13 +1372,13 @@ xmlFreeInputStream(xmlParserInputPtr input) {
|
||||
* xmlNewInputStream:
|
||||
* @ctxt: an XML parser context
|
||||
*
|
||||
* Create a new input stream structure
|
||||
* Create a new input stream structure.
|
||||
*
|
||||
* Returns the new input stream or NULL
|
||||
*/
|
||||
xmlParserInputPtr
|
||||
xmlNewInputStream(xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr input;
|
||||
static int id = 0;
|
||||
|
||||
input = (xmlParserInputPtr) xmlMalloc(sizeof(xmlParserInput));
|
||||
if (input == NULL) {
|
||||
@ -1389,11 +1389,15 @@ xmlNewInputStream(xmlParserCtxtPtr ctxt) {
|
||||
input->line = 1;
|
||||
input->col = 1;
|
||||
input->standalone = -1;
|
||||
|
||||
/*
|
||||
* we don't care about thread reentrancy unicity for a single
|
||||
* parser context (and hence thread) is sufficient.
|
||||
* If the context is NULL the id cannot be initialized, but that
|
||||
* should not happen while parsing which is the situation where
|
||||
* the id is actually needed.
|
||||
*/
|
||||
input->id = id++;
|
||||
if (ctxt != NULL)
|
||||
input->id = ctxt->input_id++;
|
||||
|
||||
return(input);
|
||||
}
|
||||
|
||||
@ -1757,6 +1761,7 @@ xmlInitParserCtxt(xmlParserCtxtPtr ctxt)
|
||||
ctxt->charset = XML_CHAR_ENCODING_UTF8;
|
||||
ctxt->catalogs = NULL;
|
||||
ctxt->nbentities = 0;
|
||||
ctxt->input_id = 1;
|
||||
xmlInitNodeInfoSeq(&ctxt->node_seq);
|
||||
return(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user