1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-01-25 09:34:11 +00:00

[patch] Unbreak port: archivers/libcabinet

This port did not build with gcc 3.3.1. I also fixed a
	possible buffer overflow (they used gets() to read from
	stdin).

	Please review the patch file ``patch-cftypes.cpp'' with
	extra care, since I am not sure whether this makes sense
	(2 positions in the file, marked with ``TODO'' - thanks.

Also added some lines in cftypes.cpp to overcome the absence of
values.h on -current.

PR:		ports/55767
Submitted by:	Simon Barner <barner@in.tum.de>
This commit is contained in:
Edwin Groothuis 2003-08-31 13:09:31 +00:00
parent 26fc57a5c4
commit 8a8b31d05c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=88198
15 changed files with 298 additions and 25 deletions

View File

@ -19,12 +19,6 @@ INSTALLS_SHLIB= yes
SRCFILE= ${WRKSRC}/listcab.cpp
PROGFILE= ${SRCFILE:S/.cpp$//}
.include <bsd.port.pre.mk>
.if ${OSVERSION} >= 500035
BROKEN= "Does not compile on 5.0"
.endif
post-build:
${CXX} ${CXXFLAGS} -o ${PROGFILE} ${SRCFILE} -L${WRKSRC} -lcabinet
@ -34,4 +28,4 @@ pre-install:
post-install:
${INSTALL_PROGRAM} ${PROGFILE} ${PREFIX}/bin
.include <bsd.port.post.mk>
.include <bsd.port.mk>

View File

@ -0,0 +1,19 @@
--- Makefile.orig Tue Aug 19 18:15:11 2003
+++ Makefile Tue Aug 19 18:33:06 2003
@@ -0,0 +1,16 @@
+NOPROFILE= true
+CXXFLAGS+= -Wno-deprecated
+LIB= cabinet
+LIBDIR= ${PREFIX}/lib
+INCSDIR= ${PREFIX}/include/cabinet
+INCDIR= ${INCSDIR} # for pre-bsd.incs.mk API
+SHLIB_MAJOR= 1
+SHLIB_MINOR= 0
+SRCS= bstring.cpp cfcreate.cpp cfdblock.cpp cffdrmgr.cpp cffile.cpp \
+ cffolder.cpp cfheader.cpp cfreader.cpp cftypes.cpp object.cpp
+INCS= bstring.h cfcreate.h cfdblock.h cffdrmgr.h cffile.h cffolder.h \
+ cfheader.h cfreader.h cftypes.h darray.h dos_comp.h object.hpp \
+ queue.hpp
+LDADD= -lz
+
+.include <bsd.lib.mk>

View File

@ -0,0 +1,11 @@
--- bstring.cpp.orig Sun Aug 31 05:49:53 2003
+++ bstring.cpp Sun Aug 31 05:49:53 2003
@@ -91,7 +91,7 @@
b_string b_string::operator + (const char* s)
{
- b_string temp = str;
+ b_string temp (str);
return temp += s;
}

View File

@ -0,0 +1,12 @@
--- bstring.h.orig Tue Aug 19 18:15:26 2003
+++ bstring.h Tue Aug 19 18:16:08 2003
@@ -28,6 +28,9 @@
#include <fstream.h>
#include "dos_comp.h"
+using std::ostream;
+using std::istream;
+
//////////////////////////////////////////////////////////////////////////////
class b_string

View File

@ -0,0 +1,38 @@
--- cfcreate.cpp.orig Sun Oct 24 13:29:53 1999
+++ cfcreate.cpp Tue Aug 19 21:16:05 2003
@@ -29,6 +29,8 @@
#include <unistd.h>
#endif
+using std::ios;
+
///////////////////////////////////////***************************************
int cfc_fileinfo::write_entry(ostream& out)
@@ -129,7 +131,7 @@
}
}
- if(fstat(in.rdbuf()->fd(), &statbuf) != 0) return FSTAT_FAILURE;
+ if(stat(fname, &statbuf) != 0) return FSTAT_FAILURE;
#ifndef unix
if(getftime(in.rdbuf()->fd(), &datetime) != 0) return GETTIME_FAILURE;
#endif
@@ -194,7 +196,7 @@
unprocessed_data = NULL; // Reset buffer holder
unprocessed_data_len = 0u;
- if(in.read(buf + bytesread, len - bytesread).bad())
+ if(in.read((char*)buf + bytesread, len - bytesread).bad())
{
delete[] buf;
buf = NULL;
@@ -272,7 +274,7 @@
return WRITE_ERROR;
}
- tempfile->write(compdata, blockinfo.compressed_len);
+ tempfile->write((char*)compdata, blockinfo.compressed_len);
processed_bytes += sizeof(blockinfo) + blockinfo.compressed_len;
if(compdata != data) delete[] compdata; // If buffer was allocated, free it
data_blocks++; // Incriment block counter

View File

@ -0,0 +1,20 @@
--- cfdblock.cpp.orig Tue Aug 19 18:22:14 2003
+++ cfdblock.cpp Tue Aug 19 18:23:24 2003
@@ -124,7 +124,7 @@
ra_size = cab_header.get_datablock_ra_size();
reserved_area = new byte[ra_size];
- if(in.read(reserved_area, ra_size).bad())
+ if(in.read((char*)reserved_area, ra_size).bad())
{
return (in.fail()) ? READ_ERROR : UNEXPECTED_EOF;
}
@@ -154,7 +154,7 @@
if(ra_size) // If reserve area, write it
{
- if(out.write(reserved_area, ra_size).fail()) return WRITE_ERROR;
+ if(out.write((char*)reserved_area, ra_size).fail()) return WRITE_ERROR;
}
// write data to stream
// if(out.write(compressed_data, compressed_size).bad()) return WRITE_ERROR;

View File

@ -0,0 +1,9 @@
--- cffile.h.orig Sun Aug 31 05:54:08 2003
+++ cffile.h Sun Aug 31 05:54:10 2003
@@ -161,4 +161,4 @@
////////////////////////////////////////////////////////////////////////////////
-#endif
\ No newline at end of file
+#endif

View File

@ -0,0 +1,20 @@
--- cffolder.cpp.orig Tue Aug 19 18:23:48 2003
+++ cffolder.cpp Tue Aug 19 18:24:14 2003
@@ -70,7 +70,7 @@
ra_size = cab_header.get_folder_ra_size();
reserved_area = new byte[ra_size];
- if(in.read(reserved_area, ra_size).bad())
+ if(in.read((char*)reserved_area, ra_size).bad())
{
return (in.fail()) ? READ_ERROR : UNEXPECTED_EOF;
}
@@ -90,7 +90,7 @@
if(ra_size) // If reserved area present
{
- if(out.write(reserved_area, ra_size).fail()) { return WRITE_ERROR; }
+ if(out.write((char*)reserved_area, ra_size).fail()) { return WRITE_ERROR; }
}
return OK;

View File

@ -0,0 +1,10 @@
--- cffolder.h.orig Tue Aug 19 18:30:59 2003
+++ cffolder.h Tue Aug 19 18:31:08 2003
@@ -89,4 +89,5 @@
////////////////////////////////////////////////////////////////////////////////
-#endif
\ No newline at end of file
+#endif
+

View File

@ -0,0 +1,43 @@
--- cfheader.cpp.orig Tue Aug 19 18:24:35 2003
+++ cfheader.cpp Tue Aug 19 18:28:27 2003
@@ -24,11 +24,14 @@
#include "cfheader.h"
#ifdef unix
-#include <strstream.h>
+#include <strstream>
#else
#include <strstrea.h>
#endif
+using std::ostrstream;
+using std::ends;
+
////////////////////////////////////////****************************************
// Initializes a valid fixed cabinet header
@@ -127,7 +130,7 @@
{
reserved_area = new byte[cabinet_ra_size];
- if(in.read(reserved_area, cabinet_ra_size).bad())
+ if(in.read((char*)reserved_area, cabinet_ra_size).bad())
{
return (in.fail()) ? READ_ERROR : UNEXPECTED_EOF;
}
@@ -172,7 +175,7 @@
if(cabinet_ra_size > 0) // If has cabinet reserved area
{
- if(out.write(reserved_area, cabinet_ra_size).fail())
+ if(out.write((char*)reserved_area, cabinet_ra_size).fail())
{
return WRITE_ERROR;
}
@@ -210,4 +213,4 @@
////////////////////////////////////////****************************************
-#endif
\ No newline at end of file
+#endif

View File

@ -0,0 +1,11 @@
--- cfreader.cpp.orig Tue Aug 19 18:28:46 2003
+++ cfreader.cpp Tue Aug 19 18:29:10 2003
@@ -31,6 +31,8 @@
#include "cfheader.h"
#include "cfreader.h"
+using std::ios;
+
////////////////////////////////////////****************************************
int cabinet_reader::open(const char* fname)

View File

@ -1,47 +1,70 @@
$FreeBSD$
--- cftypes.cpp 2002/10/01 11:38:22 1.1
+++ cftypes.cpp 2002/10/01 11:39:37
@@ -10,7 +10,7 @@
--- cftypes.cpp.orig Sat Oct 23 23:13:29 1999
+++ cftypes.cpp Sun Aug 31 06:07:25 2003
@@ -10,7 +10,15 @@
#ifndef __CFTYPES_CPP__
#define __CFTYPES_CPP__
-#include <values.h>
+#ifndef MAXSHORT
+#define BITSPERBYTE 8
+#define BITS(type) (BITSPERBYTE * (int)sizeof(type))
+#define SHORTBITS BITS(int16_t)
+#define MINSHORT ((int16_t)(1 << (SHORTBITS - 1)))
+#define MAXSHORT ((int16_t)~MINSHORT)
+#endif
+
+#include <limits.h>
#include <fstream.h>
#include "zlib.h"
#include "cftypes.h"
@@ -138,12 +138,12 @@
@@ -138,15 +146,20 @@
int io_read(istream& in, byte* buf, word len)
{
- while(len > MAXINT)
+ while(len > INT_MAX)
+ // replaced MAXINT with MAXSHORT, since len is of type
+ // word == unsigned short int
+ //
+ // TODO: please review this, since IMO the while-loop is
+ // never entered
+ while (len > MAXSHORT)
{
- if(in.read(buf, MAXINT).bad())
+ if(in.read(buf, INT_MAX).bad())
+ if(in.read((char*)buf, MAXSHORT).bad())
return (in.fail()) ? READ_ERROR : UNEXPECTED_EOF;
- len -= (word) MAXINT;
- buf += (word) MAXINT;
+ len -= (word) INT_MAX;
+ buf += (word) INT_MAX;
+ len -= (word) MAXSHORT;
+ buf += (word) MAXSHORT;
}
return (in.read(buf, (int) len).bad())
@@ -154,11 +154,11 @@
- return (in.read(buf, (int) len).bad())
+ return (in.read((char*)buf, (int) len).bad())
? (in.fail()) ? READ_ERROR : UNEXPECTED_EOF : OK;
}
@@ -154,14 +167,19 @@
int io_write(ostream& out, const byte* buf, word len)
{
- while(len > MAXINT)
+ while(len > INT_MAX)
+ // replaced MAXINT with MAXSHORT, since len is of type
+ // word == unsigned short int
+ //
+ // TODO: please review this, since IMO the while-loop is
+ // never entered
+ while(len > MAXSHORT)
{
- if(out.write(buf, MAXINT).fail()) return WRITE_ERROR;
- len -= (word) MAXINT;
- buf += (word) MAXINT;
+ if(out.write(buf, INT_MAX).fail()) return WRITE_ERROR;
+ len -= (word) INT_MAX;
+ buf += (word) INT_MAX;
+ if(out.write((char*)buf, MAXSHORT).fail()) return WRITE_ERROR;
+ len -= (word) MAXSHORT;
+ buf += (word) MAXSHORT;
}
return (out.write(buf, (int) len).fail()) ? WRITE_ERROR : OK;
- return (out.write(buf, (int) len).fail()) ? WRITE_ERROR : OK;
+ return (out.write((char*)buf, (int) len).fail()) ? WRITE_ERROR : OK;
}
//*****************************************************************************/

View File

@ -0,0 +1,12 @@
--- cftypes.h.orig Tue Aug 19 18:17:55 2003
+++ cftypes.h Tue Aug 19 18:18:54 2003
@@ -18,6 +18,9 @@
#include <fstream.h>
+using std::istream;
+using std::ostream;
+
typedef unsigned char byte;
typedef unsigned short int word;
typedef unsigned long int dword;

View File

@ -0,0 +1,9 @@
--- darray.h.orig Sun Aug 31 05:55:31 2003
+++ darray.h Sun Aug 31 05:55:32 2003
@@ -155,4 +155,4 @@
///////////////////////////////////////***************************************
-#endif
\ No newline at end of file
+#endif

View File

@ -0,0 +1,42 @@
--- listcab.cpp.orig Tue Aug 19 20:42:27 2003
+++ listcab.cpp Tue Aug 19 20:49:27 2003
@@ -47,13 +47,19 @@
cerr << "New Folder Error: " << retval << endl;
return 1;
}
-
+ int n;
do{
cout << "Enter filename: ";
- gets(filename);
-
- if(strlen(filename) > 0)
+ fgets(filename, 256, stdin);
+ n = strlen (filename);
+
+ if (n == 1 && filename[0] == '\n')
+ n = 0;
+
+ if(n > 0)
{
+ if (filename[n-1] == '\n')
+ filename[n-1] = '\0';
if((retval = cab.add_file(filename)) != OK)
{
perror("read");
@@ -62,10 +68,13 @@
return 1;
}
}
- }while(strlen(filename) > 0);
+ }while(n > 0);
cout << "Enter filename for cabinet: ";
- gets(filename);
+ fgets(filename, 256, stdin);
+ n = strlen (filename);
+ if (n > 0 && filename[n-1] == '\n')
+ filename[n-1] = '\0';
if((retval = cab.close(filename)) != OK)
{