Skip to content

Commit

Permalink
Merge branch 'smoke-me/afl-crash-gh1168'
Browse files Browse the repository at this point in the history
Smoked ok
  • Loading branch information
Reini Urban committed Jan 11, 2015
2 parents 2176e8e + 7690786 commit e6b93c1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Expand Up @@ -6,6 +6,9 @@
Default 3 for generations 0,1,2.
+ Add the DEPRECATED attribute to all deprecated functions. #1163
+ Fix parser crashes detected by the american fuzzy lop (1.06b) #1168
+ Replace an end op inside pcc methods by a returncc op, #1168.
This used to crash the last years, now it returns. It is now documented as
unspecified behavior.
- Build
+ More code cleanup to reduce compiler warnings, code size and unneeded calls.
+ Add ARGIN_FORMAT declarations, probe for gnu_printf, ms_printf, printf. #1163
Expand Down
10 changes: 9 additions & 1 deletion compilers/imcc/pcc.c
Expand Up @@ -413,6 +413,7 @@ expand_pcc_sub(ARGMOD(imc_info_t * imcc), ARGMOD(IMC_Unit *unit), ARGIN(Instruct
&& !sub->pcc_sub->object
/* s. src/inter_call.c:119 */
&& sub->pcc_sub->tailcall) {
IMCC_debug(imcc, DEBUG_IMC, "sub tailcall - %s\n", unit->last_ins->opname);
return;
}
}
Expand Down Expand Up @@ -441,9 +442,16 @@ expand_pcc_sub(ARGMOD(imc_info_t * imcc), ARGMOD(IMC_Unit *unit), ARGIN(Instruct
tmp = INS(imcc, unit, "returncc", NULL, regs, 0, 0, 0);
}

IMCC_debug(imcc, DEBUG_IMC, "add sub ret - %d\n", tmp);
IMCC_debug(imcc, DEBUG_IMC, "add sub ret - %d %s\n", tmp, unit->last_ins->opname);
insert_ins(unit, unit->last_ins, tmp);
}
/* end is currently forbidden inside methods. it will be translated to a returncc */
else if (STREQ(unit->last_ins->opname, "end") && sub && sub->pcc_sub) {
Instruction *tmp;
IMCC_debug(imcc, DEBUG_IMC, "sub ret via end => returncc\n");
tmp = INS(imcc, unit, "returncc", NULL, regs, 0, 0, 0);
subst_ins(unit, unit->last_ins, tmp, 1);
}
}

/*
Expand Down
2 changes: 2 additions & 0 deletions include/parrot/context.h
Expand Up @@ -27,6 +27,8 @@ typedef union {
typedef struct Parrot_CallContext_attributes Parrot_Context;

#define CONTEXT_STRUCT(c) (PMC_data_typed((c), Parrot_Context *))
/* ((Parrot_Context *)ctx->data)->n_regs_used */
#define PCC_GET_REGS_USED(ctx, type) CONTEXT_STRUCT(ctx)->n_regs_used[type]

/*
* Macros to make accessing registers more convenient/readable.
Expand Down
10 changes: 5 additions & 5 deletions src/call/context.c
Expand Up @@ -651,7 +651,7 @@ Parrot_pcc_get_INTVAL_reg(PARROT_INTERP, ARGIN(const PMC *ctx), UINTVAL idx)
#ifdef NDEBUG
UNUSED(interp)
#endif
PARROT_ASSERT(Parrot_pcc_get_regs_used(interp, ctx, REGNO_INT) > idx);
PARROT_ASSERT(PCC_GET_REGS_USED(ctx, REGNO_INT) > idx);
return &(CONTEXT_STRUCT(ctx)->bp.regs_i[idx]);
}

Expand Down Expand Up @@ -682,7 +682,7 @@ Parrot_pcc_get_FLOATVAL_reg(PARROT_INTERP, ARGIN(const PMC *ctx), UINTVAL idx)
#ifdef NDEBUG
UNUSED(interp)
#endif
PARROT_ASSERT(Parrot_pcc_get_regs_used(interp, ctx, REGNO_NUM) > idx);
PARROT_ASSERT(PCC_GET_REGS_USED(ctx, REGNO_NUM) > idx);
return &(CONTEXT_STRUCT(ctx)->bp.regs_n[-1L - idx]);
}

Expand Down Expand Up @@ -710,7 +710,7 @@ STRING **
Parrot_pcc_get_STRING_reg(PARROT_INTERP, ARGIN(PMC *ctx), UINTVAL idx)
{
ASSERT_ARGS(Parrot_pcc_get_STRING_reg)
PARROT_ASSERT(Parrot_pcc_get_regs_used(interp, ctx, REGNO_STR) > idx);
PARROT_ASSERT(PCC_GET_REGS_USED(ctx, REGNO_STR) > idx);
PARROT_GC_WRITE_BARRIER(interp, ctx);
return &(CONTEXT_STRUCT(ctx)->bp_ps.regs_s[idx]);
}
Expand Down Expand Up @@ -739,7 +739,7 @@ Parrot_pcc_get_PMC_reg(PARROT_INTERP, ARGIN(PMC *ctx), UINTVAL idx)
{
ASSERT_ARGS(Parrot_pcc_get_PMC_reg)
PMC **res;
PARROT_ASSERT(Parrot_pcc_get_regs_used(interp, ctx, REGNO_PMC) > idx);
PARROT_ASSERT(PCC_GET_REGS_USED(ctx, REGNO_PMC) > idx);
PARROT_GC_WRITE_BARRIER(interp, ctx);
res = &(CONTEXT_STRUCT(ctx)->bp_ps.regs_p[-1L - idx]);
PARROT_ASSERT(!*res || !PObj_on_free_list_TEST(*res));
Expand All @@ -763,7 +763,7 @@ UINTVAL
Parrot_pcc_get_regs_used(SHIM_INTERP, ARGIN(const PMC *ctx), int type)
{
ASSERT_ARGS(Parrot_pcc_get_regs_used)
return CONTEXT_STRUCT(ctx)->n_regs_used[type];
return PCC_GET_REGS_USED(ctx, type);
}

/*
Expand Down
15 changes: 7 additions & 8 deletions src/debug.c
Expand Up @@ -2256,7 +2256,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))

if (condition->type & PDB_cond_int) {
INTVAL i, j;
if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_INT))
if (condition->reg >= PCC_GET_REGS_USED(ctx, REGNO_INT))
return 0;
i = CTX_REG_INT(interp, ctx, condition->reg);

Expand All @@ -2278,7 +2278,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_num) {
FLOATVAL k, l;

if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_NUM))
if (condition->reg >= PCC_GET_REGS_USED(ctx, REGNO_NUM))
return 0;
k = CTX_REG_NUM(interp, ctx, condition->reg);

Expand All @@ -2300,7 +2300,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_str) {
STRING *m, *n;

if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_STR))
if (condition->reg >= PCC_GET_REGS_USED(ctx, REGNO_STR))
return 0;
m = CTX_REG_STR(interp, ctx, condition->reg);

Expand Down Expand Up @@ -2331,7 +2331,7 @@ PDB_check_condition(PARROT_INTERP, ARGIN(const PDB_condition_t *condition))
else if (condition->type & PDB_cond_pmc) {
PMC *m;

if (condition->reg >= Parrot_pcc_get_regs_used(interp, ctx, REGNO_PMC))
if (condition->reg >= PCC_GET_REGS_USED(ctx, REGNO_PMC))
return 0;
m = CTX_REG_PMC(interp, ctx, condition->reg);

Expand Down Expand Up @@ -3322,8 +3322,7 @@ PDB_assign(PARROT_INTERP, ARGIN(const char *command))
Parrot_io_eprintf(debugger, "Invalid register type %c\n", reg_type_id);
return;
}
if (register_num >= Parrot_pcc_get_regs_used(debugee,
CURRENT_CONTEXT(debugee), reg_type)) {
if (register_num >= PCC_GET_REGS_USED(CURRENT_CONTEXT(debugee), reg_type)) {
no_such_register(debugger, reg_type_id, register_num);
return;
}
Expand Down Expand Up @@ -3755,7 +3754,7 @@ GDB_print_reg(PARROT_INTERP, int t, int n)
ASSERT_ARGS(GDB_print_reg)
char * string;

if (n >= 0 && (UINTVAL)n < Parrot_pcc_get_regs_used(interp, CURRENT_CONTEXT(interp), t)) {
if (n >= 0 && (UINTVAL)n < PCC_GET_REGS_USED(CURRENT_CONTEXT(interp), t)) {
switch (t) {
case REGNO_INT:
return Parrot_str_from_int(interp, IREG(n));
Expand Down Expand Up @@ -3820,7 +3819,7 @@ GDB_P(PARROT_INTERP, ARGIN(const char *s))
}
if (! s[1]) {
/* Print all registers of this type. */
const int max_reg = Parrot_pcc_get_regs_used(interp, CURRENT_CONTEXT(interp), t);
const int max_reg = PCC_GET_REGS_USED(CURRENT_CONTEXT(interp), t);
int n;

for (n = 0; n < max_reg; ++n) {
Expand Down
6 changes: 5 additions & 1 deletion src/ops/core.ops
Expand Up @@ -54,7 +54,11 @@ internal use only; don't emit these opcodes.

=item B<end>()

Halts the interpreter. See also B<exit>.
Halts the current interpreter. See also B<exit>.

Note that a user-defined method currently creates its own interpreter,
so end inside a method is like a return without any context.
This is unspecified behaviour. Currently it is replaced by the returncc op.

=cut

Expand Down
4 changes: 2 additions & 2 deletions src/runcore/trace.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2014, Parrot Foundation.
Copyright (C) 2001-2015, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -364,7 +364,7 @@ trace_key_dump(PARROT_INTERP, ARGIN(PMC *key))
case KEY_string_FLAG|KEY_register_FLAG:
{
const UINTVAL keynum = (UINTVAL)VTABLE_get_integer(interp, key);
if (keynum < Parrot_pcc_get_regs_used(interp, CURRENT_CONTEXT(interp), REGNO_STR)) {
if (keynum < PCC_GET_REGS_USED(CURRENT_CONTEXT(interp), REGNO_STR)) {
const STRING * const s = REG_STR(interp, keynum);
STRING * const escaped = Parrot_str_escape_truncate(interp, s, 20);
if (escaped)
Expand Down
21 changes: 19 additions & 2 deletions t/compilers/imcc/reg/alloc.t
@@ -1,12 +1,12 @@
#!perl
# Copyright (C) 2005-2014, Parrot Foundation.
# Copyright (C) 2005-2015, Parrot Foundation.

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use Parrot::Test tests => 10;
use Parrot::Test tests => 11;

pir_output_is( <<'CODE', <<'OUT', "alligator" );
# if the side-effect of set_label/continuation isn't
Expand Down Expand Up @@ -143,6 +143,23 @@ CODE
ok
OUT

pir_output_is( <<'CODE', <<'OUT', "Wrong regs_used[S], afl crash 3 - GH #1168" );
# src/call/context.c:713: failed assertion 'get_regs_used(interp, ctx, REGNO_STR) > idx'
.sub main :main
$P1 = newclass "Foo11"
$P2 = new "Foo11"
$S1 = $P2
eq $S1, 'stringy thingy', ok
ok:
.end
.namespace [ "Foo11" ]
.sub 'get_string' :vtable
end # <== this is the inserted statement, leading to the wrong n_regs_used[S]
.end
CODE
OUT

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down

0 comments on commit e6b93c1

Please sign in to comment.