Changeset 18313


Ignore:
Timestamp:
01/06/09 13:26:48 (12 years ago)
Author:
davidb
Message:

Fixed bug to do with initialization of RequestFields variable. Had been using a memset to make it all zero, but this is not a safe thing to do when there are text_t fields in the class. Code upgraded to use a constructor and 'reset' function that explicitly initializes and clears the text_t fields

Location:
gsdl/trunk/runtime-src/src/w32server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/runtime-src/src/w32server/httpreq.cpp

    r11259 r18313  
    212212}
    213213
     214void resetRequestFieldsT(RequestFieldsT& RequestFields)
     215{
     216  // Can't just 'memset' the text_t fields (as used to be done),
     217  // as this could lead to inconsistent state in text_t fields
     218  // ultimately resulting in a segmentation fault
     219  // => need to go through an explicitly reset them
     220
     221  //Simple request line info v0.9
     222  RequestFields.MethodStr.clear();
     223  RequestFields.URIStr.clear();
     224  //added v1.0
     225  RequestFields.VersionStr.clear();
     226  //General Header
     227  RequestFields.DateStr.clear();
     228  RequestFields.MIMEVerStr.clear();
     229  RequestFields.PragmaStr.clear();
     230  //Request Header
     231  RequestFields.AuthorizationStr.clear();
     232  RequestFields.FromStr.clear();
     233  RequestFields.IfModSinceStr.clear();
     234  RequestFields.RefererStr.clear();
     235  RequestFields.UserAgentStr.clear();
     236  //Entity Header (Only CGI stuff)
     237  RequestFields.ContentEncodingStr.clear();
     238  RequestFields.ContentTypeStr.clear();
     239  RequestFields.ContentLengthStr.clear();
     240  //v1.0 Optional (the more common ones)
     241  RequestFields.AcceptStr.clear();
     242  RequestFields.AcceptLangStr.clear();
     243  //v1.1 Exentions
     244  RequestFields.ConnectionStr.clear();
     245 
     246  //Reset all the non text_t fields
     247  RequestFields.ContentLength = 0;
     248  RequestFields.Content = NULL;
     249  RequestFields.NumOtherHeaders = 0;
     250 
     251  for (int i=0 ; i<MAX_OTHER_HEADERS; i++) {
     252    RequestFields.OtherHeaders[i].Var.clear();
     253    RequestFields.OtherHeaders[i].Val.clear();
     254  }
     255}
     256
    214257/******************************************************************************/
    215258int GetHTTPHeaders(RequestInfoT &RequestInfo, RequestFieldsT &RequestFields) {
     
    226269  text_t::const_iterator end;
    227270
    228   //Clear all the fields
    229   memset(&RequestFields, 0, sizeof(RequestFieldsT));
     271  resetRequestFieldsT(RequestFields);
    230272
    231273  ReadBufferIndex = 0;
  • gsdl/trunk/runtime-src/src/w32server/httpreq.h

    r3811 r18313  
    6161  text_t Var;
    6262  text_t Val;
     63
     64  RequestHeaderT()
     65  : Var(), Val()
     66  {}
    6367};
    6468
     
    9599  int NumOtherHeaders;
    96100  RequestHeaderT OtherHeaders[MAX_OTHER_HEADERS];
     101
     102  RequestFieldsT()
     103  : MethodStr(), URIStr(), VersionStr(), DateStr(), MIMEVerStr(),
     104    PragmaStr(), AuthorizationStr(), FromStr(), IfModSinceStr(),
     105    RefererStr(), UserAgentStr(), ContentEncodingStr(),
     106    ContentTypeStr(), ContentLengthStr(), AcceptStr(),
     107    AcceptLangStr(), ConnectionStr(),
     108    OtherHeaders()
     109  {
     110    ContentLength = 0;
     111    Content = NULL;
     112    NumOtherHeaders = 0;
     113  }
     114
    97115};
    98116
Note: See TracChangeset for help on using the changeset viewer.