[Expat-bugs] Problem with current expat in CVS and XML_ParserCreate_MM

Tim Crook tim.crook@adobe.com
Tue, 27 Aug 2002 16:11:15 -0400


Hi Karl and Fred.

I see problems in XML_ParserCreate_MM when parserInit is called before
poolInit initializes tempPool. poolCopyString is called using the
uninitialized variable tempPool, which causes unpredictable results, in my
case, an access violation. Shouldn't poolInit be called before parserInit?
Here is an updated version of XML_ParserCreate_MM, which calls poolInit
first.

XML_Parser
XML_ParserCreate_MM(const XML_Char *encodingName,
                    const XML_Memory_Handling_Suite *memsuite,
                    const XML_Char *nameSep) {
  XML_Parser parser;
  static const XML_Char implicitContext[] = {
    'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/',
    'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
    'X', 'M', 'L', '/', '1', '9', '9', '8', '/',
    'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\0'
  };


  if (memsuite) {
    XML_Memory_Handling_Suite *mtemp;
    parser = memsuite->malloc_fcn(sizeof(struct XML_ParserStruct));
    if (parser != NULL) {
      mtemp = &(parser->m_mem);
      mtemp->malloc_fcn = memsuite->malloc_fcn;
      mtemp->realloc_fcn = memsuite->realloc_fcn;
      mtemp->free_fcn = memsuite->free_fcn;
    }
  }
  else {
    XML_Memory_Handling_Suite *mtemp;
    parser = malloc(sizeof(struct XML_ParserStruct));
    if (parser != NULL) {
      mtemp = &(parser->m_mem);
      mtemp->malloc_fcn = malloc;
      mtemp->realloc_fcn = realloc;
      mtemp->free_fcn = free;
    }
  }

  if (!parser)
    return parser;

  buffer = NULL;
  bufferLim = NULL;

  attsSize = INIT_ATTS_SIZE;
  atts = MALLOC(attsSize * sizeof(ATTRIBUTE));
  if (atts == NULL) {
    FREE(parser);
    return NULL;
  }
  dataBuf = MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
  if (dataBuf == NULL) {
    FREE(atts);
    FREE(parser);
    return NULL;
  }
  dataBufEnd = dataBuf + INIT_DATA_BUF_SIZE;

  freeBindingList = NULL;
  freeTagList = NULL;

  groupSize = 0;
  groupConnector = NULL;

  unknownEncodingHandler = NULL;
  unknownEncodingHandlerData = NULL;

  namespaceSeparator = '!';
  ns = XML_FALSE;
  ns_triplets = XML_FALSE;

  poolInit(&tempPool, &(parser->m_mem));
  poolInit(&temp2Pool, &(parser->m_mem));
  parserInit(parser, encodingName);
  dtdInit(&dtd, parser);

  if (!atts || !dataBuf || (encodingName && !protocolEncodingName)) {
    XML_ParserFree(parser);
    return NULL;
  }

  if (nameSep) {
    ns = XML_TRUE;
    internalEncoding = XmlGetInternalEncodingNS();
    namespaceSeparator = *nameSep;

    if (!setContext(parser, implicitContext)) {
      XML_ParserFree(parser);
      return NULL;
    }
  }
  else {
    internalEncoding = XmlGetInternalEncoding();
  }

  return parser;
}

_________________________________________
Tim Crook
Computer Scientist

Adobe Systems Canada Inc.
> 785 Carling Avenue
> Ottawa, Ontario
> Canada  K1S 5H4
> 
Phone: +1 613.751.4800 Ext 5734
Fax: +1 613.594.8886
E-mail: tim.crook@adobe.com