Show
Ignore:
Timestamp:
22.09.2010 13:52:18 (9 years ago)
Author:
ak19
Message:

For ticket no 712 again. Tidier code in decode_commas function. Related to previous commit to fix a crash that occurred when using a combination of advanced and fielded searching - in an MGPP collection (server.exe and library.cgi would crash depending on which web server was used): 1. When parsing cgi args, arrays stem and fold contained the URL encodings percent-2-C rather than commas for delimiters and weren't split properly resulting in arrays of unexpected lengths (and values). Need to decode the percent-2-C to commas by calling decode_commas() in cgiutils.cpp before splitting. 2. decode_commas in cgiutils.cpp was performing an illegal iterator operation by attempting to peek PAST the end of the iterator which doesn't seem to be allowed by the STL code. When the iteration really got past the end, the iteration operation causes a problem resulting in a server.exe crash of its own.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/cgiutils.cpp

    r22934 r22942  
    412412  text_t::const_iterator end = intext.end (); 
    413413   
    414   /*while (here != end) { 
    415     if (((here+2)<end) && *here == '%' && *(here+1) == '2' 
    416         && (*(here+2) == 'C' || *(here+2) == 'c')) { 
    417       here += 2; 
    418       outtext.push_back(','); 
    419        
    420     }else outtext.push_back (*here); 
    421     ++here; 
    422   } 
    423   return outtext;*/ 
    424  
    425   // iterators do not allow a forward increment/peek that goes past  
    426   // iterator's end: tests like (here+2 <end) above cause errors if  
    427   // the result ends up being > end. So have to test one character  
    428   // at a time, since tests like (here != end) *are* allowed: 
    429  
    430   while (here != end) { // look for "%2C" to replace with "," 
    431      if(*here == '%') { 
    432          ++here; 
    433          if(here != end && *here == '2') { 
    434             ++here; 
    435             if(here != end && (*here == 'C' || *here == 'c')) { 
     414  // for loop 
     415  int intext_len = intext.size(); 
     416  for(int i = 0; i < intext_len; i++) { 
     417      if ((i+2)<intext_len) { 
     418          if(intext[i] == '%' && intext[i+1] == '2' 
     419            && (intext[i+2] == 'C' || intext[i+2] == 'c')) { 
     420                i += 2; 
    436421                outtext.push_back(','); 
    437             } else { 
    438                 here -= 2; 
    439                 outtext.push_back (*here); 
    440             } 
    441          } else { // go back to % char and push it back 
    442             --here; 
    443             outtext.push_back (*here); 
    444          }       
    445      } else { 
    446         outtext.push_back (*here); 
    447      } 
    448  
    449      ++here; 
    450   } // end while 
    451   return outtext; 
     422                continue; 
     423          } 
     424      } 
     425      outtext.push_back (intext[i]); 
     426   } 
     427  return outtext;  
    452428} 
    453429