[ 
https://issues.apache.org/jira/browse/TS-4313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15222004#comment-15222004
 ] 

ASF GitHub Bot commented on TS-4313:
------------------------------------

Github user jpeach commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/542#discussion_r58236316
  
    --- Diff: proxy/hdrs/test_mime.cc ---
    @@ -0,0 +1,80 @@
    +/** @file
    +
    +  A brief file description
    +
    +  @section license License
    +
    +  Licensed to the Apache Software Foundation (ASF) under one
    +  or more contributor license agreements.  See the NOTICE file
    +  distributed with this work for additional information
    +  regarding copyright ownership.  The ASF licenses this file
    +  to you under the Apache License, Version 2.0 (the
    +  "License"); you may not use this file except in compliance
    +  with the License.  You may obtain a copy of the License at
    +
    +      http://www.apache.org/licenses/LICENSE-2.0
    +
    +  Unless required by applicable law or agreed to in writing, software
    +  distributed under the License is distributed on an "AS IS" BASIS,
    +  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +  See the License for the specific language governing permissions and
    +  limitations under the License.
    + */
    +
    +
    +#include "P_Eventsystem.h"
    +#include "MIME.h"
    +
    +static void
    +test_mime()
    +{
    +  int failed = 0;
    +  MIMEField *field;
    +  MIMEHdr hdr;
    +  hdr.create(NULL);
    +
    +  hdr.field_create("Test1", 5);
    +  hdr.field_create("Test2", 5);
    +  hdr.field_create("Test3", 5);
    +  hdr.field_create("Test4", 5);
    +  field = hdr.field_create("Test5", 5);
    +  if (!hdr.m_mime->m_first_fblock.contains(field)) {
    +    printf("FAILED: The field block doesn't contain the field but it 
should\n\n");
    +    failed = 1;
    +  }
    +  if (hdr.m_mime->m_first_fblock.contains(field + (1L << 32))) {
    +    printf("FAILED: The field block contains the field but it 
shouldn't\n\n");
    +    failed = 1;
    +  }
    +
    +  int slot_num = mime_hdr_field_slotnum(hdr.m_mime, field);
    +  if (slot_num != 4) {
    +    printf("FAILED: Slot number is %d but should be 4\n\n", slot_num);
    +    failed = 1;
    +  }
    +
    +  slot_num = mime_hdr_field_slotnum(hdr.m_mime, field + (1L << 32));
    +  if (slot_num != -1) {
    +    printf("FAILED: Slot number is %d but should be -1\n\n", slot_num);
    +    failed = 1;
    +  }
    +
    +  hdr.destroy();
    +
    +  printf("*** %s ***\n", (failed ? "FAILED" : "PASSED"));
    +  if (failed) {
    +    exit(1);
    +  }
    +}
    +
    +int
    +main(int argc, char *argv[])
    +{
    +  Thread *main_thread = new EThread;
    +  main_thread->set_specific();
    +  mime_init();
    +
    +  test_mime();
    --- End diff --
    
    This is nice! Could you use ``<ts/TestBox.h>`` for the test harness? (see 
plugins/experimental/sslheaders/test_sslheaders.cc, for example).


> MIMEHdr fails to find header fields
> -----------------------------------
>
>                 Key: TS-4313
>                 URL: https://issues.apache.org/jira/browse/TS-4313
>             Project: Traffic Server
>          Issue Type: Bug
>          Components: MIME
>            Reporter: Masakazu Kitajo
>            Assignee: Masakazu Kitajo
>             Fix For: 6.2.0
>
>
> MIMEHdr fails to find a MIMEField occasionally due to improper type 
> conversion.
> It happens if the lower 32 bits of addresses of m_field_slots are the same. 
> The logic below picks up wrong block.
> mime_hdr_field_slotnum(): 
> {code}
> for (fblock = &(mh->m_first_fblock); fblock != NULL; fblock = fblock->m_next) 
> {
>     MIMEField *first = &(fblock->m_field_slots[0]);
>     int block_slot = (int)(field - first); // in units of MIMEField
>     if ((block_slot >= 0) && (block_slot < MIME_FIELD_BLOCK_SLOTS))
> {code}
> The type of block_slot should be intptr_t.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to