X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dd0af4bb63747bc46e70e1e3212f49966cb2bbfc..952f4277280975bada5ab5019728449d41a80a1b:/src/common/tarstrm.cpp diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index 7b053df2ab..7eb827582e 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -230,7 +230,7 @@ wxUint32 wxTarHeaderBlock::SumField(int id) } bool wxTarHeaderBlock::Read(wxInputStream& in) -{ +{ bool ok = true; for (int id = 0; id < TAR_NUMFIELDS && ok; id++) @@ -268,7 +268,7 @@ wxTarNumber wxTarHeaderBlock::GetOctal(int id) bool wxTarHeaderBlock::SetOctal(int id, wxTarNumber n) { // set an octal field, return true if the number fits - char *field = Get(id); + char *field = Get(id); char *p = field + Len(id); *--p = 0; while (p > field) { @@ -314,7 +314,7 @@ bool wxTarHeaderBlock::SetPath(const wxString& name, wxMBConv& conv) for (;;) { fits = i < maxprefix && len - i <= maxname; - + if (!fits) { const char *p = strchr(mbName + i, '/'); if (p) @@ -336,7 +336,7 @@ bool wxTarHeaderBlock::SetPath(const wxString& name, wxMBConv& conv) return fits && !badconv; } - + ///////////////////////////////////////////////////////////////////////////// // Some helpers @@ -362,7 +362,8 @@ static wxString wxTarUserName(int uid) wxCharBuffer buf(bufsize); struct passwd pw; - if (getpwuid_r(uid, &pw, buf.data(), bufsize, &ppw) == 0) + memset(&pw, 0, sizeof(pw)); + if (getpwuid_r(uid, &pw, buf.data(), bufsize, &ppw) == 0 && pw.pw_name) return wxString(pw.pw_name, wxConvLibc); #else if ((ppw = getpwuid(uid)) != NULL) @@ -384,7 +385,8 @@ static wxString wxTarGroupName(int gid) wxCharBuffer buf(bufsize); struct group gr; - if (getgrgid_r(gid, &gr, buf.data(), bufsize, &pgr) == 0) + memset(&gr, 0, sizeof(gr)); + if (getgrgid_r(gid, &gr, buf.data(), bufsize, &pgr) == 0 && gr.gr_name) return wxString(gr.gr_name, wxConvLibc); #else if ((pgr = getgrgid(gid)) != NULL) @@ -627,7 +629,7 @@ int wxTarEntry::GetMode() const return m_Mode; else return m_Mode | 0111; - + } void wxTarEntry::SetMode(int mode) @@ -943,13 +945,13 @@ bool wxTarInputStream::ReadExtendedHeader(wxTarHeaderRecords*& recs) size_t recPos, recSize; bool ok = true; - for (recPos = 0; recPos < len; recPos += recSize) { + for (recPos = 0; recPos < len && ok; recPos += recSize) { char *pRec = buf.data() + recPos; char *p = pRec; // read the record size (byte count in ascii decimal) recSize = 0; - while (isdigit(*p)) + while (isdigit((unsigned char) *p)) recSize = recSize * 10 + *p++ - '0'; // validity checks @@ -983,7 +985,7 @@ bool wxTarInputStream::ReadExtendedHeader(wxTarHeaderRecords*& recs) if (value.empty()) recs->erase(key); else - (*recs)[key] = value; + (*recs)[key] = value; } if (!ok || recPos < len || size != lastread) { @@ -1032,7 +1034,7 @@ size_t wxTarInputStream::OnSysRead(void *buffer, size_t size) size_t lastread = m_parent_i_stream->Read(buffer, size).LastRead(); m_pos += lastread; - + if (m_pos >= m_size) { m_lasterror = wxSTREAM_EOF; } else if (!m_parent_i_stream->IsOk()) { @@ -1209,7 +1211,7 @@ bool wxTarOutputStream::Close() { if (!CloseEntry() || (m_tarsize == 0 && m_endrecWritten)) return false; - + memset(m_hdr, 0, sizeof(*m_hdr)); int count = (RoundUpSize(m_tarsize + 2 * TAR_BLOCKSIZE, m_BlockingFactor) - m_tarsize) / TAR_BLOCKSIZE; @@ -1246,7 +1248,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) *m_hdr->Get(TAR_TYPEFLAG) = char(entry.GetTypeFlag()); strcpy(m_hdr->Get(TAR_MAGIC), USTAR_MAGIC); - strcpy(m_hdr->Get(TAR_VERSION), USTAR_VERSION); + strcpy(m_hdr->Get(TAR_VERSION), USTAR_VERSION); SetHeaderString(TAR_LINKNAME, entry.GetLinkName()); SetHeaderString(TAR_UNAME, entry.GetUserName()); @@ -1255,7 +1257,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) if (~entry.GetDevMajor()) SetHeaderNumber(TAR_DEVMAJOR, entry.GetDevMajor()); if (~entry.GetDevMinor()) - SetHeaderNumber(TAR_DEVMINOR, entry.GetDevMinor()); + SetHeaderNumber(TAR_DEVMINOR, entry.GetDevMinor()); m_chksum = m_hdr->Sum(); m_hdr->SetOctal(TAR_CHKSUM, m_chksum); @@ -1286,7 +1288,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) strcpy(m_hdr2->Get(TAR_MTIME), m_hdr->Get(TAR_MTIME)); *m_hdr2->Get(TAR_TYPEFLAG) = 'x'; strcpy(m_hdr2->Get(TAR_MAGIC), USTAR_MAGIC); - strcpy(m_hdr2->Get(TAR_VERSION), USTAR_VERSION); + strcpy(m_hdr2->Get(TAR_VERSION), USTAR_VERSION); strcpy(m_hdr2->Get(TAR_UNAME), m_hdr->Get(TAR_UNAME)); strcpy(m_hdr2->Get(TAR_GNAME), m_hdr->Get(TAR_GNAME)); @@ -1310,7 +1312,7 @@ bool wxTarOutputStream::WriteHeaders(wxTarEntry& entry) m_badfit.c_str(), entry.GetName().c_str()); m_badfit.clear(); } - + m_hdr->Write(*m_parent_o_stream); m_tarsize += TAR_BLOCKSIZE; m_lasterror = m_parent_o_stream->GetLastError(); @@ -1324,7 +1326,7 @@ wxString wxTarOutputStream::PaxHeaderPath(const wxString& format, wxString d = path.BeforeLast(_T('/')); wxString f = path.AfterLast(_T('/')); wxString ret; - + if (d.empty()) d = _T(".");