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

    https://github.com/apache/trafficserver/pull/435#discussion_r51563391
  
    --- Diff: lib/atscppapi/src/Transaction.cc ---
    @@ -186,6 +186,20 @@ Transaction::setErrorBody(const std::string &page)
       TSHttpTxnErrorBodySet(state_->txn_, TSstrdup(page.c_str()), 
page.length(), NULL); // Default to text/html
     }
     
    +void
    +Transaction::setErrorBody(const std::string &page, const std::string 
&mimetype)
    +{
    +  LOG_DEBUG("Transaction tshttptxn=%p setting error body page: %s", 
state_->txn_, page.c_str());
    +  TSHttpTxnErrorBodySet(state_->txn_, TSstrdup(page.c_str()), 
page.length(), TSstrdup(mimetype.c_str()));
    --- End diff --
    
    I'm totally good w/ this addition but there is a bug that was recently 
identified in `Transaction::setErrorBody()`, if someone passes a binary string 
in for page it will result in weird truncation because of the use of string 
functions. The code needs to change to be:
    
    `
    char *body = (char*)TSmalloc(page.length());
    memcpy(body, page.data(), page.length());
    TSHttpTxnErrorBodySet(state_->txn_, body, page.length(), 
TSstrdup(mimetype.c_str()));
    `
    
    Can you make this change to both versions of `Transaction::setErrorBody()`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to