Bug 29325

Summary: Dbview contains an error, because of which at review dbf files with text boxes which length of 255 characters , the program crashed.
Product: Ports & Packages Reporter: Alexander Trapeznikov <infoteacher>
Component: Individual Port(s)Assignee: Ade Lovett <ade>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Alexander Trapeznikov 2001-07-30 12:20:04 UTC
Current version dbview (1.0.3) contains an error, because of which at
review dbf files with text boxes which length of 255 characters, the program
crashed. As value FF becomes-1, and should be 255.

How-To-Repeat: Patch for db_dump.c:

Index: db_dump.c
===================================================================
RCS file: /usr/local/cvsroot/dbview/src/db_dump.c,v
retrieving revision 1.1
retrieving revision 2.0
diff -r1.1 -r2.0
57c57
< #include <malloc.h>
---
> #include <stdlib.h>
166a167,170
>     int		    len;
>     char	    *info;
>     char	    *lang;
>     char	    *cdx;
174c178
<     if( !(dbhead.version==3 || dbhead.version==0x83) ) {
---
>     if ( ! ( dbhead.version==0x03 || dbhead.version==0x83 || dbhead.version==0x04 || dbhead.version==0x05 || dbhead.version==0x8b || dbhead.version==0xf5 ) ) {
176,177c180,181
< 	if(dbhead.version==0x8b ) {
< 	    printf ("dBase IV - partially known...\n");
---
> 	if (dbhead.version==0x8e ) {
> 	    printf ("dBase IV or dBase V with SQL table - partially known...\n");
178a183,185
> 	if (dbhead.version==0x43 || dbhead.version==0xb3){
> 	    printf ("FlagShip - partially known...\n");
>         }
180a188,207
>     if (dbhead.version==0x03){
>  	info="Plain dbf, dBaseIII+";
>     }
>     if (dbhead.version==0x04){
>  	info="Plain dbf, dBaseIV+";
>     }
>     if (dbhead.version==0x05){
>  	info="Plain dbf, dBaseV or FoxPro";
>     }
>     if (dbhead.version==0x83){
>  	info="dBaseIII+ w/memo";
>     }
>     if (dbhead.version==0x8b){
>  	info="dBaseIV+ w/memo";
>     }
>     if (dbhead.version==0xf5){
>  	info="FoxPro w/memo";
>     }
> 
>     fields=(dbhead.header-1)/32-1;
181a209,229
>     if (dbhead.excdx){
> 	cdx="Yes";
>     }
>     else{
> 	cdx="No";
>     }
>     if (dbhead.language==101){
> 	lang="DOS 866";
>     }
>     else if (dbhead.language==2){
> 	lang="WIN 1251";
>     }
>     else if (dbhead.language==2){
> 	lang="DOS 850 Multi ling";
>     }
>     else if (dbhead.language==1){
> 	lang="DOS 437 USA";
>     }
>     else{
> 	lang="Unknow";
>     }
183,187c231,238
< 	printf("File version  : %d\n",dbhead.version);
< 	printf("Last update   : %02d/%02d/%2d\n", dbhead.l_update[1],dbhead.l_update[2],dbhead.l_update[0]);
< 	printf("Number of recs: %ld\n",dbhead.count);
< 	printf("Header length : %d\n",dbhead.header);
< 	printf("Record length : %d\n",dbhead.lrecl);
---
> 	printf("File version    : %d, %s\n",dbhead.version,info);
> 	printf("Last update     : %02d/%02d/%2d\n", dbhead.l_update[1],dbhead.l_update[2],dbhead.l_update[0]+1900);
> 	printf("Number of recs  : %ld\n",dbhead.count);
> 	printf("Header length   : %d\n",dbhead.header);
> 	printf("Record length   : %d\n",dbhead.lrecl);
> 	printf("Exist index cdx : %s\n",cdx);
> 	printf("Language ID     : %s\n",lang);
> 	printf("Count fields    : %d\n\n",fields);
191,193c242
<  
<     fields=(dbhead.header-1)/32-1;
<     
---
> 
206a256,261
> 	    if (fld->length==-1){
> 		len=fld->length+256;
> 	    }
> 	    else{
> 		len=fld->length;
> 	    }
208c263
< 		   fld->length,fld->dec_point);
---
> 		   len,fld->dec_point);
230c285
<  
---
>     lseek(dbfile,dbhead.header,SEEK_SET);
256c311,312
<  
---
>     int		len;
> 
259,260c315,322
<         memcpy(buf_work,temp->data,temp->fld->length);
<         buf_work[temp->fld->length] = '\0';
---
> 	if (temp->fld->length==-1){
> 	  len=temp->fld->length+256;
>         }
> 	else{
> 	  len=temp->fld->length;
>         }
>         memcpy(buf_work,temp->data,len);
>         buf_work[len] = '\0';

Patch for db_dump.h:
Index: db_dump.h
===================================================================
RCS file: /usr/local/cvsroot/dbview/src/db_dump.h,v
retrieving revision 1.1
retrieving revision 2.0
diff -r1.1 -r2.0
51c51,54
<     unsigned char	version;		/* 03 for dbIII and 83 for dbIII w/memo file */
---
>     unsigned char	version;		/* 0x03,0x04,0x05-DBIII+/DBIV */
> 						/* 0x83 - DBIII+ w/memo;*/
> 						/* 0xF5-FoxPro w/memo;*/
> 						/* 0x8B-DBIV w/memo file */
61c64,67
<     unsigned char   reserv[20];
---
>     unsigned char   reserv1[16];
>     unsigned char   excdx;                      /* 1-exist cdx file, 0 - nonexist*/
>     unsigned char   language;                   /* language driver:0x01 - 437 DOS;0x02 - 850 DOS; 0x03 - 1251; 0x00 - ignored*/
>     unsigned char   reserv2[2];
63,68c69,82
< 
< #define DB_FLD_CHAR  'C'
< #define DB_FLD_NUM   'N'
< #define DB_FLD_LOGIC 'L'
< #define DB_FLD_MEMO  'M'
< #define DB_FLD_DATE  'D'
---
>  
> #define DB_FLD_CHAR     'C'
> #define DB_FLD_NUM      'N'
> #define DB_FLD_LOGIC    'L'
> #define DB_FLD_VARIABLE 'V'
> #define DB_FLD_MEMO     'M'
> #define DB_FLD_FLOAT    'F'
> #define DB_FLD_PICTURE  'P'
> #define DB_FLD_BINARY   'B'
> #define DB_FLD_GENERAL  'G'
> #define DB_FLD_SHINT    '2'
> #define DB_FLD_LINT     '4'
> #define DB_FLD_DOUBLE   '8'
> #define DB_FLD_DATE     'D'

Patch for dbview.c:

Index: dbview.c
===================================================================
RCS file: /usr/local/cvsroot/dbview/src/dbview.c,v
retrieving revision 1.1
retrieving revision 2.0
diff -r1.1 -r2.0
37c37
<     printf ("%s %s - %s, (c) 1996 by Martin Schulze\n", progname, version, longname);
---
>     printf ("%s %s - %s, (c) 1996 by Martin Schulze, Patched Alexander Trapeznikov, 2001 \n", progname, version, longname);
44c44
<     printf ("%s %s - %s, (c) 1996 by Martin Schulze\n", progname, version, longname);
---
>     printf ("%s %s - %s, (c) 1996 by Martin Schulze, Patched Alexander Trapeznikov, 2001 \n", progname, version, longname);
57c57
< void main (int argc, char **argv)
---
> int main (int argc, char **argv)
84a85
> /*	    printf ("DB_FL_BROWSE\n"); */
93a95
> /*	    printf ("DB_FL_DESCR\n"); */
99a102
> /*	    printf ("DB_FL_INFO\n"); */
102a106
> /*	    printf ("DB_FL_OMIT\n"); */
105a110
> /*	    printf ("DB_FL_RESERVE\n"); */
108a114
> /*	    printf ("DB_FL_TRIM\n"); */

Patch for version.c:

Index: version.c
===================================================================
RCS file: /usr/local/cvsroot/dbview/src/version.c,v
retrieving revision 1.1
retrieving revision 2.0
diff -r1.1 -r2.0
24c24
< char longname[] = "View dBase III files";
---
> char longname[] = "View dbf files";
26c26
< char version[] = "1.0.2";
---
> char version[] = "1.0.3.1";
Comment 1 Ade Lovett freebsd_committer freebsd_triage 2002-04-13 03:44:32 UTC
State Changed
From-To: open->feedback

I'll take care of this. 


Comment 2 Ade Lovett freebsd_committer freebsd_triage 2002-04-13 03:44:32 UTC
Responsible Changed
From-To: freebsd-ports->ade

Can you please resubmit your diff's in unified (diff -uN) format, which 
is what we use for patches in the ports/ tree, and I will commit it.
Comment 3 perisa 2002-05-28 22:41:58 UTC
Hi,

Alexander Trapeznikov created a new PR at 
http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/37186 which contains 
the unified diffs.

Can you take care of this?

Thanks

Marc
Comment 4 Ade Lovett freebsd_committer freebsd_triage 2002-05-28 22:53:20 UTC
State Changed
From-To: feedback->closed

Superceded by ports/37186