From 061ffda5457df3711ec9ca4f20da1fc8b5330dec Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 15 Nov 2010 11:57:39 +0100 Subject: [PATCH] checked/changed all sprintf calls --- src/common/rclconfig.cpp | 6 ++++-- src/index/beaglequeue.cpp | 2 +- src/index/fsindexer.cpp | 2 +- src/index/rclmonrcv.cpp | 2 +- src/internfile/mh_mail.cpp | 2 +- src/internfile/mh_text.cpp | 2 +- src/query/docseqhist.cpp | 4 ++-- src/query/reslistpager.h | 6 ++++++ src/rcldb/rcldb.cpp | 3 ++- src/utils/circache.cpp | 6 ++++-- src/utils/debuglog.cpp | 10 +++++----- src/utils/netcon.cpp | 4 ++-- src/utils/readfile.cpp | 2 +- 13 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index a2a6d4fd..fd546ee8 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -23,6 +23,7 @@ static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.62 2008-10-08 16:15:22 dockes E #include #include #include +#include #include #include @@ -959,9 +960,10 @@ static int ncffiles = sizeof(configfiles) / sizeof(char *); bool RclConfig::initUserConfig() { // Explanatory text - char blurb[sizeof(blurb0)+1025]; + const int bs = sizeof(blurb0)+PATH_MAX+1; + char blurb[bs]; string exdir = path_cat(m_datadir, "examples"); - sprintf(blurb, blurb0, exdir.c_str()); + snprintf(blurb, bs, blurb0, exdir.c_str()); // Use protective 700 mode to create the top configuration // directory: documents can be reconstructed from index data. diff --git a/src/index/beaglequeue.cpp b/src/index/beaglequeue.cpp index df987b64..c011d412 100644 --- a/src/index/beaglequeue.cpp +++ b/src/index/beaglequeue.cpp @@ -398,7 +398,7 @@ BeagleQueueIndexer::processone(const string &path, make_udi(udipath, "", udi); LOGDEB(("BeagleQueueIndexer: prc1: udi [%s]\n", udi.c_str())); - char ascdate[20]; + char ascdate[30]; sprintf(ascdate, "%ld", long(stp->st_mtime)); // We only process bookmarks or text/html and text/plain files. diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index e771a97d..ec73769a 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -399,7 +399,7 @@ FsIndexer::processone(const std::string &fn, const struct stat *stp, make_udi(fn, "", parent_udi); Rcl::Doc doc; const string plus("+"); - char ascdate[20]; + char ascdate[30]; sprintf(ascdate, "%ld", long(stp->st_mtime)); FileInterner::Status fis = FileInterner::FIAgain; diff --git a/src/index/rclmonrcv.cpp b/src/index/rclmonrcv.cpp index f206013c..e2878d1b 100644 --- a/src/index/rclmonrcv.cpp +++ b/src/index/rclmonrcv.cpp @@ -242,7 +242,7 @@ const char *RclFAM::event_name(int code) "FAMExists", "FAMEndExist" }; - static char unknown_event[20]; + static char unknown_event[30]; if (code < FAMChanged || code > FAMEndExist) { sprintf(unknown_event, "unknown (%d)", code); diff --git a/src/internfile/mh_mail.cpp b/src/internfile/mh_mail.cpp index f5c5d8e8..8866a5f6 100644 --- a/src/internfile/mh_mail.cpp +++ b/src/internfile/mh_mail.cpp @@ -288,7 +288,7 @@ bool MimeHandlerMail::processAttach() } // Ipath - char nbuf[10]; + char nbuf[20]; sprintf(nbuf, "%d", m_idx); m_metaData["ipath"] = nbuf; diff --git a/src/internfile/mh_text.cpp b/src/internfile/mh_text.cpp index 7cdc2fbd..5451a58b 100644 --- a/src/internfile/mh_text.cpp +++ b/src/internfile/mh_text.cpp @@ -140,7 +140,7 @@ bool MimeHandlerText::next_document() // first chunk). This is a hack. The right thing to do would // be to use a different mtype for files over the page size, // and keep text/plain only for smaller files. - char buf[20]; + char buf[30]; sprintf(buf, "%lld", (long long)(m_offs - m_text.length())); if (m_offs - m_text.length() != 0) m_metaData["ipath"] = buf; diff --git a/src/query/docseqhist.cpp b/src/query/docseqhist.cpp index 71262b05..d79cb182 100644 --- a/src/query/docseqhist.cpp +++ b/src/query/docseqhist.cpp @@ -35,8 +35,8 @@ static char rcsid[] = "@(#$Id: docseqhist.cpp,v 1.4 2008-09-29 08:59:20 dockes E // The U distinguishes udi-based entries from older fn+ipath ones bool RclDHistoryEntry::encode(string& value) { - char chartime[20]; - sprintf(chartime, "%ld", unixtime); + char chartime[30]; + sprintf(chartime,"%ld", unixtime); string budi; base64_encode(udi, budi); value = string("U ") + string(chartime) + " " + budi; diff --git a/src/query/reslistpager.h b/src/query/reslistpager.h index 5ac04fa8..25b530a6 100644 --- a/src/query/reslistpager.h +++ b/src/query/reslistpager.h @@ -75,6 +75,12 @@ public: { return append(data); } + // Translation function. This is reimplemented in the qt reslist + // object For this to work, the strings must be duplicated inside + // reslist.cpp (see the QT_TR_NOOP in there). Very very unwieldy. + // To repeat: any change to a string used with trans() inside + // reslistpager.cpp must be reflected in the string table inside + // reslist.cpp for translation to work. virtual string trans(const string& in); virtual string detailsLink(); virtual const string &parFormat(); diff --git a/src/rcldb/rcldb.cpp b/src/rcldb/rcldb.cpp index ed4ab244..08e26d5d 100644 --- a/src/rcldb/rcldb.cpp +++ b/src/rcldb/rcldb.cpp @@ -988,7 +988,8 @@ bool Db::addOrUpdate(const string &udi, const string &parent_udi, doc.dmtime.c_str()); struct tm *tm = localtime(&mtime); char buf[9]; - sprintf(buf, "%04d%02d%02d",tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday); + snprintf(buf, 9, "%04d%02d%02d", + tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday); newdocument.add_term("D" + string(buf)); // Date (YYYYMMDD) buf[6] = '\0'; newdocument.add_term("M" + string(buf)); // Month (YYYYMM) diff --git a/src/utils/circache.cpp b/src/utils/circache.cpp index fcf2b16d..33a9b6f7 100644 --- a/src/utils/circache.cpp +++ b/src/utils/circache.cpp @@ -391,7 +391,8 @@ public: { char bf[CIRCACHE_HEADER_SIZE]; memset(bf, 0, CIRCACHE_HEADER_SIZE); - sprintf(bf, headerformat, d.dicsize, d.datasize, d.padsize, d.flags); + snprintf(bf, CIRCACHE_HEADER_SIZE, + headerformat, d.dicsize, d.datasize, d.padsize, d.flags); if (lseek(m_fd, offset, 0) != offset) { m_reason << "CirCache::weh: lseek(" << offset << ") failed: errno " << errno; @@ -1000,7 +1001,8 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf, char head[CIRCACHE_HEADER_SIZE]; memset(head, 0, CIRCACHE_HEADER_SIZE); - sprintf(head, headerformat, dic.size(), datalen, npadsize, flags); + snprintf(head, CIRCACHE_HEADER_SIZE, + headerformat, dic.size(), datalen, npadsize, flags); struct iovec vecs[3]; vecs[0].iov_base = head; vecs[0].iov_len = CIRCACHE_HEADER_SIZE; diff --git a/src/utils/debuglog.cpp b/src/utils/debuglog.cpp index c3323459..8f759ad2 100644 --- a/src/utils/debuglog.cpp +++ b/src/utils/debuglog.cpp @@ -182,12 +182,12 @@ static bool fileInFiles(const string& file) #ifdef _WINDOWS #include -static void datestring(char *d) { +static void datestring(char *d, int sz) { SYSTEMTIME buf; GetLocalTime(&buf); int year = buf.wYear % 100; - sprintf(d, "%02d%02d%02d%02d%02d%02d", year, int(buf.wMonth), + snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, int(buf.wMonth), int(buf.wDay), int(buf.wHour), int(buf.wMinute), int(buf.wSecond)); } #define vsnprintf _vsnprintf @@ -195,13 +195,13 @@ static void datestring(char *d) { #else // !WINDOWS -> #include -static void datestring(char *d) +static void datestring(char *d, int sz) { struct tm *tmp; time_t tim = time((time_t)0); tmp = localtime(&tim); int year = tmp->tm_year % 100; - sprintf(d, "%02d%02d%02d%02d%02d%02d", year, tmp->tm_mon+1, + snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, tmp->tm_mon+1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } @@ -220,7 +220,7 @@ DebugLog::prolog(int lev, const char *f, int line) } if (dodate) { char dts[100]; - datestring(dts); + datestring(dts, 100); writer->put(dts); } char buf[100]; diff --git a/src/utils/netcon.cpp b/src/utils/netcon.cpp index 757ae3f6..f997ee19 100644 --- a/src/utils/netcon.cpp +++ b/src/utils/netcon.cpp @@ -389,7 +389,7 @@ int NetconData::send(const char *buf, int cnt, int expedited) // Note: byte count may be different from cnt if fd is non-blocking if (ret < 0) { - char fdcbuf[10];sprintf(fdcbuf, "%d", m_fd); + char fdcbuf[20];sprintf(fdcbuf, "%d", m_fd); LOGSYSERR("NetconData::send", "send", fdcbuf); } return ret; @@ -453,7 +453,7 @@ int NetconData::receive(char *buf, int cnt, int timeo) } m_didtimo = 0; if ((cnt = read(m_fd, buf + fromibuf, cnt)) < 0) { - char fdcbuf[10];sprintf(fdcbuf, "%d", m_fd); + char fdcbuf[20];sprintf(fdcbuf, "%d", m_fd); LOGSYSERR("NetconData::receive", "read", fdcbuf); return -1; } diff --git a/src/utils/readfile.cpp b/src/utils/readfile.cpp index 39850fbf..bb5df6d0 100644 --- a/src/utils/readfile.cpp +++ b/src/utils/readfile.cpp @@ -49,7 +49,7 @@ static void caterrno(string *reason, const char *what, int _errno) if (reason) { reason->append(what); reason->append(": errno: "); - char nbuf[10]; + char nbuf[20]; sprintf(nbuf, "%d", _errno); reason->append(nbuf); reason->append(" : ");