Compare commits

...

10 commits

Author SHA1 Message Date
Jeff Epler
0256eb9a45 actually run what I intended 100x 2017-08-21 10:07:01 -05:00
Jeff Epler
a7b65aefbf jfc test my branches wtq 2017-08-21 09:53:36 -05:00
Jeff Epler
5f476506bd jfc test my branches wtq 2017-08-21 09:52:45 -05:00
Jeff Epler
f87868d8e3 temporary tweak to CI scripts 2017-08-21 09:30:37 -05:00
Jeff Epler
3ec5466445 lazyFileReader: open file in binary mode
Inputs to lazyFileReader may look like text files (their contents
are essentially ASCII), but they may not necessarily obey the
platform rules for text files, such as terminating each line with
the CR LF control sequence on Windows platforms.

Also, the file position operations which may be performed on text
files are severely limited by the C and C++ language standards.  For
instance, Microsoft documentation states that
 1. ifstream::seekg will call basic_filebuf::seekpos.
    basic_filebuf::seekpos is in turn implemented in terms of C fsetpos
    on Windows.
    https://msdn.microsoft.com/en-us/library/xx21a6ww(v=vs.110).aspx

 2. The C standard specifies that it is undefined behavior if the
    "fsetpos function is called to set a position that was not returned
    by a previous successful call to the fgetpos function on a stream
    associated with the same file (7.21.9.3)." [ISO/IEC 9899:2011]

 3. Similarly, ifstream::unget() may call basic_filebuf::pbackfail()
    which on Windows is implemented in terms of ungetc().
    https://msdn.microsoft.com/en-us/library/x0kf6337(v=vs.110).aspx
    https://msdn.microsoft.com/en-us/library/29hykw2y(v=vs.110).aspx

 4. Microsoft documents the following about how file positions are
    maintained when ungetc() is used on text streams:
        On a successful ungetc call against a text stream, the
        file-position indicator is unspecified until all the
        pushed-back characters are read or discarded.

 5. In stepcode, unget() and seekg() are freely mixed without regard
    to whether undefined behavior is encountered as a result of
    [1-4]
2017-08-21 09:04:53 -05:00
Jeff Epler
1d01b831aa errordesc.cc: Correctly append a single character to a std::string
The idiom
    char c = ...;
    _userMsg.append( &c );
is not correct C++, because it treats the address of 'c' as a NUL-
terminated C string.  However, this is not guaranteed.

When building and testing on Debian Stretch with AddressSanitizer:
    ASAN_OPTIONS="detect_leaks=false" CXX="clang++" CC=clang CXXFLAGS="-fsanitize=address" LDFLAGS="-fsanitize=address" cmake .. -DSC_ENABLE_TESTING=ON  -DSC_BUILD_SCHEMAS="ifc2x3;ap214e3;ap209"
    ASAN_OPTIONS="detect_leaks=false" make
    ASAN_OPTIONS="detect_leaks=false" ctest . --output-on-failure
an error like the following is encountered:

==15739==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffeb2ca7621 at pc 0x00000043c943 bp 0x7ffeb2ca75d0 sp 0x7ffeb2ca6d80
READ of size 33 at 0x7ffeb2ca7621 thread T0
    #0 0x43c942 in __interceptor_strlen.part.45 (/home/jepler/src/stepcode/build/bin/lazy_sdai_ap214e3+0x43c942)
    #1 0x7fb9056e6143 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::append(char const*) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x11f143)
    #2 0x7fb905b677c3 in ErrorDescriptor::AppendToDetailMsg(char) /home/jepler/src/stepcode/src/clutils/errordesc.cc:150:5

Address 0x7ffeb2ca7621 is located in stack of thread T0 at offset 33 in frame
    #0 0x7fb905b676af in ErrorDescriptor::AppendToDetailMsg(char) /home/jepler/src/stepcode/src/clutils/errordesc.cc:149

  This frame has 1 object(s):
    [32, 33) '' <== Memory access at offset 33 overflows this variable

A similar problem with AppendToUserMsg is found by inspection.

After this change, all 200 tests pass under the AddressSanitizer
configuration
2017-08-21 08:35:04 -05:00
Jeff Epler
0d2e791e82 express/error.c: Ensure the error buffer does not overflow
On Debian Stretch, when configuring stepcode like so:
    ASAN_OPTIONS="detect_leaks=false" CXX="clang++" CXXFLAGS="-fsanitize=address" cmake ..
a fatal error would be detected:

  ==29661==ERROR: AddressSanitizer: heap-buffer-overflow on address
  0x62100001dca0 at pc 0x0000004435e3 bp 0x7ffed6d9cae0 sp 0x7ffed6d9c290

  READ of size 4001 at 0x62100001dca0 thread T0

      #0 0x4435e2 in __interceptor_strlen.part.45 (/home/jepler/src/stepcode/build/bin/schema_scanner+0x4435e2)
      #1 0x501d7b in ERRORreport_with_symbol /home/jepler/src/stepcode/src/express/error.c:413

  0x62100001dca0 is located 0 bytes to the right of 4000-byte region
  [0x62100001cd00,0x62100001dca0)

  allocated by thread T0 here:

      #0 0x4c3ae8 in __interceptor_malloc (/home/jepler/src/stepcode/build/bin/schema_scanner+0x4c3ae8)
      #1 0x5011fc in ERRORinitialize /home/jepler/src/stepcode/src/express/error.c:129

Operations on ERROR_string were unsafe, because they did not guard
against accesses beyond the end of the allocatd region.

This patch ensures that all accesses via *printf functions do respect
the end of the buffer; and encapsulates the routine for pointing
ERROR_string at the space for the next error text to start, if space is
available.

Finally, because it was found with search and replace, a stray manipulation
of ERROR_string within the print-to-file branch of the code is removed.
This stray line would have had the effect of moving ERROR_string one byte
further along at every warning-to-file, which could also have been a
cause of the problem here.
2017-08-21 08:35:04 -05:00
Mark
71fe947ff5 Merge pull request #361 from jepler/appveyor-single-thread-test
appveyor build: don't use ctest parallelism
2017-08-19 17:12:28 -04:00
Mark
beb2a595f1 Merge pull request #357 from jepler/nullptr-bool
Fix build error with g++ 6.3 (Debian Stretch)
2017-08-19 15:41:33 -04:00
Jeff Epler
0fbc3c0c84 Fix build error with g++ 6.3 (Debian Stretch)
On this platform, TEST_NULLPTR fails, even though nullptr and
nullptr_t are supported:

/home/jepler/src/stepcode/build/CMakeFiles/CMakeTmp/src.cxx:4:23:
    error: converting to 'bool' from 'std::nullptr_t'
    requires direct-initialization [-fpermissive]
 int main() {return !!f();}
                      ~^~

Subsequent to this failure, the workaround definitions in sc_nullptr.h
prevent standard C++ headers (which must refer to real nullptr) to fail.

The failure occurs because the C++ standard apparently does not state
that operator! may be used on nullptr.  Despite this, some compilers
have historically allowed it.  g++ 6.3's behavior appears to be aligned
with the standard.

As requested by @brlcad, ensure that the function 'f' is used from main,
to avoid a clever (but not nullptr-supporting) compiler from somehow
skipping 'f' altogether, creating a false positive for nullptr support.
2017-08-15 06:50:56 -05:00
6 changed files with 143 additions and 29 deletions

View file

@ -1,11 +1,5 @@
version: '{build}'
# for Appveyor CI (windows)
branches:
only:
- master
os: Windows Server 2012 R2
clone_folder: c:\projects\STEPcode
@ -59,6 +53,106 @@ test_script:
- cmd: cd c:\projects\STEPcode\build
- cmd: echo excluding test_inverse_attr3, which hangs
- cmd: ctest -j1 . -C Debug -E test_inverse_attr3 --output-on-failure
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
- cmd: bin\tst_inverse_attr3 ..\test\p21\test_inverse_attr.p21
# - cmd: grep -niB20 "Test Failed" Testing/Temporary/LastTest.log

View file

@ -3,9 +3,6 @@ language: cpp
compiler:
- clang
script: mkdir build && cd build && cmake .. -DSC_ENABLE_TESTING=ON && make -j3 && ctest -j2 --output-on-failure
branches:
only:
- master
notifications:
irc: "chat.freenode.net#stepcode"
email: scl-dev@groups.google.com
@ -14,6 +11,3 @@ notifications:
os:
- linux
- osx
matrix:
allow_failures:
- os: osx

View file

@ -80,7 +80,7 @@ std::cout << \"1s is \"<< std::chrono::duration_cast<std::chrono::milliseconds>(
set( TEST_NULLPTR "
#include <cstddef>
std::nullptr_t f() {return nullptr;}
int main() {return !!f();}
int main() {return !(f() == f());}
" )
cmake_push_check_state()
if( UNIX )

View file

@ -50,7 +50,7 @@ instancesLoaded_t * lazyFileReader::getHeaderInstances() {
}
lazyFileReader::lazyFileReader( std::string fname, lazyInstMgr * i, fileID fid ): _fileName( fname ), _parent( i ), _fileID( fid ) {
_file.open( _fileName.c_str() );
_file.open( _fileName.c_str(), std::ios::binary );
_file.imbue( std::locale::classic() );
_file.unsetf( std::ios_base::skipws );
assert( _file.is_open() && _file.good() );

View file

@ -131,7 +131,7 @@ void ErrorDescriptor::PrependToUserMsg( const char * msg ) {
}
void ErrorDescriptor::AppendToUserMsg( const char c ) {
_userMsg.append( &c );
_userMsg.push_back( c );
}
void ErrorDescriptor::AppendToUserMsg( const char * msg ) {
@ -147,7 +147,7 @@ void ErrorDescriptor::PrependToDetailMsg( const char * msg ) {
}
void ErrorDescriptor::AppendToDetailMsg( const char c ) {
_detailMsg.append( &c );
_detailMsg.push_back( c );
}
void ErrorDescriptor::AppendToDetailMsg( const char * msg ) {

View file

@ -67,6 +67,9 @@
#include "express/info.h"
#include "express/linklist.h"
#if defined( _WIN32 ) || defined ( __WIN32__ )
# define snprintf _snprintf
#endif
bool __ERROR_buffer_errors = false;
const char * current_filename = "stdin";
@ -112,6 +115,7 @@ static struct heap_element {
static int ERROR_with_lines = 0; /**< number of warnings & errors that have occurred with a line number */
static char * ERROR_string;
static char * ERROR_string_base;
static char * ERROR_string_end;
static bool ERROR_unsafe = false;
static jmp_buf ERROR_safe_env;
@ -119,6 +123,34 @@ static jmp_buf ERROR_safe_env;
#define error_file stderr /**< message buffer file */
static int ERROR_vprintf( const char *format, va_list ap ) {
int result = snprintf( ERROR_string, ERROR_string_end - ERROR_string, format, ap );
if(result < 0) {
ERROR_string = ERROR_string_end;
} else if(result > (ERROR_string_end - ERROR_string)) {
ERROR_string = ERROR_string_end;
} else {
ERROR_string = ERROR_string + result;
}
return result;
}
static int ERROR_printf( const char *format, ... ) {
int result;
va_list ap;
va_start( ap, format );
result = ERROR_vprintf( format, ap );
va_end( ap );
return result;
}
static void ERROR_nexterror() {
if( ERROR_string == ERROR_string_end ) {
return;
}
ERROR_string++;
}
/** Initialize the Error module */
void ERRORinitialize( void ) {
ERROR_subordinate_failed =
@ -127,6 +159,7 @@ void ERRORinitialize( void ) {
ERRORcreate( "%s, expecting %s in %s %s", SEVERITY_EXIT );
ERROR_string_base = ( char * )sc_malloc( ERROR_MAX_SPACE );
ERROR_string_end = ERROR_string_base + ERROR_MAX_SPACE;
ERROR_start_message_buffer();
@ -377,20 +410,14 @@ va_dcl {
heap[child].msg = ERROR_string;
if( what->severity >= SEVERITY_ERROR ) {
sprintf( ERROR_string, "%s:%d: --ERROR PE%03d: ", sym->filename, sym->line, what->serial );
ERROR_string += strlen( ERROR_string );
vsprintf( ERROR_string, what->message, args );
ERROR_string += strlen( ERROR_string );
*ERROR_string++ = '\n';
*ERROR_string++ = '\0';
ERROR_printf( "%s:%d: --ERROR PE%03d: ", sym->filename, sym->line, what->serial );
ERROR_vprintf( what->message, args );
ERROR_nexterror();
ERRORoccurred = true;
} else {
sprintf( ERROR_string, "%s:%d: WARNING PW%03d: ", sym->filename, sym->line, what->serial );
ERROR_string += strlen( ERROR_string );
vsprintf( ERROR_string, what->message, args );
ERROR_string += strlen( ERROR_string );
*ERROR_string++ = '\n';
*ERROR_string++ = '\0';
ERROR_printf( "%s:%d: WARNING PW%03d: ", sym->filename, sym->line, what->serial );
ERROR_vprintf( what->message, args );
ERROR_nexterror();
}
if( what->severity >= SEVERITY_EXIT ||
ERROR_string + ERROR_MAX_STRLEN > ERROR_string_base + ERROR_MAX_SPACE ||
@ -410,7 +437,6 @@ va_dcl {
ERRORoccurred = true;
} else {
fprintf( error_file, "%s:%d: WARNING PW%03d: ", sym->filename, sym->line, what->serial );
ERROR_string += strlen( ERROR_string ) + 1;
vfprintf( error_file, what->message, args );
fprintf( error_file, "\n" );
}