Use StackBuf<> instead of direct char[]+SafeBuf

This commit is contained in:
Ivan Skytte Jørgensen
2017-01-06 12:19:21 +01:00
parent 9fd4ea3a87
commit 026f1c1556
13 changed files with 23 additions and 47 deletions

@ -2569,8 +2569,7 @@ bool CollectionRec::save ( ) {
g_hostdb.m_dir , m_coll , (int32_t)m_collnum );
//log("coll: saving %s",tmp);
// in case emergency save from malloc core, do not alloc
char stack[1024];
SafeBuf sb(stack,1024);
StackBuf<1024> sb;
//m_localCrawlInfo.print ( &sb );
// binary now
sb.safeMemcpy ( &m_localCrawlInfo , sizeof(CrawlInfo) );

@ -828,8 +828,7 @@ void downloadTheDocForReals3b ( Msg13Request *r ) {
// ALSO ADD authorization to the NEW proxy we are sending to
// r->m_proxyIp/r->m_proxyPort that has a username:password
char tmpBuf[1024];
SafeBuf newReq (tmpBuf,1024);
StackBuf<1024> newReq;
if ( r->m_isSquidProxiedUrl && r->m_proxyIp ) {
newReq.safeStrcpy ( exactRequest );
addNewProxyAuthorization ( &newReq , r );

@ -144,8 +144,7 @@ bool sendReply ( void *state ) {
printUrl = false;
// page is not more than 32k
char buf[1024*32+MAX_URL_LEN*2];
SafeBuf sb(buf, 1024*32+MAX_URL_LEN*2);
StackBuf<1024*32+MAX_URL_LEN*2> sb;
g_pages.printAdminTop ( &sb , sock , &gr->m_hr );

@ -750,8 +750,7 @@ bool sendPageWidgets ( TcpSocket *socket , HttpRequest *hr ) {
return true;
}
char buf [ 128000 ];
SafeBuf sb(buf,128000);
StackBuf<128000> sb;
printFrontPageShell ( &sb, "widgets", cr , true );
@ -778,9 +777,7 @@ bool sendPageWidgets ( TcpSocket *socket , HttpRequest *hr ) {
//
///////////
bool sendPageBasicStatus ( TcpSocket *socket , HttpRequest *hr ) {
char buf [ 128000 ];
SafeBuf sb(buf,128000);
sb.reset();
StackBuf<128000> sb;
char format = hr->getReplyFormat();

@ -1495,8 +1495,7 @@ bool printSearchResultsTail ( State0 *st ) {
// now print "Prev X Results" if we need to
if ( firstNum < 0 ) firstNum = 0;
char abuf[300];
SafeBuf args(abuf,300);
StackBuf<300> args;
// show banned?
if ( si->m_showBanned && ! si->m_isMasterAdmin )
args.safePrintf("&sb=1");
@ -3109,8 +3108,7 @@ bool printResult ( State0 *st, int32_t ix , int32_t *numPrintedSoFar ) {
hbuf [ hlen ] = '\0';
// make the cgi parm to add to the original url
char tmp[512];
SafeBuf qq (tmp,512);
StackBuf<512> qq;
qq.safePrintf("q=");
urlEncode(&qq, "site:");
urlEncode(&qq, hbuf);
@ -3118,8 +3116,7 @@ bool printResult ( State0 *st, int32_t ix , int32_t *numPrintedSoFar ) {
qq.safeStrcpy(st->m_qesb.getBufStart());
qq.nullTerm();
// get the original url and add/replace in query
char tmp2[512];
SafeBuf newUrl(tmp2, 512);
StackBuf<512> newUrl;
replaceParm ( qq.getBufStart() , &newUrl , hr );
// put show more results from this site link
sb->safePrintf (" - <nobr><a href=\"%s\">"
@ -3187,9 +3184,7 @@ bool printResult ( State0 *st, int32_t ix , int32_t *numPrintedSoFar ) {
Json md;
JsonItem *ji = md.parseJsonStringIntoJsonItems(mr->ptr_metadataBuf);
char tmpBuf1[1024];
char tmpBuf2[1024];
SafeBuf nameBuf(tmpBuf1, 1024);
StackBuf<1024> nameBuf;
for ( ; ji ; ji = ji->m_next ) {
if(ji->isInArray()) continue;
if(ji->m_type == JT_ARRAY) continue;
@ -3202,7 +3197,7 @@ bool printResult ( State0 *st, int32_t ix , int32_t *numPrintedSoFar ) {
int32_t valLen;
const char* valBuf = ji->getValueAsString(&valLen);
SafeBuf queryBuf(tmpBuf2, 1024);
StackBuf<1024> queryBuf;
// log("compound name is %s %d %d",nameBuf.getBufStart(),
// nameBuf.length(), valLen);
@ -3270,8 +3265,7 @@ bool printResult ( State0 *st, int32_t ix , int32_t *numPrintedSoFar ) {
if ( nr == 1 ) nr = 0;
// print breakout tables here for distance matrix
// final score calc
char tmp[1024];
SafeBuf ft(tmp, 1024);;
StackBuf<1024> ft;
// put in a hidden div so you can unhide it
if ( si->m_format == FORMAT_HTML )
@ -5259,8 +5253,7 @@ static bool printMenu ( SafeBuf *sb , int32_t menuNum , HttpRequest *hr ) {
// . add our cgi to the original url
// . so if it has &qlang=de and they select &qlang=en
// we have to replace it... etc.
char tmp2[512];
SafeBuf newUrl(tmp2, 512);
StackBuf<512> newUrl;
replaceParm ( mi->m_cgi , &newUrl , hr );
newUrl += '\0';

@ -1053,11 +1053,10 @@ static bool printAddUrlHomePage ( SafeBuf &sb , const char *url , HttpRequest *r
// . call g_httpServer.sendDynamicPage() to send it
bool sendPageRoot ( TcpSocket *s , HttpRequest *r, char *cookie ) {
// don't allow pages bigger than 128k in cache
char buf [ 10*1024 ];//+ MAX_QUERY_LEN ];
// a ptr into "buf"
//char *p = buf;
//char *pend = buf + 10*1024 + MAX_QUERY_LEN - 100 ;
SafeBuf sb(buf, 10*1024 );//+ MAX_QUERY_LEN);
StackBuf<10*1024> sb;//+ MAX_QUERY_LEN);
// print bgcolors, set focus, set font style
//p = g_httpServer.printFocus ( p , pend );
//p = g_httpServer.printColors ( p , pend );
@ -1435,8 +1434,7 @@ static void doneInjectingWrapper3 ( void *st ) {
// printUrl = false;
// page is not more than 32k
char buf[1024*32+MAX_URL_LEN*2];
SafeBuf sb(buf, 1024*32+MAX_URL_LEN*2);
StackBuf<1024*32+MAX_URL_LEN*2> sb;
//char rawbuf[1024*8];
//SafeBuf rb(rawbuf, 1024*8);

@ -23,8 +23,7 @@ static void printUdpTable (SafeBuf *p, const char *title, const UdpServer *serv
// . call g_httpServer.sendDynamicPage() to send it
bool sendPageSockets ( TcpSocket *s , HttpRequest *r ) {
// don't allow pages bigger than 128k in cache
char buf [ 128*1024 ];
SafeBuf p(buf, 128*1024);
StackBuf<128*1024> p;
int32_t collLen = 0;
const char *coll = r->getString( "c", &collLen );
char tmp_coll[MAX_COLL_LEN+1];

@ -32,8 +32,7 @@ static const char *thread_type_name(thread_type_t tt) {
bool sendPageThreads ( TcpSocket *s , HttpRequest *r ) {
char buf [ 64*1024 ];
SafeBuf p(buf, 64*1024);
StackBuf<64*1024> p;
g_pages.printAdminTop ( &p , s , r );

@ -979,8 +979,7 @@ bool printSitePatternExamples ( SafeBuf *sb , HttpRequest *hr );
// which is called by HttpServer::sendReply(s,r) when it gets an http request
bool Parms::sendPageGeneric ( TcpSocket *s , HttpRequest *r ) {
char buf [ 128000 ];
SafeBuf stackBuf(buf,128000);
StackBuf<128000> stackBuf;
SafeBuf *sb = &stackBuf;
@ -1739,8 +1738,7 @@ bool Parms::printParm( SafeBuf* sb,
}
// if parm value is not defaut, use orange!
char rr[1024];
SafeBuf val1(rr,1024);
StackBuf<1024> val1;
if ( m->m_type != TYPE_FILEUPLOADBUTTON )
m->printVal ( &val1 , collnum , j ); // occNum );
// test it
@ -2915,8 +2913,7 @@ bool Parms::saveToXml ( char *THIS , char *f , char objType ) {
// print into buffer
// "seeds" can be pretty big so go with safebuf now
// fix so if we core in malloc/free we can still save conf
char tmpbuf[200000];
SafeBuf sb(tmpbuf,200000);
StackBuf<200000> sb;
//char *p = buf;
//char *pend = buf + MAX_CONF_SIZE;
//int32_t n ;

@ -862,8 +862,7 @@ bool Process::shutdown2() {
// make a file called 'cleanexit' so bash keep alive loop will stop
// because bash does not get the correct exit code, 0 in this case,
// even though we explicitly say 'exit(0)' !!!! poop
char tmp[128];
SafeBuf cleanFileName(tmp,128);
StackBuf<128> cleanFileName;
cleanFileName.safePrintf("%s/cleanexit",g_hostdb.m_dir);
SafeBuf nothing;
// returns # of bytes written, -1 if could not create file

@ -297,8 +297,7 @@ int32_t SafeBuf::dumpToFile(const char *filename ) const {
int32_t SafeBuf::safeSave(const char *filename) const {
// first write to tmp file
char tmp[1024];
SafeBuf fn(tmp,1024);
StackBuf<1024> fn;
fn.safePrintf( "%s.saving",filename );
int32_t fd = open ( fn.getBufStart() ,

@ -2670,8 +2670,7 @@ char *XmlDoc::hashJSONFields2 ( HashTableX *table ,
JsonItem *ji = jp->getFirstItem();
char nb[1024];
SafeBuf nameBuf(nb,1024);
StackBuf<1024> nameBuf;
//int32_t totalHash32 = 0;

@ -4137,8 +4137,7 @@ static void dumpTagdb(const char *coll, int32_t startFileNum, int32_t numFiles,
Tag *tag = (Tag *)rec;
// print the version and site
char tmpBuf[1024];
SafeBuf sb(tmpBuf, 1024);
StackBuf<1024> sb;
bool match = false;