Restart CI for New Technology and UBSAN hunting

Continuous Integration (via runit and runitd) is now re-enabled on win7
and win10. The `make test` command, which runs the tests on all systems
is now the fastest and most stable it's been since the project started.

UBSAN is now enabled in MODE=dbg in addition to ASAN. Many instances of
undefined behavior have been removed. Mostly things like passing a NULL
argument to memcpy(), which works fine with Cosmopolitan Libc, but that
doesn't prevents the compiler from being unhappy. There was an issue w/
GNU make where static analysis claims a sprintf() call can overflow. We
also now have nicer looking crash reports on Windows since uname should
now be supported and msys64 addr2line works reliably.
This commit is contained in:
Justine Tunney 2022-03-21 03:46:16 -07:00
parent d5ff2c3fb9
commit 5e8ae2d5bc
80 changed files with 506 additions and 249 deletions

View file

@ -1255,7 +1255,7 @@ static void EmitData(struct As *a, const void *p, uint128_t n) {
struct Slice *s;
s = &a->sections.p[a->section].binary;
s->p = realloc(s->p, s->n + n);
memcpy(s->p + s->n, p, n);
if (n) memcpy(s->p + s->n, p, n);
s->n += n;
}
@ -3910,8 +3910,10 @@ static void Objectify(struct As *a, int path) {
Fail(a, "unsupported relocation type");
}
}
memcpy(elfwriter_reserve(elf, a->sections.p[i].binary.n),
a->sections.p[i].binary.p, a->sections.p[i].binary.n);
if (a->sections.p[i].binary.n) {
memcpy(elfwriter_reserve(elf, a->sections.p[i].binary.n),
a->sections.p[i].binary.p, a->sections.p[i].binary.n);
}
elfwriter_commit(elf, a->sections.p[i].binary.n);
elfwriter_finishsection(elf);
}

View file

@ -19,7 +19,7 @@
#include "third_party/chibicc/chibicc.h"
int main(int argc, char *argv[]) {
showcrashreports();
ShowCrashReports();
Assembler(argc, argv);
return 0;
}

View file

@ -119,28 +119,28 @@ o/$(MODE)/third_party/infozip/zip.com.dbg: \
$(THIRD_PARTY_ZIP_DEPS) \
$(THIRD_PARTY_ZIP_COM_OBJS) \
$(CRT) \
$(APE)
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/third_party/infozip/zipsplit.com.dbg: \
$(THIRD_PARTY_ZIP_DEPS) \
$(THIRD_PARTY_ZIPSPLIT_OBJS) \
$(CRT) \
$(APE)
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/third_party/infozip/zipnote.com.dbg: \
$(THIRD_PARTY_ZIP_DEPS) \
$(THIRD_PARTY_ZIPNOTE_OBJS) \
$(CRT) \
$(APE)
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/third_party/infozip/zipcloak.com.dbg: \
$(THIRD_PARTY_ZIP_DEPS) \
$(THIRD_PARTY_ZIPCLOAK_OBJS) \
$(CRT) \
$(APE)
$(APE_NO_MODIFY_SELF)
@$(APELINK)
.PHONY: o/$(MODE)/third_party/infozip

View file

@ -2195,7 +2195,7 @@ char **argv; /* command line tokens */
char **args = NULL; /* could be wide argv */
if (!IsTiny()) showcrashreports();
if (!IsTiny()) ShowCrashReports();
#ifdef THEOS
/* the argument expansion from the standard library is full of bugs */

View file

@ -872,7 +872,7 @@ file_timestamp_cons (const char *fname, time_t stamp, long int ns)
char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
const char *f = fname ? fname : _("Current time");
ts = s <= OLD_MTIME ? ORDINARY_MTIME_MIN : ORDINARY_MTIME_MAX;
file_timestamp_sprintf (buf, ts);
file_timestamp_sprintf (buf, sizeof(buf), ts);
OSS (error, NILF,
_("%s: Timestamp out of range; substituting %s"), f, buf);
}
@ -933,27 +933,37 @@ file_timestamp_now (int *resolution)
/* Place into the buffer P a printable representation of the file
timestamp TS. */
void
file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts)
file_timestamp_sprintf (char *p, int n, FILE_TIMESTAMP ts)
{
/*
* [jart] patch weakness upstream because buffer can probably overflow
* if integer timestamp is irreguular
*/
int m;
time_t t = FILE_TIMESTAMP_S (ts);
struct tm *tm = localtime (&t);
if (tm)
sprintf (p, "%04d-%02d-%02d %02d:%02d:%02d",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
snprintf (p, n, "%04d-%02d-%02d %02d:%02d:%02d",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec);
else if (t < 0)
sprintf (p, "%ld", (long) t);
snprintf (p, n, "%ld", (long) t);
else
sprintf (p, "%lu", (unsigned long) t);
p += strlen (p);
snprintf (p, n, "%lu", (unsigned long) t);
m = strlen (p);
p += m;
n -= m;
if (n <= 0) return;
/* Append nanoseconds as a fraction, but remove trailing zeros. We don't
know the actual timestamp resolution, since clock_getres applies only to
local times, whereas this timestamp might come from a remote filesystem.
So removing trailing zeros is the best guess that we can do. */
sprintf (p, ".%09d", FILE_TIMESTAMP_NS (ts));
p += strlen (p) - 1;
snprintf (p, n, ".%09d", FILE_TIMESTAMP_NS (ts));
m = strlen (p) - 1;
p += m;
n += m;
while (*p == '0')
p--;
p += *p != '.';
@ -1052,7 +1062,7 @@ print_file (const void *item)
else
{
char buf[FILE_TIMESTAMP_PRINT_LEN_BOUND + 1];
file_timestamp_sprintf (buf, f->last_mtime);
file_timestamp_sprintf (buf, sizeof(buf), f->last_mtime);
printf (_("# Last modified %s\n"), buf);
}
puts (f->updated

View file

@ -164,14 +164,14 @@ int stemlen_compare (const void *v1, const void *v2);
add 4 to allow for any 4-digit epoch year (e.g. 1970);
add 25 to allow for "-MM-DD HH:MM:SS.NNNNNNNNN". */
#define FLOOR_LOG2_SECONDS_PER_YEAR 24
#define FILE_TIMESTAMP_PRINT_LEN_BOUND \
#define FILE_TIMESTAMP_PRINT_LEN_BOUND /* 62 */ \
(((sizeof (FILE_TIMESTAMP) * CHAR_BIT - 1 - FLOOR_LOG2_SECONDS_PER_YEAR) \
* 302 / 1000) \
+ 1 + 1 + 4 + 25)
FILE_TIMESTAMP file_timestamp_cons (char const *, time_t, long int);
FILE_TIMESTAMP file_timestamp_now (int *);
void file_timestamp_sprintf (char *p, FILE_TIMESTAMP ts);
void file_timestamp_sprintf (char *, int, FILE_TIMESTAMP );
/* Return the mtime of file F (a struct file *), caching it.
The value is NONEXISTENT_MTIME if the file does not exist. */

View file

@ -15,6 +15,7 @@
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "libc/intrin/kprintf.h"
#include "libc/rand/rand.h"
#include "libc/runtime/runtime.h"
#include "third_party/mbedtls/common.h"
@ -763,6 +764,10 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
const unsigned char *input,
unsigned char *output )
{
RSA_VALIDATE_RET( ctx );
RSA_VALIDATE_RET( input );
RSA_VALIDATE_RET( output );
int ret = MBEDTLS_ERR_THIS_CORRUPTION;
size_t olen;
@ -798,10 +803,6 @@ int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
* checked result; should be the same in the end. */
mbedtls_mpi I, C;
RSA_VALIDATE_RET( ctx );
RSA_VALIDATE_RET( input );
RSA_VALIDATE_RET( output );
if( rsa_check_context( ctx, 1 /* private key checks */,
f_rng != NULL /* blinding y/n */ ) != 0 )
{

View file

@ -87,7 +87,7 @@ int mbedtls_test_platform_setup(void) {
char *p;
int ret = 0;
static char mybuf[2][BUFSIZ];
showcrashreports();
ShowCrashReports();
setvbuf(stdout, mybuf[0], _IOLBF, BUFSIZ);
setvbuf(stderr, mybuf[1], _IOLBF, BUFSIZ);
#if defined(MBEDTLS_PLATFORM_C)
@ -794,7 +794,8 @@ static int convert_params(size_t cnt, char **params, int *int_params_store) {
*
* \return 0 for success else 1
*/
static dontinline int test_snprintf(size_t n, const char *ref_buf, int ref_ret) {
static dontinline int test_snprintf(size_t n, const char *ref_buf,
int ref_ret) {
int ret;
char buf[10] = "xxxxxxxxx";
const char ref[10] = "xxxxxxxxx";

View file

@ -2410,9 +2410,11 @@ _PyObject_FastCall_Prepend(PyObject *callable,
/* use borrowed references */
args2[0] = obj;
memcpy(&args2[1],
args,
(nargs - 1)* sizeof(PyObject *));
if (nargs > 1) {
memcpy(&args2[1],
args,
(nargs - 1)* sizeof(PyObject *));
}
result = _PyObject_FastCall(callable, args2, nargs);
if (args2 != small_stack) {

View file

@ -97,7 +97,7 @@ static inline void *
_PyMem_RawMalloc(void *ctx, size_t size)
{
#ifdef __COSMOPOLITAN__
#ifdef __FSANITIZE_ADDRESS__
#ifdef __SANITIZE_ADDRESS__
return __asan_memalign(16, size);
#else
return dlmalloc(size);
@ -117,7 +117,7 @@ static inline void *
_PyMem_RawCalloc(void *ctx, size_t nelem, size_t elsize)
{
#ifdef __COSMOPOLITAN__
#ifdef __FSANITIZE_ADDRESS__
#ifdef __SANITIZE_ADDRESS__
return __asan_calloc(nelem, elsize);
#else
return dlcalloc(nelem, elsize);
@ -141,7 +141,7 @@ _PyMem_RawRealloc(void *ctx, void *ptr, size_t size)
if (size == 0)
size = 1;
#ifdef __COSMOPOLITAN__
#ifdef __FSANITIZE_ADDRESS__
#ifdef __SANITIZE_ADDRESS__
return __asan_realloc(ptr, size);
#else
return dlrealloc(ptr, size);
@ -155,7 +155,7 @@ static inline void
_PyMem_RawFree(void *ctx, void *ptr)
{
#ifdef __COSMOPOLITAN__
#ifdef __FSANITIZE_ADDRESS__
#ifdef __SANITIZE_ADDRESS__
__asan_free(ptr);
#else
dlfree(ptr);
@ -2029,11 +2029,13 @@ int
static void
_PyMem_DebugRawFree(void *ctx, void *p)
{
debug_alloc_api_t *api = (debug_alloc_api_t *)ctx;
uint8_t *q = (uint8_t *)p - 2*SST; /* address returned from malloc */
debug_alloc_api_t *api;
uint8_t *q;
size_t nbytes;
if (p == NULL)
return;
api = (debug_alloc_api_t *)ctx;
q = (uint8_t *)p - 2*SST; /* address returned from malloc */
_PyMem_DebugCheckAddress(api->api_id, p);
nbytes = read_size_t(q);
nbytes += 4*SST;

View file

@ -1501,7 +1501,8 @@ tok_get(struct tok_state *tok, char **p_start, char **p_end)
} while (c == ' ' || c == '\t' || c == '\014');
/* Set start of current token */
tok->start = tok->cur - 1;
if (tok->cur)
tok->start = tok->cur - 1;
/* Skip comment */
if (c == '#') {

View file

@ -17,7 +17,7 @@
#include "third_party/python/Include/pystate.h"
/* clang-format off */
#if defined(__FSANITIZE_ADDRESS__) || defined(__FSANITIZE_UNDEFINED__)
#if defined(__SANITIZE_ADDRESS__) || defined(__SANITIZE_UNDEFINED__)
STATIC_YOINK("__die"); /* to guarantee backtraces */
#endif

View file

@ -505,7 +505,7 @@
/* #undef WITH_LIBINTL */
/* Define if you want to compile in Python-specific mallocs */
#ifndef __FSANITIZE_ADDRESS__
#ifndef __SANITIZE_ADDRESS__
#define WITH_PYMALLOC 0
#endif
@ -580,7 +580,7 @@
/* #define FAST_LOOPS 1 /\* froot loops *\/ */
#ifdef __FSANITIZE_UNDEFINED__
#ifdef __SANITIZE_UNDEFINED__
#define HAVE_ALIGNED_REQUIRED 1
#endif

View file

@ -297,7 +297,7 @@ int bf_set(bf_t *r, const bf_t *a)
}
r->sign = a->sign;
r->expn = a->expn;
memcpy(r->tab, a->tab, a->len * sizeof(limb_t));
if (a->len) memcpy(r->tab, a->tab, a->len * sizeof(limb_t));
return 0;
}

View file

@ -24,6 +24,7 @@
*/
#include "libc/assert.h"
#include "libc/calls/weirdtypes.h"
#include "libc/dce.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
@ -328,6 +329,10 @@ int main(int argc, char **argv)
#endif
size_t stack_size = 0;
#if IsModeDbg()
ShowCrashReports();
#endif
#ifdef CONFIG_BIGNUM
/* load jscalc runtime if invoked as 'qjscalc' */
{

View file

@ -488,6 +488,11 @@ int main(int argc, char **argv)
BOOL bignum_ext = FALSE;
#endif
namelist_t dynamic_module_list;
#if IsModeDbg()
ShowCrashReports();
#endif
if (argc == 2 && !strcmp(argv[1], "-n")) return 0;
out_filename = NULL;
output_type = OUTPUT_EXECUTABLE;

View file

@ -10926,7 +10926,7 @@ typedef struct CodeContext {
#define M2(op1, op2) ((op1) | ((op2) << 8))
#define M3(op1, op2, op3) ((op1) | ((op2) << 8) | ((op3) << 16))
#define M4(op1, op2, op3, op4) ((op1) | ((op2) << 8) | ((op3) << 16) | ((op4) << 24))
#define M4(op1, op2, op3, op4) ((op1) | ((op2) << 8) | ((op3) << 16) | ((uint32_t)(op4) << 24))
static BOOL code_match(CodeContext *s, int pos, ...)
{

View file

@ -1950,7 +1950,7 @@ int main(int argc, char **argv)
BOOL is_test262_harness = FALSE;
BOOL is_module = FALSE;
showcrashreports();
ShowCrashReports();
#if !defined(_WIN32)
/* Date tests assume California local time */

View file

@ -174,8 +174,8 @@ o/$(MODE)/%.shell.o: %.c o/$(MODE)/%.o
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
o/$(MODE)/third_party/sqlite3/shell.shell.o: QUOTA = -M512m -C16
o/$(MODE)/third_party/sqlite3/vdbe.o: QUOTA = -M512m
o/$(MODE)/third_party/sqlite3/vdbe.shell.o: QUOTA = -M512m
o/$(MODE)/third_party/sqlite3/vdbe.o: QUOTA = -M1024m
o/$(MODE)/third_party/sqlite3/vdbe.shell.o: QUOTA = -M1024m
o/$(MODE)/third_party/sqlite3/fts5.o: QUOTA = -M512m -C16
o/$(MODE)/third_party/sqlite3/fts5.shell.o: QUOTA = -M512m -C16

View file

@ -809,7 +809,9 @@ void _tr_stored_block(struct DeflateState *s, charf *buf, uint64_t stored_len,
bi_windup(s); /* align on byte boundary */
put_short(s, (uint16_t)stored_len);
put_short(s, (uint16_t)~stored_len);
memcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
if (stored_len) {
memcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
}
s->pending += stored_len;
#ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (uint64_t)~7L;