Skip to content

Commit 3ac35bb

Browse files
committed
Fix crash when a line is not ended by \n.
modified: storage/connect/filamap.cpp Add specifying a password when reading zipped tables. modified: storage/connect/filamzip.cpp modified: storage/connect/filamzip.h modified: storage/connect/tabdos.cpp modified: storage/connect/tabdos.h Try Vaintroub suggestion modified: storage/connect/mysql-test/connect/t/jdbc.test
1 parent 5de5daa commit 3ac35bb

File tree

5 files changed

+64
-27
lines changed

5 files changed

+64
-27
lines changed

storage/connect/filamap.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,9 @@ int MAPFAM::SkipRecord(PGLOBAL g, bool header)
301301
PDBUSER dup = (PDBUSER)g->Activityp->Aptr;
302302

303303
// Skip this record
304-
while (*Mempos++ != '\n') ; // What about Unix ???
305-
306-
if (Mempos >= Top)
307-
return RC_EF;
304+
while (*Mempos++ != '\n') // What about Unix ???
305+
if (Mempos == Top)
306+
return RC_EF;
308307

309308
// Update progress information
310309
dup->ProgCur = GetPos();
@@ -320,7 +319,7 @@ int MAPFAM::SkipRecord(PGLOBAL g, bool header)
320319
/***********************************************************************/
321320
int MAPFAM::ReadBuffer(PGLOBAL g)
322321
{
323-
int rc, len;
322+
int rc, len, n = 1;
324323

325324
// Are we at the end of the memory
326325
if (Mempos >= Top) {
@@ -362,10 +361,14 @@ int MAPFAM::ReadBuffer(PGLOBAL g)
362361
Placed = false;
363362

364363
// Immediately calculate next position (Used by DeleteDB)
365-
while (*Mempos++ != '\n') ; // What about Unix ???
364+
while (*Mempos++ != '\n') // What about Unix ???
365+
if (Mempos == Top) {
366+
n = 0;
367+
break;
368+
} // endif Mempos
366369

367370
// Set caller line buffer
368-
len = (Mempos - Fpos) - 1;
371+
len = (Mempos - Fpos) - n;
369372

370373
// Don't rely on ENDING setting
371374
if (len > 0 && *(Mempos - 2) == '\r')
@@ -619,7 +622,9 @@ int MBKFAM::ReadBuffer(PGLOBAL g)
619622
} // endif's
620623

621624
// Immediately calculate next position (Used by DeleteDB)
622-
while (*Mempos++ != '\n') ; // What about Unix ???
625+
while (*Mempos++ != '\n') // What about Unix ???
626+
if (Mempos == Top)
627+
break;
623628

624629
// Set caller line buffer
625630
len = (Mempos - Fpos) - Ending;

storage/connect/filamzip.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ UNZIPUTL::UNZIPUTL(PSZ tgt, bool mul)
386386
{
387387
zipfile = NULL;
388388
target = tgt;
389+
pwd = NULL;
389390
fp = NULL;
390391
memory = NULL;
391392
size = 0;
@@ -401,6 +402,26 @@ UNZIPUTL::UNZIPUTL(PSZ tgt, bool mul)
401402
#endif
402403
} // end of UNZIPUTL standard constructor
403404

405+
UNZIPUTL::UNZIPUTL(PDOSDEF tdp)
406+
{
407+
zipfile = NULL;
408+
target = tdp->GetEntry();
409+
pwd = tdp->Pwd;
410+
fp = NULL;
411+
memory = NULL;
412+
size = 0;
413+
entryopen = false;
414+
multiple = tdp->GetMul();
415+
memset(fn, 0, sizeof(fn));
416+
417+
// Init the case mapping table.
418+
#if defined(__WIN__)
419+
for (int i = 0; i < 256; ++i) mapCaseTable[i] = toupper(i);
420+
#else
421+
for (int i = 0; i < 256; ++i) mapCaseTable[i] = i;
422+
#endif
423+
} // end of UNZIPUTL standard constructor
424+
404425
#if 0
405426
UNZIPUTL::UNZIPUTL(PZIPUTIL zutp)
406427
{
@@ -625,7 +646,7 @@ bool UNZIPUTL::openEntry(PGLOBAL g)
625646
if (rc != UNZ_OK) {
626647
sprintf(g->Message, "unzGetCurrentFileInfo64 rc=%d", rc);
627648
return true;
628-
} else if ((rc = unzOpenCurrentFile(zipfile)) != UNZ_OK) {
649+
} else if ((rc = unzOpenCurrentFilePassword(zipfile, pwd)) != UNZ_OK) {
629650
sprintf(g->Message, "unzOpen fn=%s rc=%d", fn, rc);
630651
return true;
631652
} // endif rc
@@ -675,15 +696,17 @@ void UNZIPUTL::closeEntry()
675696
UNZFAM::UNZFAM(PDOSDEF tdp) : MAPFAM(tdp)
676697
{
677698
zutp = NULL;
678-
target = tdp->GetEntry();
679-
mul = tdp->GetMul();
699+
tdfp = tdp;
700+
//target = tdp->GetEntry();
701+
//mul = tdp->GetMul();
680702
} // end of UNZFAM standard constructor
681703

682704
UNZFAM::UNZFAM(PUNZFAM txfp) : MAPFAM(txfp)
683705
{
684706
zutp = txfp->zutp;
685-
target = txfp->target;
686-
mul = txfp->mul;
707+
tdfp = txfp->tdfp;
708+
//target = txfp->target;
709+
//mul = txfp->mul;
687710
} // end of UNZFAM copy constructor
688711

689712
/***********************************************************************/
@@ -726,7 +749,7 @@ bool UNZFAM::OpenTableFile(PGLOBAL g)
726749
/*********************************************************************/
727750
/* Allocate the ZIP utility class. */
728751
/*********************************************************************/
729-
zutp = new(g) UNZIPUTL(target, mul);
752+
zutp = new(g) UNZIPUTL(tdfp);
730753

731754
// We used the file name relative to recorded datapath
732755
PlugSetPath(filename, To_File, Tdbp->GetPath());
@@ -841,17 +864,19 @@ void UNZFAM::CloseTableFile(PGLOBAL g, bool)
841864
UZXFAM::UZXFAM(PDOSDEF tdp) : MPXFAM(tdp)
842865
{
843866
zutp = NULL;
844-
target = tdp->GetEntry();
845-
mul = tdp->GetMul();
867+
tdfp = tdp;
868+
//target = tdp->GetEntry();
869+
//mul = tdp->GetMul();
846870
//Lrecl = tdp->GetLrecl();
847871
} // end of UZXFAM standard constructor
848872

849873
UZXFAM::UZXFAM(PUZXFAM txfp) : MPXFAM(txfp)
850874
{
851875
zutp = txfp->zutp;
852-
target = txfp->target;
853-
mul = txfp->mul;
854-
//Lrecl = txfp->Lrecl;
876+
tdfp = txfp->tdfp;
877+
//target = txfp->target;
878+
//mul = txfp->mul;
879+
//Lrecl = txfp->Lrecl;
855880
} // end of UZXFAM copy constructor
856881

857882
/***********************************************************************/
@@ -907,7 +932,7 @@ bool UZXFAM::OpenTableFile(PGLOBAL g)
907932
/* Allocate the ZIP utility class. */
908933
/*********************************************************************/
909934
if (!zutp)
910-
zutp = new(g)UNZIPUTL(target, mul);
935+
zutp = new(g)UNZIPUTL(tdfp);
911936

912937
// We used the file name relative to recorded datapath
913938
PlugSetPath(filename, To_File, Tdbp->GetPath());

storage/connect/filamzip.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class DllExport ZIPUTIL : public BLOCK {
4545
// Members
4646
zipFile zipfile; // The ZIP container file
4747
PSZ target; // The target file name
48+
PSZ pwd; // The ZIP file password
4849
//unz_file_info finfo; // The current file info
4950
PFBLOCK fp;
5051
//char *memory;
@@ -61,8 +62,8 @@ class DllExport ZIPUTIL : public BLOCK {
6162
class DllExport UNZIPUTL : public BLOCK {
6263
public:
6364
// Constructor
64-
UNZIPUTL(PSZ tgt, bool mul);
65-
//UNZIPUTL(UNZIPUTL *zutp);
65+
UNZIPUTL(PSZ tgt, bool mul);
66+
UNZIPUTL(PDOSDEF tdp);
6667

6768
// Implementation
6869
//PTXF Duplicate(PGLOBAL g) { return (PTXF) new(g)UNZFAM(this); }
@@ -80,6 +81,7 @@ class DllExport UNZIPUTL : public BLOCK {
8081
// Members
8182
unzFile zipfile; // The ZIP container file
8283
PSZ target; // The target file name
84+
PSZ pwd; // The ZIP file password
8385
unz_file_info finfo; // The current file info
8486
PFBLOCK fp;
8587
char *memory;
@@ -119,8 +121,9 @@ class DllExport UNZFAM : public MAPFAM {
119121
protected:
120122
// Members
121123
UNZIPUTL *zutp;
122-
PSZ target;
123-
bool mul;
124+
PDOSDEF tdfp;
125+
//PSZ target;
126+
//bool mul;
124127
}; // end of UNZFAM
125128

126129
/***********************************************************************/
@@ -147,8 +150,9 @@ class DllExport UZXFAM : public MPXFAM {
147150
protected:
148151
// Members
149152
UNZIPUTL *zutp;
150-
PSZ target;
151-
bool mul;
153+
PDOSDEF tdfp;
154+
//PSZ target;
155+
//bool mul;
152156
}; // end of UZXFAM
153157

154158
/***********************************************************************/

storage/connect/tabdos.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ DOSDEF::DOSDEF(void)
9898
Ofn = NULL;
9999
Entry = NULL;
100100
To_Indx = NULL;
101+
Pwd = NULL;
101102
Recfm = RECFM_VAR;
102103
Mapped = false;
103104
Zipped = false;
@@ -139,7 +140,8 @@ bool DOSDEF::DefineAM(PGLOBAL g, LPCSTR am, int)
139140
: false;
140141
Mulentries = GetBoolCatInfo("Mulentries", Mulentries);
141142
Append = GetBoolCatInfo("Append", false);
142-
}
143+
Pwd = GetStringCatInfo(g, "Password", NULL);
144+
} // endif Zipped
143145

144146
Desc = Fn = GetStringCatInfo(g, "Filename", NULL);
145147
Ofn = GetStringCatInfo(g, "Optname", Fn);

storage/connect/tabdos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class DllExport DOSDEF : public TABDEF { /* Logical table description */
7777
PSZ Fn; /* Path/Name of corresponding file */
7878
PSZ Ofn; /* Base Path/Name of matching index files*/
7979
PSZ Entry; /* Zip entry name or pattern */
80+
PSZ Pwd; /* Zip password */
8081
PIXDEF To_Indx; /* To index definitions blocks */
8182
RECFM Recfm; /* 0:VAR, 1:FIX, 2:BIN, 3:VCT, 6:DBF */
8283
bool Mapped; /* 0: disk file, 1: memory mapped file */

0 commit comments

Comments
 (0)