Skip to content

Commit 0fd354c

Browse files
starseekercshorler
authored andcommitted
Make sure BUFSIZ buffers have room for NULL
In case we do end up with buffers with contents at the BUFSIZ limit, make sure we leave room to set a null termination char. Not always clear where these buffers might get used or re-used, so just bump their size across the board.
1 parent fd8b7e3 commit 0fd354c

35 files changed

Lines changed: 139 additions & 139 deletions

cmake/schema_scanner/schemaScanner.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void writeLists( const char * schemaName, stringstream & eh, stringstream & ei,
220220

221221
cmLists.close();
222222

223-
char pwd[BUFSIZ] = {0};
223+
char pwd[BUFSIZ+1] = {0};
224224
if( getcwd( pwd, BUFSIZ ) ) {
225225
cout << pwd << "/" << shortName << endl;
226226
} else {

src/cleditor/STEPfile.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Severity STEPfile::ReadHeader( istream & in ) {
117117
int fileid;
118118
std::string keywd;
119119
char c = '\0';
120-
char buf [BUFSIZ];
120+
char buf [BUFSIZ+1];
121121

122122
std::string strbuf;
123123

@@ -442,7 +442,7 @@ int STEPfile::ReadData1( istream & in ) {
442442

443443
char c;
444444
int instance_count = 0;
445-
char buf[BUFSIZ];
445+
char buf[BUFSIZ+1];
446446
buf[0] = '\0';
447447
std::string tmpbuf;
448448

@@ -565,7 +565,7 @@ int STEPfile::ReadData2( istream & in, bool useTechCor ) {
565565
_warningCount = 0; // reset error count
566566

567567
char c;
568-
char buf[BUFSIZ];
568+
char buf[BUFSIZ+1];
569569
buf[0] = '\0';
570570
std::string tmpbuf;
571571

@@ -730,7 +730,7 @@ int STEPfile::FindDataSection( istream & in ) {
730730
}
731731

732732
int STEPfile::FindHeaderSection( istream & in ) {
733-
char buf[BUFSIZ];
733+
char buf[BUFSIZ+1];
734734
char * b = buf;
735735

736736
*b = '\0';
@@ -1150,7 +1150,7 @@ SDAI_Application_instance * STEPfile::ReadInstance( istream & in, ostream & out,
11501150
Severity sev = SEVERITY_NULL;
11511151

11521152
std::string tmpbuf;
1153-
char errbuf[BUFSIZ];
1153+
char errbuf[BUFSIZ+1];
11541154
errbuf[0] = '\0';
11551155
std::string currSch;
11561156
std::string objnm;
@@ -1603,7 +1603,7 @@ void STEPfile::WriteValuePairsData( ostream & out, int writeComments, int mixedC
16031603

16041604
Severity STEPfile::AppendFile( istream * in, bool useTechCor ) {
16051605
Severity rval = SEVERITY_NULL;
1606-
char errbuf[BUFSIZ];
1606+
char errbuf[BUFSIZ+1];
16071607

16081608
SetFileIdIncrement();
16091609
int total_insts = 0, valid_insts = 0;

src/cleditor/STEPfile.inline.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) {
179179
return( 0 );
180180
} else {
181181
if( SetFileName( filename ).empty() && ( filename.compare( "-" ) != 0 ) ) {
182-
char msg[BUFSIZ];
182+
char msg[BUFSIZ+1];
183183
sprintf( msg, "Unable to find file for input: \'%s\'. File not read.\n", filename.c_str() );
184184
_error.AppendToUserMsg( msg );
185185
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
@@ -196,7 +196,7 @@ istream * STEPfile::OpenInputFile( const std::string filename ) {
196196
}
197197

198198
if( !in || !( in -> good() ) ) {
199-
char msg[BUFSIZ];
199+
char msg[BUFSIZ+1];
200200
sprintf( msg, "Unable to open file for input: \'%s\'. File not read.\n", filename.c_str() );
201201
_error.AppendToUserMsg( msg );
202202
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );
@@ -231,7 +231,7 @@ ofstream * STEPfile::OpenOutputFile( std::string filename ) {
231231
}
232232
} else {
233233
if( SetFileName( filename ).empty() ) {
234-
char msg[BUFSIZ];
234+
char msg[BUFSIZ+1];
235235
sprintf( msg, "can't find file: %s\nFile not written.\n", filename.c_str() );
236236
_error.AppendToUserMsg( msg );
237237
_error.GreaterSeverity( SEVERITY_INPUT_ERROR );

src/clstepcore/Registry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void Registry::DeleteContents() {
7979
const EntityDescriptor * Registry::FindEntity( const char * e, const char * schNm, int check_case ) const {
8080
const EntityDescriptor * entd;
8181
const SchRename * altlist;
82-
char schformat[BUFSIZ], altName[BUFSIZ];
82+
char schformat[BUFSIZ+1], altName[BUFSIZ+1];
8383

8484
if( check_case ) {
8585
entd = ( EntityDescriptor * )SC_HASHfind( primordialSwamp, ( char * )e );

src/clstepcore/STEPaggrEntity.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err,
2121
int addFileId, int assignVal,
2222
int exchangeFileFormat, const char * ) {
2323
ErrorDescriptor errdesc;
24-
char errmsg[BUFSIZ];
24+
char errmsg[BUFSIZ+1];
2525
int value_cnt = 0;
2626
std::string buf;
2727

src/clstepcore/STEPaggrInt.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const char * IntNode::asStr( std::string & s ) {
9494
}
9595

9696
const char * IntNode::STEPwrite( std::string & s, const char * ) {
97-
char tmp[BUFSIZ];
97+
char tmp[BUFSIZ+1];
9898
if( value != S_INT_NULL ) {
9999
sprintf( tmp, "%ld", value );
100100
s = tmp;

src/clstepcore/STEPaggrSelect.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Severity SelectAggregate::ReadValue( istream & in, ErrorDescriptor * err,
1919
int addFileId, int assignVal,
2020
int exchangeFileFormat, const char * currSch ) {
2121
ErrorDescriptor errdesc;
22-
char errmsg[BUFSIZ];
22+
char errmsg[BUFSIZ+1];
2323
int value_cnt = 0;
2424
std::string buf;
2525

src/clstepcore/STEPaggregate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Severity STEPaggregate::ReadValue( istream & in, ErrorDescriptor * err,
106106
(void) addFileId; //not used in ReadValue() for this class
107107

108108
ErrorDescriptor errdesc;
109-
char errmsg[BUFSIZ];
109+
char errmsg[BUFSIZ+1];
110110
int value_cnt = 0;
111111
std::string buf;
112112

src/clstepcore/STEPattribute.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ ostream & operator<< ( ostream & out, STEPattribute & a ) {
12631263
* value.
12641264
******************************************************************/
12651265
void STEPattribute::AddErrorInfo() {
1266-
char errStr[BUFSIZ];
1266+
char errStr[BUFSIZ+1];
12671267
errStr[0] = '\0';
12681268
if( SEVERITY_INPUT_ERROR < _error.severity() &&
12691269
_error.severity() < SEVERITY_NULL ) {
@@ -1293,7 +1293,7 @@ char STEPattribute::SkipBadAttr( istream & in, char * StopChars ) {
12931293
// read bad data until end of this attribute or entity.
12941294
char * foundCh = 0;
12951295
char c = '\0';
1296-
char errStr[BUFSIZ];
1296+
char errStr[BUFSIZ+1];
12971297
errStr[0] = '\0';
12981298

12991299
_error.GreaterSeverity( SEVERITY_WARNING );

src/clstepcore/STEPcomplex.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ STEPcomplex::STEPcomplex( Registry * registry, int fileid )
2020
STEPcomplex::STEPcomplex( Registry * registry, const std::string ** names,
2121
int fileid, const char * schnm )
2222
: SDAI_Application_instance( fileid, true ), sc( 0 ), _registry( registry ), visited( 0 ) {
23-
char * nms[BUFSIZ];
23+
char * nms[BUFSIZ+1];
2424
int j, k;
2525

2626
head = this;
@@ -61,7 +61,7 @@ void STEPcomplex::Initialize( const char ** names, const char * schnm ) {
6161
EntNode * ents = new EntNode( names ),
6262
*eptr = ents, *prev = NULL, *enext;
6363
const EntityDescriptor * enDesc;
64-
char nm[BUFSIZ];
64+
char nm[BUFSIZ+1];
6565
bool invalid = false, outOfOrder = false;
6666

6767
// Splice out the invalid names from our list:
@@ -659,7 +659,7 @@ const char * STEPcomplex::WriteExtMapEntities( std::string & buf, const char * c
659659

660660
void STEPcomplex::CopyAs( SDAI_Application_instance * se ) {
661661
if( !se->IsComplex() ) {
662-
char errStr[BUFSIZ];
662+
char errStr[BUFSIZ+1];
663663
cerr << "STEPcomplex::CopyAs() called with non-complex entity: "
664664
<< __FILE__ << __LINE__ << "\n" << _POC_ "\n";
665665
sprintf( errStr,
@@ -700,7 +700,7 @@ SDAI_Application_instance * STEPcomplex::Replicate() {
700700
}
701701
nameList[i] = ( std::string * )0;
702702
if( i == 63 ) {
703-
char errStr[BUFSIZ];
703+
char errStr[BUFSIZ+1];
704704
cerr << "STEPcomplex::Replicate() name buffer too small: "
705705
<< __FILE__ << __LINE__ << "\n" << _POC_ "\n";
706706
sprintf( errStr,

0 commit comments

Comments
 (0)