View Issue Details

IDProjectCategoryView StatusLast Update
0000493LDMudLPC Compiler/Preprocessorpublic2018-01-29 22:57
ReporterGnomi Assigned Tolars 
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Platformi686OSDebian GNU/LinuxOS Version3.1
Summary0000493: find_struct should only consider global identifier
Descriptionvoid fun()
{
    struct abc abc = (<abc>);
}

without any prior definition of struct abc crashes.

Program terminated with signal 11, Segmentation fault.
#0 0x080ecb7d in yyparse () at lang.y:10244
10244 if ($7.length > STRUCT_MAX_MEMBERS
(gdb) bt
#0 0x080ecb7d in yyparse () at lang.y:10244
0000001 0x080fa195 in compile_file (fd=11, fname=0xbfea5600 "w/gnomi/LPC_zst.c",
    isMasterObj=0) at prolang.y:16713
0000002 0x0810b217 in load_object (lname=0x81f9400 "apps/goetter_register",
    create_super=0, depth=0, isMasterObj=0, chain=0x0) at simulate.c:1955
0000003 0x0810c0f3 in lookfor_object (str=0x90917fc, bLoad=1) at simulate.c:2397
0000004 0x0810fa0c in f_load_object (sp=0x8173ee8) at simulate.c:4466
0000005 0x08093fd2 in eval_instruction (
    first_instruction=0x8b4af5e "\036\001\003P\036", initial_sp=0x8173ee0)
    at interpret.c:7974
0000006 0x080af2f7 in int_call_lambda (lsvp=0x8173ed0, num_arg=2, allowRefs=0)
    at interpret.c:17772
0000007 0x080b3c3a in v_funcall (sp=0x8173ee0, num_arg=3) at interpret.c:20261
0000008 0x0809517d in eval_instruction (
    first_instruction=0x8b4af76 "`\002\005\036", initial_sp=0x8173ec0)
    at interpret.c:8173
0000009 0x080a5fde in eval_instruction (
    first_instruction=0x92b9aa9 "a\r\ra\bU\v\207?b*\r\016*\020c??",
    initial_sp=0x8173e80) at interpret.c:14664
0000010 0x0810858a in catch_instruction (flags=0, offset=24, i_sp=0x823dcc0,
    i_pc=0x92b9aa9 "a\r\ra\bU\v\207?b*\r\016*\020c??", i_fp=0x8173e50,
    reserve_cost=65536, i_context=0x0) at simulate.c:447
0000011 0x08096f4e in eval_instruction (
    first_instruction=0x92b9c6a "`\001\002a\017\003@\036",
    initial_sp=0x8173e40) at interpret.c:9381
0000012 0x080ad5b5 in apply_low (fun=0x9251528, ob=0x92a7210, num_arg=1,
    b_ign_prot=0, allowRefs=0) at interpret.c:16698
0000013 0x080adc14 in int_apply (fun=0x9251528, ob=0x92a7210, num_arg=1,
    b_ign_prot=0, b_use_default=1) at interpret.c:16889
#14 0x080ae07e in sapply_int (fun=0x9251528, ob=0x92a7210, num_arg=1,
    b_find_static=0, b_use_default=1) at interpret.c:17050
#15 0x0804c9ce in parse_command (
    buff=0xbfea8570 "zlpc struct abc abc = (<abc>);", from_efun=0)
    at actions.c:1094
#16 0x0804cf41 in execute_command (
    str=0xbfea8570 "zlpc struct abc abc = (<abc>);", ob=0x91f59a4)
    at actions.c:1258
#17 0x08054999 in backend () at backend.c:671
#18 0x080c0079 in main (argc=16, argv=0xbfea9f24) at main.c:615

The reason is, that find_struct doesn't search for the global identifier (which a struct must be), but instead just takes what find_shared_identifier returns (which may be a local identifier). So find_structs may return an arbitrary number if it is a local identifier, an access to the corresponding struct definition then crashes.

I attached a patch, which fixes this.

Greetings,
Gnomi.

PS: The global case (struct abc abc as a global variable) also crashes, but in a more interesting way. I'll make another bug entry for this.
TagsNo tags attached.
External Data (URL)

Activities

2006-11-14 05:59

 

structs.diff (566 bytes)   
Index: trunk.structs/src/prolang.y
===================================================================
--- trunk.structs/src/prolang.y	(Revision 2312)
+++ trunk.structs/src/prolang.y	(Arbeitskopie)
@@ -4118,6 +4118,11 @@
     ident_t * p;
 
     p = find_shared_identifier(get_txt(name), I_TYPE_GLOBAL, 0);
+
+    /* Find the global struct identifier */
+    while (p != NULL && p->type != I_TYPE_GLOBAL)
+        p = p->inferior;
+
     if (p == NULL || p->u.global.struct_id < 0)
         return -1;
     if (STRUCT_DEF(p->u.global.struct_id).flags & NAME_HIDDEN)
structs.diff (566 bytes)   

lars

2007-10-14 02:28

reporter   ~0000571

Implemented the patch.

Issue History

Date Modified Username Field Change
2006-11-14 05:59 Gnomi New Issue
2006-11-14 05:59 Gnomi File Added: structs.diff
2007-10-14 02:28 lars Status new => resolved
2007-10-14 02:28 lars Fixed in Version => 3.3.716
2007-10-14 02:28 lars Resolution open => fixed
2007-10-14 02:28 lars Assigned To => lars
2007-10-14 02:28 lars Note Added: 0000571
2010-11-16 10:42 lars Source_changeset_attached => ldmud.git master 9d3f495b
2018-01-29 19:59 lars Source_changeset_attached => ldmud.git master 9d3f495b
2018-01-29 22:57 lars Source_changeset_attached => ldmud.git master 9d3f495b