From 9f5ac5b212f01883c072254f2e7bf276993de4da Mon Sep 17 00:00:00 2001 From: marcobaye Date: Mon, 22 Jun 2020 13:39:27 +0000 Subject: [PATCH] fixed buffer overrun when printing long ints on 64bit machines git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@256 4df02467-bbd4-4a76-a152-e7ce94205b78 --- src/acme.c | 3 +-- src/alu.c | 11 +++++++++-- src/symbol.c | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/acme.c b/src/acme.c index 976ec1b..8ff98b9 100644 --- a/src/acme.c +++ b/src/acme.c @@ -547,8 +547,7 @@ static const char *long_option(const char *string) else if (strcmp(string, OPTION_DIALECT) == 0) set_dialect(cliargs_get_next()); // NULL is ok (handled like unknown) else if (strcmp(string, OPTION_TEST) == 0) { - if (config.test_new_features) - config.wanted_version = VER_FUTURE; // giving "--test" twice enables every new feature + config.wanted_version = VER_FUTURE; config.test_new_features = TRUE; } PLATFORM_LONGOPTION_CODE else if (strcmp(string, OPTION_COLOR) == 0) diff --git a/src/alu.c b/src/alu.c index a9403da..dd41966 100644 --- a/src/alu.c +++ b/src/alu.c @@ -2265,14 +2265,19 @@ static void object_no_op(struct object *self) // int/float: // print value for user message +#define NUMBUFSIZE 64 // large enough(tm) even for 64bit systems static void number_print(const struct object *self, struct dynabuf *db) { - char buffer[40]; // large enough(tm) + char buffer[NUMBUFSIZE]; if (self->u.number.ntype == NUMTYPE_UNDEFINED) { DynaBuf_add_string(db, ""); } else if (self->u.number.ntype == NUMTYPE_INT) { +#if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L + snprintf(buffer, NUMBUFSIZE, "%ld (0x%lx)", (long) self->u.number.val.intval, (long) self->u.number.val.intval); +#else sprintf(buffer, "%ld (0x%lx)", (long) self->u.number.val.intval, (long) self->u.number.val.intval); +#endif DynaBuf_add_string(db, buffer); } else if (self->u.number.ntype == NUMTYPE_FLOAT) { // write up to 30 significant characters. @@ -2492,6 +2497,7 @@ void ALU_defined_int(struct number *intresult) // no ACCEPT constants? if (expression.result.type == &type_number) { if (expression.result.u.number.ntype == NUMTYPE_UNDEFINED) { Throw_serious_error("Value not defined."); + expression.result.u.number.val.intval = 0; } else if (expression.result.u.number.ntype == NUMTYPE_INT) { // ok } else if (expression.result.u.number.ntype == NUMTYPE_FLOAT) { @@ -2530,7 +2536,8 @@ void ALU_addrmode_int(struct expression *expression, int paren) // ACCEPT_UNDEFI // convert float to int if (expression->result.u.number.ntype == NUMTYPE_FLOAT) float_to_int(&(expression->result)); - // FIXME - check for undefined? + else if (expression->result.u.number.ntype == NUMTYPE_UNDEFINED) + expression->result.u.number.val.intval = 0; } else if (expression->result.type == &type_string) { // accept single-char strings, to be more // compatible with versions before 0.97: diff --git a/src/symbol.c b/src/symbol.c index 9d5a263..e9e0744 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -60,7 +60,7 @@ static void dump_one_symbol(struct rwnode *node, FILE *fd) else if (symbol->object.u.number.ntype == NUMTYPE_FLOAT) fprintf(fd, "%.30f", symbol->object.u.number.val.fpval); //FIXME %g else - Bug_found("BogusType", 0); // FIXME - put in docs! + Bug_found("IllegalNumberType4", symbol->object.u.number.ntype); if (symbol->object.u.number.flags & NUMBER_EVER_UNDEFINED) fprintf(fd, "\t; ?"); // TODO - write "forward" instead? if (!symbol->has_been_read)