View | Details | Raw Unified | Return to bug 755377
Collapse All | Expand All

(-)lib/xmlparse.c (-47 / +116 lines)
Lines 5-10 Link Here
5
#include <stddef.h>
5
#include <stddef.h>
6
#include <string.h>                     /* memset(), memcpy() */
6
#include <string.h>                     /* memset(), memcpy() */
7
#include <assert.h>
7
#include <assert.h>
8
#include <limits.h>                     /* UINT_MAX */
9
#include <time.h>                       /* time() */
8
10
9
#define XML_BUILDING_EXPAT 1
11
#define XML_BUILDING_EXPAT 1
10
12
Lines 391-402 static void dtdReset(DTD *p, const XML_M Link Here
391
static void
393
static void
392
dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);
394
dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms);
393
static int
395
static int
394
dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms);
396
dtdCopy(XML_Parser oldParser,
397
        DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms);
395
static int
398
static int
396
copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *);
399
copyEntityTable(XML_Parser oldParser,
397
400
                HASH_TABLE *, STRING_POOL *, const HASH_TABLE *);
398
static NAMED *
401
static NAMED *
399
lookup(HASH_TABLE *table, KEY name, size_t createSize);
402
lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize);
400
static void FASTCALL
403
static void FASTCALL
401
hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms);
404
hashTableInit(HASH_TABLE *, const XML_Memory_Handling_Suite *ms);
402
static void FASTCALL hashTableClear(HASH_TABLE *);
405
static void FASTCALL hashTableClear(HASH_TABLE *);
Lines 429-439 static ELEMENT_TYPE * Link Here
429
getElementType(XML_Parser parser, const ENCODING *enc,
432
getElementType(XML_Parser parser, const ENCODING *enc,
430
               const char *ptr, const char *end);
433
               const char *ptr, const char *end);
431
434
435
static unsigned long generate_hash_secret_salt(void);
436
static XML_Bool startParsing(XML_Parser parser);
437
432
static XML_Parser
438
static XML_Parser
433
parserCreate(const XML_Char *encodingName,
439
parserCreate(const XML_Char *encodingName,
434
             const XML_Memory_Handling_Suite *memsuite,
440
             const XML_Memory_Handling_Suite *memsuite,
435
             const XML_Char *nameSep,
441
             const XML_Char *nameSep,
436
             DTD *dtd);
442
             DTD *dtd);
443
437
static void
444
static void
438
parserInit(XML_Parser parser, const XML_Char *encodingName);
445
parserInit(XML_Parser parser, const XML_Char *encodingName);
439
446
Lines 546-551 struct XML_ParserStruct { Link Here
546
  XML_Bool m_useForeignDTD;
553
  XML_Bool m_useForeignDTD;
547
  enum XML_ParamEntityParsing m_paramEntityParsing;
554
  enum XML_ParamEntityParsing m_paramEntityParsing;
548
#endif
555
#endif
556
  unsigned long m_hash_secret_salt;
549
};
557
};
550
558
551
#define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
559
#define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
Lines 653-658 struct XML_ParserStruct { Link Here
653
#define useForeignDTD (parser->m_useForeignDTD)
661
#define useForeignDTD (parser->m_useForeignDTD)
654
#define paramEntityParsing (parser->m_paramEntityParsing)
662
#define paramEntityParsing (parser->m_paramEntityParsing)
655
#endif /* XML_DTD */
663
#endif /* XML_DTD */
664
#define hash_secret_salt (parser->m_hash_secret_salt)
656
665
657
XML_Parser XMLCALL
666
XML_Parser XMLCALL
658
XML_ParserCreate(const XML_Char *encodingName)
667
XML_ParserCreate(const XML_Char *encodingName)
Lines 677-682 static const XML_Char implicitContext[] Link Here
677
  ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'
686
  ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'
678
};
687
};
679
688
689
static unsigned long
690
generate_hash_secret_salt(void)
691
{
692
  unsigned int seed = time(NULL) % UINT_MAX;
693
  srand(seed);
694
  return rand();
695
}
696
697
static XML_Bool  /* only valid for root parser */
698
startParsing(XML_Parser parser)
699
{
700
    /* hash functions must be initialized before setContext() is called */
701
    if (hash_secret_salt == 0)
702
      hash_secret_salt = generate_hash_secret_salt();
703
    if (ns) {
704
      /* implicit context only set for root parser, since child
705
         parsers (i.e. external entity parsers) will inherit it
706
      */
707
      return setContext(parser, implicitContext);
708
    }
709
    return XML_TRUE;
710
}
711
680
XML_Parser XMLCALL
712
XML_Parser XMLCALL
681
XML_ParserCreate_MM(const XML_Char *encodingName,
713
XML_ParserCreate_MM(const XML_Char *encodingName,
682
                    const XML_Memory_Handling_Suite *memsuite,
714
                    const XML_Memory_Handling_Suite *memsuite,
Lines 866-871 parserInit(XML_Parser parser, const XML_ Link Here
866
  useForeignDTD = XML_FALSE;
898
  useForeignDTD = XML_FALSE;
867
  paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
899
  paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER;
868
#endif
900
#endif
901
  hash_secret_salt = 0;
869
}
902
}
870
903
871
/* moves list of bindings to freeBindingList */
904
/* moves list of bindings to freeBindingList */
Lines 982-987 XML_ExternalEntityParserCreate(XML_Parse Link Here
982
  int oldInEntityValue = prologState.inEntityValue;
1015
  int oldInEntityValue = prologState.inEntityValue;
983
#endif
1016
#endif
984
  XML_Bool oldns_triplets = ns_triplets;
1017
  XML_Bool oldns_triplets = ns_triplets;
1018
  /* Note that the new parser shares the same hash secret as the old
1019
     parser, so that dtdCopy and copyEntityTable can lookup values
1020
     from hash tables associated with either parser without us having
1021
     to worry which hash secrets each table has.
1022
  */
1023
  unsigned long oldhash_secret_salt = hash_secret_salt;
985
1024
986
#ifdef XML_DTD
1025
#ifdef XML_DTD
987
  if (!context)
1026
  if (!context)
Lines 1035-1047 XML_ExternalEntityParserCreate(XML_Parse Link Here
1035
    externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
1074
    externalEntityRefHandlerArg = oldExternalEntityRefHandlerArg;
1036
  defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
1075
  defaultExpandInternalEntities = oldDefaultExpandInternalEntities;
1037
  ns_triplets = oldns_triplets;
1076
  ns_triplets = oldns_triplets;
1077
  hash_secret_salt = oldhash_secret_salt;
1038
  parentParser = oldParser;
1078
  parentParser = oldParser;
1039
#ifdef XML_DTD
1079
#ifdef XML_DTD
1040
  paramEntityParsing = oldParamEntityParsing;
1080
  paramEntityParsing = oldParamEntityParsing;
1041
  prologState.inEntityValue = oldInEntityValue;
1081
  prologState.inEntityValue = oldInEntityValue;
1042
  if (context) {
1082
  if (context) {
1043
#endif /* XML_DTD */
1083
#endif /* XML_DTD */
1044
    if (!dtdCopy(_dtd, oldDtd, &parser->m_mem)
1084
    if (!dtdCopy(oldParser, _dtd, oldDtd, &parser->m_mem)
1045
      || !setContext(parser, context)) {
1085
      || !setContext(parser, context)) {
1046
      XML_ParserFree(parser);
1086
      XML_ParserFree(parser);
1047
      return NULL;
1087
      return NULL;
Lines 1426-1431 XML_SetParamEntityParsing(XML_Parser par Link Here
1426
#endif
1466
#endif
1427
}
1467
}
1428
1468
1469
int XMLCALL
1470
XML_SetHashSalt(XML_Parser parser,
1471
                unsigned long hash_salt)
1472
{
1473
  /* block after XML_Parse()/XML_ParseBuffer() has been called */
1474
  if (ps_parsing == XML_PARSING || ps_parsing == XML_SUSPENDED)
1475
    return 0;
1476
  hash_secret_salt = hash_salt;
1477
  return 1;
1478
}
1479
1429
enum XML_Status XMLCALL
1480
enum XML_Status XMLCALL
1430
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
1481
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
1431
{
1482
{
Lines 1436-1441 XML_Parse(XML_Parser parser, const char Link Here
1436
  case XML_FINISHED:
1487
  case XML_FINISHED:
1437
    errorCode = XML_ERROR_FINISHED;
1488
    errorCode = XML_ERROR_FINISHED;
1438
    return XML_STATUS_ERROR;
1489
    return XML_STATUS_ERROR;
1490
  case XML_INITIALIZED:
1491
    if (parentParser == NULL && !startParsing(parser)) {
1492
      errorCode = XML_ERROR_NO_MEMORY;
1493
      return XML_STATUS_ERROR;
1494
    }
1439
  default:
1495
  default:
1440
    ps_parsing = XML_PARSING;
1496
    ps_parsing = XML_PARSING;
1441
  }
1497
  }
Lines 1494-1504 XML_Parse(XML_Parser parser, const char Link Here
1494
        break;
1550
        break;
1495
      case XML_INITIALIZED:
1551
      case XML_INITIALIZED:
1496
      case XML_PARSING:
1552
      case XML_PARSING:
1497
        result = XML_STATUS_OK;
1498
        if (isFinal) {
1553
        if (isFinal) {
1499
          ps_parsing = XML_FINISHED;
1554
          ps_parsing = XML_FINISHED;
1500
          return result;
1555
          return XML_STATUS_OK;
1501
        }
1556
        }
1557
      /* fall through */
1558
      default:
1559
        result = XML_STATUS_OK;
1502
      }
1560
      }
1503
    }
1561
    }
1504
1562
Lines 1559-1564 XML_ParseBuffer(XML_Parser parser, int l Link Here
1559
  case XML_FINISHED:
1617
  case XML_FINISHED:
1560
    errorCode = XML_ERROR_FINISHED;
1618
    errorCode = XML_ERROR_FINISHED;
1561
    return XML_STATUS_ERROR;
1619
    return XML_STATUS_ERROR;
1620
  case XML_INITIALIZED:
1621
    if (parentParser == NULL && !startParsing(parser)) {
1622
      errorCode = XML_ERROR_NO_MEMORY;
1623
      return XML_STATUS_ERROR;
1624
    }
1562
  default:
1625
  default:
1563
    ps_parsing = XML_PARSING;
1626
    ps_parsing = XML_PARSING;
1564
  }
1627
  }
Lines 2240-2246 doContent(XML_Parser parser, Link Here
2240
                                next - enc->minBytesPerChar);
2303
                                next - enc->minBytesPerChar);
2241
        if (!name)
2304
        if (!name)
2242
          return XML_ERROR_NO_MEMORY;
2305
          return XML_ERROR_NO_MEMORY;
2243
        entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0);
2306
        entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
2244
        poolDiscard(&dtd->pool);
2307
        poolDiscard(&dtd->pool);
2245
        /* First, determine if a check for an existing declaration is needed;
2308
        /* First, determine if a check for an existing declaration is needed;
2246
           if yes, check that the entity exists, and that it is internal,
2309
           if yes, check that the entity exists, and that it is internal,
Lines 2630-2641 storeAtts(XML_Parser parser, const ENCOD Link Here
2630
  const XML_Char *localPart;
2693
  const XML_Char *localPart;
2631
2694
2632
  /* lookup the element type name */
2695
  /* lookup the element type name */
2633
  elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);
2696
  elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, tagNamePtr->str,0);
2634
  if (!elementType) {
2697
  if (!elementType) {
2635
    const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2698
    const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2636
    if (!name)
2699
    if (!name)
2637
      return XML_ERROR_NO_MEMORY;
2700
      return XML_ERROR_NO_MEMORY;
2638
    elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,
2701
    elementType = (ELEMENT_TYPE *)lookup(parser, &dtd->elementTypes, name,
2639
                                         sizeof(ELEMENT_TYPE));
2702
                                         sizeof(ELEMENT_TYPE));
2640
    if (!elementType)
2703
    if (!elementType)
2641
      return XML_ERROR_NO_MEMORY;
2704
      return XML_ERROR_NO_MEMORY;
Lines 2804-2812 storeAtts(XML_Parser parser, const ENCOD Link Here
2804
      if (s[-1] == 2) {  /* prefixed */
2867
      if (s[-1] == 2) {  /* prefixed */
2805
        ATTRIBUTE_ID *id;
2868
        ATTRIBUTE_ID *id;
2806
        const BINDING *b;
2869
        const BINDING *b;
2807
        unsigned long uriHash = 0;
2870
        unsigned long uriHash = hash_secret_salt;
2808
        ((XML_Char *)s)[-1] = 0;  /* clear flag */
2871
        ((XML_Char *)s)[-1] = 0;  /* clear flag */
2809
        id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, s, 0);
2872
        id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, s, 0);
2810
        b = id->prefix->binding;
2873
        b = id->prefix->binding;
2811
        if (!b)
2874
        if (!b)
2812
          return XML_ERROR_UNBOUND_PREFIX;
2875
          return XML_ERROR_UNBOUND_PREFIX;
Lines 2828-2834 storeAtts(XML_Parser parser, const ENCOD Link Here
2828
        } while (*s++);
2891
        } while (*s++);
2829
2892
2830
        { /* Check hash table for duplicate of expanded name (uriName).
2893
        { /* Check hash table for duplicate of expanded name (uriName).
2831
             Derived from code in lookup(HASH_TABLE *table, ...).
2894
             Derived from code in lookup(parser, HASH_TABLE *table, ...).
2832
          */
2895
          */
2833
          unsigned char step = 0;
2896
          unsigned char step = 0;
2834
          unsigned long mask = nsAttsSize - 1;
2897
          unsigned long mask = nsAttsSize - 1;
Lines 3777-3783 doProlog(XML_Parser parser, Link Here
3777
    case XML_ROLE_DOCTYPE_PUBLIC_ID:
3840
    case XML_ROLE_DOCTYPE_PUBLIC_ID:
3778
#ifdef XML_DTD
3841
#ifdef XML_DTD
3779
      useForeignDTD = XML_FALSE;
3842
      useForeignDTD = XML_FALSE;
3780
      declEntity = (ENTITY *)lookup(&dtd->paramEntities,
3843
      declEntity = (ENTITY *)lookup(parser,
3844
                                    &dtd->paramEntities,
3781
                                    externalSubsetName,
3845
                                    externalSubsetName,
3782
                                    sizeof(ENTITY));
3846
                                    sizeof(ENTITY));
3783
      if (!declEntity)
3847
      if (!declEntity)
Lines 3832-3838 doProlog(XML_Parser parser, Link Here
3832
        XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3896
        XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3833
        dtd->hasParamEntityRefs = XML_TRUE;
3897
        dtd->hasParamEntityRefs = XML_TRUE;
3834
        if (paramEntityParsing && externalEntityRefHandler) {
3898
        if (paramEntityParsing && externalEntityRefHandler) {
3835
          ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,
3899
          ENTITY *entity = (ENTITY *)lookup(parser,
3900
                                            &dtd->paramEntities,
3836
                                            externalSubsetName,
3901
                                            externalSubsetName,
3837
                                            sizeof(ENTITY));
3902
                                            sizeof(ENTITY));
3838
          if (!entity)
3903
          if (!entity)
Lines 3876-3882 doProlog(XML_Parser parser, Link Here
3876
        XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3941
        XML_Bool hadParamEntityRefs = dtd->hasParamEntityRefs;
3877
        dtd->hasParamEntityRefs = XML_TRUE;
3942
        dtd->hasParamEntityRefs = XML_TRUE;
3878
        if (paramEntityParsing && externalEntityRefHandler) {
3943
        if (paramEntityParsing && externalEntityRefHandler) {
3879
          ENTITY *entity = (ENTITY *)lookup(&dtd->paramEntities,
3944
          ENTITY *entity = (ENTITY *)lookup(parser, &dtd->paramEntities,
3880
                                            externalSubsetName,
3945
                                            externalSubsetName,
3881
                                            sizeof(ENTITY));
3946
                                            sizeof(ENTITY));
3882
          if (!entity)
3947
          if (!entity)
Lines 4090-4096 doProlog(XML_Parser parser, Link Here
4090
      break;
4155
      break;
4091
#else /* XML_DTD */
4156
#else /* XML_DTD */
4092
      if (!declEntity) {
4157
      if (!declEntity) {
4093
        declEntity = (ENTITY *)lookup(&dtd->paramEntities,
4158
        declEntity = (ENTITY *)lookup(parser,
4159
                                      &dtd->paramEntities,
4094
                                      externalSubsetName,
4160
                                      externalSubsetName,
4095
                                      sizeof(ENTITY));
4161
                                      sizeof(ENTITY));
4096
        if (!declEntity)
4162
        if (!declEntity)
Lines 4165-4171 doProlog(XML_Parser parser, Link Here
4165
          const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4231
          const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4166
          if (!name)
4232
          if (!name)
4167
            return XML_ERROR_NO_MEMORY;
4233
            return XML_ERROR_NO_MEMORY;
4168
          declEntity = (ENTITY *)lookup(&dtd->generalEntities, name,
4234
          declEntity = (ENTITY *)lookup(parser, &dtd->generalEntities, name,
4169
                                        sizeof(ENTITY));
4235
                                        sizeof(ENTITY));
4170
          if (!declEntity)
4236
          if (!declEntity)
4171
            return XML_ERROR_NO_MEMORY;
4237
            return XML_ERROR_NO_MEMORY;
Lines 4197-4203 doProlog(XML_Parser parser, Link Here
4197
        const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4263
        const XML_Char *name = poolStoreString(&dtd->pool, enc, s, next);
4198
        if (!name)
4264
        if (!name)
4199
          return XML_ERROR_NO_MEMORY;
4265
          return XML_ERROR_NO_MEMORY;
4200
        declEntity = (ENTITY *)lookup(&dtd->paramEntities,
4266
        declEntity = (ENTITY *)lookup(parser, &dtd->paramEntities,
4201
                                           name, sizeof(ENTITY));
4267
                                           name, sizeof(ENTITY));
4202
        if (!declEntity)
4268
        if (!declEntity)
4203
          return XML_ERROR_NO_MEMORY;
4269
          return XML_ERROR_NO_MEMORY;
Lines 4379-4385 doProlog(XML_Parser parser, Link Here
4379
                                next - enc->minBytesPerChar);
4445
                                next - enc->minBytesPerChar);
4380
        if (!name)
4446
        if (!name)
4381
          return XML_ERROR_NO_MEMORY;
4447
          return XML_ERROR_NO_MEMORY;
4382
        entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0);
4448
        entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
4383
        poolDiscard(&dtd->pool);
4449
        poolDiscard(&dtd->pool);
4384
        /* first, determine if a check for an existing declaration is needed;
4450
        /* first, determine if a check for an existing declaration is needed;
4385
           if yes, check that the entity exists, and that it is internal,
4451
           if yes, check that the entity exists, and that it is internal,
Lines 4903-4909 appendAttributeValue(XML_Parser parser, Link Here
4903
                               next - enc->minBytesPerChar);
4969
                               next - enc->minBytesPerChar);
4904
        if (!name)
4970
        if (!name)
4905
          return XML_ERROR_NO_MEMORY;
4971
          return XML_ERROR_NO_MEMORY;
4906
        entity = (ENTITY *)lookup(&dtd->generalEntities, name, 0);
4972
        entity = (ENTITY *)lookup(parser, &dtd->generalEntities, name, 0);
4907
        poolDiscard(&temp2Pool);
4973
        poolDiscard(&temp2Pool);
4908
        /* First, determine if a check for an existing declaration is needed;
4974
        /* First, determine if a check for an existing declaration is needed;
4909
           if yes, check that the entity exists, and that it is internal.
4975
           if yes, check that the entity exists, and that it is internal.
Lines 5012-5018 storeEntityValue(XML_Parser parser, Link Here
5012
          result = XML_ERROR_NO_MEMORY;
5078
          result = XML_ERROR_NO_MEMORY;
5013
          goto endEntityValue;
5079
          goto endEntityValue;
5014
        }
5080
        }
5015
        entity = (ENTITY *)lookup(&dtd->paramEntities, name, 0);
5081
        entity = (ENTITY *)lookup(parser, &dtd->paramEntities, name, 0);
5016
        poolDiscard(&tempPool);
5082
        poolDiscard(&tempPool);
5017
        if (!entity) {
5083
        if (!entity) {
5018
          /* not a well-formedness error - see XML 1.0: WFC Entity Declared */
5084
          /* not a well-formedness error - see XML 1.0: WFC Entity Declared */
Lines 5302-5308 setElementTypePrefix(XML_Parser parser, Link Here
5302
      }
5368
      }
5303
      if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5369
      if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5304
        return 0;
5370
        return 0;
5305
      prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool),
5371
      prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool),
5306
                                sizeof(PREFIX));
5372
                                sizeof(PREFIX));
5307
      if (!prefix)
5373
      if (!prefix)
5308
        return 0;
5374
        return 0;
Lines 5331-5337 getAttributeId(XML_Parser parser, const Link Here
5331
    return NULL;
5397
    return NULL;
5332
  /* skip quotation mark - its storage will be re-used (like in name[-1]) */
5398
  /* skip quotation mark - its storage will be re-used (like in name[-1]) */
5333
  ++name;
5399
  ++name;
5334
  id = (ATTRIBUTE_ID *)lookup(&dtd->attributeIds, name, sizeof(ATTRIBUTE_ID));
5400
  id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID));
5335
  if (!id)
5401
  if (!id)
5336
    return NULL;
5402
    return NULL;
5337
  if (id->name != name)
5403
  if (id->name != name)
Lines 5349-5355 getAttributeId(XML_Parser parser, const Link Here
5349
      if (name[5] == XML_T('\0'))
5415
      if (name[5] == XML_T('\0'))
5350
        id->prefix = &dtd->defaultPrefix;
5416
        id->prefix = &dtd->defaultPrefix;
5351
      else
5417
      else
5352
        id->prefix = (PREFIX *)lookup(&dtd->prefixes, name + 6, sizeof(PREFIX));
5418
        id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, name + 6, sizeof(PREFIX));
5353
      id->xmlns = XML_TRUE;
5419
      id->xmlns = XML_TRUE;
5354
    }
5420
    }
5355
    else {
5421
    else {
Lines 5364-5370 getAttributeId(XML_Parser parser, const Link Here
5364
          }
5430
          }
5365
          if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5431
          if (!poolAppendChar(&dtd->pool, XML_T('\0')))
5366
            return NULL;
5432
            return NULL;
5367
          id->prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&dtd->pool),
5433
          id->prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&dtd->pool),
5368
                                        sizeof(PREFIX));
5434
                                        sizeof(PREFIX));
5369
          if (id->prefix->name == poolStart(&dtd->pool))
5435
          if (id->prefix->name == poolStart(&dtd->pool))
5370
            poolFinish(&dtd->pool);
5436
            poolFinish(&dtd->pool);
Lines 5460-5466 setContext(XML_Parser parser, const XML_ Link Here
5460
      ENTITY *e;
5526
      ENTITY *e;
5461
      if (!poolAppendChar(&tempPool, XML_T('\0')))
5527
      if (!poolAppendChar(&tempPool, XML_T('\0')))
5462
        return XML_FALSE;
5528
        return XML_FALSE;
5463
      e = (ENTITY *)lookup(&dtd->generalEntities, poolStart(&tempPool), 0);
5529
      e = (ENTITY *)lookup(parser, &dtd->generalEntities, poolStart(&tempPool), 0);
5464
      if (e)
5530
      if (e)
5465
        e->open = XML_TRUE;
5531
        e->open = XML_TRUE;
5466
      if (*s != XML_T('\0'))
5532
      if (*s != XML_T('\0'))
Lines 5475-5481 setContext(XML_Parser parser, const XML_ Link Here
5475
      else {
5541
      else {
5476
        if (!poolAppendChar(&tempPool, XML_T('\0')))
5542
        if (!poolAppendChar(&tempPool, XML_T('\0')))
5477
          return XML_FALSE;
5543
          return XML_FALSE;
5478
        prefix = (PREFIX *)lookup(&dtd->prefixes, poolStart(&tempPool),
5544
        prefix = (PREFIX *)lookup(parser, &dtd->prefixes, poolStart(&tempPool),
5479
                                  sizeof(PREFIX));
5545
                                  sizeof(PREFIX));
5480
        if (!prefix)
5546
        if (!prefix)
5481
          return XML_FALSE;
5547
          return XML_FALSE;
Lines 5639-5645 dtdDestroy(DTD *p, XML_Bool isDocEntity, Link Here
5639
   The new DTD has already been initialized.
5705
   The new DTD has already been initialized.
5640
*/
5706
*/
5641
static int
5707
static int
5642
dtdCopy(DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms)
5708
dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms)
5643
{
5709
{
5644
  HASH_TABLE_ITER iter;
5710
  HASH_TABLE_ITER iter;
5645
5711
Lines 5654-5660 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5654
    name = poolCopyString(&(newDtd->pool), oldP->name);
5720
    name = poolCopyString(&(newDtd->pool), oldP->name);
5655
    if (!name)
5721
    if (!name)
5656
      return 0;
5722
      return 0;
5657
    if (!lookup(&(newDtd->prefixes), name, sizeof(PREFIX)))
5723
    if (!lookup(oldParser, &(newDtd->prefixes), name, sizeof(PREFIX)))
5658
      return 0;
5724
      return 0;
5659
  }
5725
  }
5660
5726
Lines 5676-5682 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5676
    if (!name)
5742
    if (!name)
5677
      return 0;
5743
      return 0;
5678
    ++name;
5744
    ++name;
5679
    newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name,
5745
    newA = (ATTRIBUTE_ID *)lookup(oldParser, &(newDtd->attributeIds), name,
5680
                                  sizeof(ATTRIBUTE_ID));
5746
                                  sizeof(ATTRIBUTE_ID));
5681
    if (!newA)
5747
    if (!newA)
5682
      return 0;
5748
      return 0;
Lines 5686-5692 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5686
      if (oldA->prefix == &oldDtd->defaultPrefix)
5752
      if (oldA->prefix == &oldDtd->defaultPrefix)
5687
        newA->prefix = &newDtd->defaultPrefix;
5753
        newA->prefix = &newDtd->defaultPrefix;
5688
      else
5754
      else
5689
        newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes),
5755
        newA->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5690
                                        oldA->prefix->name, 0);
5756
                                        oldA->prefix->name, 0);
5691
    }
5757
    }
5692
  }
5758
  }
Lines 5705-5711 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5705
    name = poolCopyString(&(newDtd->pool), oldE->name);
5771
    name = poolCopyString(&(newDtd->pool), oldE->name);
5706
    if (!name)
5772
    if (!name)
5707
      return 0;
5773
      return 0;
5708
    newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name,
5774
    newE = (ELEMENT_TYPE *)lookup(oldParser, &(newDtd->elementTypes), name,
5709
                                  sizeof(ELEMENT_TYPE));
5775
                                  sizeof(ELEMENT_TYPE));
5710
    if (!newE)
5776
    if (!newE)
5711
      return 0;
5777
      return 0;
Lines 5719-5732 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5719
    }
5785
    }
5720
    if (oldE->idAtt)
5786
    if (oldE->idAtt)
5721
      newE->idAtt = (ATTRIBUTE_ID *)
5787
      newE->idAtt = (ATTRIBUTE_ID *)
5722
          lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0);
5788
          lookup(oldParser, &(newDtd->attributeIds), oldE->idAtt->name, 0);
5723
    newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
5789
    newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
5724
    if (oldE->prefix)
5790
    if (oldE->prefix)
5725
      newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes),
5791
      newE->prefix = (PREFIX *)lookup(oldParser, &(newDtd->prefixes),
5726
                                      oldE->prefix->name, 0);
5792
                                      oldE->prefix->name, 0);
5727
    for (i = 0; i < newE->nDefaultAtts; i++) {
5793
    for (i = 0; i < newE->nDefaultAtts; i++) {
5728
      newE->defaultAtts[i].id = (ATTRIBUTE_ID *)
5794
      newE->defaultAtts[i].id = (ATTRIBUTE_ID *)
5729
          lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
5795
          lookup(oldParser, &(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);
5730
      newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
5796
      newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
5731
      if (oldE->defaultAtts[i].value) {
5797
      if (oldE->defaultAtts[i].value) {
5732
        newE->defaultAtts[i].value
5798
        newE->defaultAtts[i].value
Lines 5740-5752 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5740
  }
5806
  }
5741
5807
5742
  /* Copy the entity tables. */
5808
  /* Copy the entity tables. */
5743
  if (!copyEntityTable(&(newDtd->generalEntities),
5809
  if (!copyEntityTable(oldParser,
5810
                       &(newDtd->generalEntities),
5744
                       &(newDtd->pool),
5811
                       &(newDtd->pool),
5745
                       &(oldDtd->generalEntities)))
5812
                       &(oldDtd->generalEntities)))
5746
      return 0;
5813
      return 0;
5747
5814
5748
#ifdef XML_DTD
5815
#ifdef XML_DTD
5749
  if (!copyEntityTable(&(newDtd->paramEntities),
5816
  if (!copyEntityTable(oldParser,
5817
                       &(newDtd->paramEntities),
5750
                       &(newDtd->pool),
5818
                       &(newDtd->pool),
5751
                       &(oldDtd->paramEntities)))
5819
                       &(oldDtd->paramEntities)))
5752
      return 0;
5820
      return 0;
Lines 5769-5775 dtdCopy(DTD *newDtd, const DTD *oldDtd, Link Here
5769
}  /* End dtdCopy */
5837
}  /* End dtdCopy */
5770
5838
5771
static int
5839
static int
5772
copyEntityTable(HASH_TABLE *newTable,
5840
copyEntityTable(XML_Parser oldParser,
5841
                HASH_TABLE *newTable,
5773
                STRING_POOL *newPool,
5842
                STRING_POOL *newPool,
5774
                const HASH_TABLE *oldTable)
5843
                const HASH_TABLE *oldTable)
5775
{
5844
{
Lines 5788-5794 copyEntityTable(HASH_TABLE *newTable, Link Here
5788
    name = poolCopyString(newPool, oldE->name);
5857
    name = poolCopyString(newPool, oldE->name);
5789
    if (!name)
5858
    if (!name)
5790
      return 0;
5859
      return 0;
5791
    newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY));
5860
    newE = (ENTITY *)lookup(oldParser, newTable, name, sizeof(ENTITY));
5792
    if (!newE)
5861
    if (!newE)
5793
      return 0;
5862
      return 0;
5794
    if (oldE->systemId) {
5863
    if (oldE->systemId) {
Lines 5846-5861 keyeq(KEY s1, KEY s2) Link Here
5846
}
5915
}
5847
5916
5848
static unsigned long FASTCALL
5917
static unsigned long FASTCALL
5849
hash(KEY s)
5918
hash(XML_Parser parser, KEY s)
5850
{
5919
{
5851
  unsigned long h = 0;
5920
  unsigned long h = hash_secret_salt;
5852
  while (*s)
5921
  while (*s)
5853
    h = CHAR_HASH(h, *s++);
5922
    h = CHAR_HASH(h, *s++);
5854
  return h;
5923
  return h;
5855
}
5924
}
5856
5925
5857
static NAMED *
5926
static NAMED *
5858
lookup(HASH_TABLE *table, KEY name, size_t createSize)
5927
lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize)
5859
{
5928
{
5860
  size_t i;
5929
  size_t i;
5861
  if (table->size == 0) {
5930
  if (table->size == 0) {
Lines 5872-5881 lookup(HASH_TABLE *table, KEY name, size Link Here
5872
      return NULL;
5941
      return NULL;
5873
    }
5942
    }
5874
    memset(table->v, 0, tsize);
5943
    memset(table->v, 0, tsize);
5875
    i = hash(name) & ((unsigned long)table->size - 1);
5944
    i = hash(parser, name) & ((unsigned long)table->size - 1);
5876
  }
5945
  }
5877
  else {
5946
  else {
5878
    unsigned long h = hash(name);
5947
    unsigned long h = hash(parser, name);
5879
    unsigned long mask = (unsigned long)table->size - 1;
5948
    unsigned long mask = (unsigned long)table->size - 1;
5880
    unsigned char step = 0;
5949
    unsigned char step = 0;
5881
    i = h & mask;
5950
    i = h & mask;
Lines 5901-5907 lookup(HASH_TABLE *table, KEY name, size Link Here
5901
      memset(newV, 0, tsize);
5970
      memset(newV, 0, tsize);
5902
      for (i = 0; i < table->size; i++)
5971
      for (i = 0; i < table->size; i++)
5903
        if (table->v[i]) {
5972
        if (table->v[i]) {
5904
          unsigned long newHash = hash(table->v[i]->name);
5973
          unsigned long newHash = hash(parser, table->v[i]->name);
5905
          size_t j = newHash & newMask;
5974
          size_t j = newHash & newMask;
5906
          step = 0;
5975
          step = 0;
5907
          while (newV[j]) {
5976
          while (newV[j]) {
Lines 6276-6282 getElementType(XML_Parser parser, Link Here
6276
6345
6277
  if (!name)
6346
  if (!name)
6278
    return NULL;
6347
    return NULL;
6279
  ret = (ELEMENT_TYPE *) lookup(&dtd->elementTypes, name, sizeof(ELEMENT_TYPE));
6348
  ret = (ELEMENT_TYPE *) lookup(parser, &dtd->elementTypes, name, sizeof(ELEMENT_TYPE));
6280
  if (!ret)
6349
  if (!ret)
6281
    return NULL;
6350
    return NULL;
6282
  if (ret->name != name)
6351
  if (ret->name != name)

Return to bug 755377