View Issue Details

IDProjectCategoryView StatusLast Update
0005281unrealircdpublic2019-11-27 16:48
Reportersyzop Assigned Tosyzop  
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Fixed in Version5.0.0-rc2 
Summary0005281: Configuration file ideas: define and conditional sections
Description1. define variables
2. condition sections with "if"
2a. based on defines
2b. based on if a module is loaded
TagsNo tags attached.
3rd party modules

Relationships

related to 0004144 resolvedsyzop Define Variables in config file. 
child of 0005279 closedsyzop UnrealIRCd 5 master tracking issue 

Activities

syzop

2019-05-17 15:10

administrator   ~0020676

Current idea after discussion is to support these things:
$define IPADDR xyz
listen { ip $IPADDR; .... }


$define SERVER "hub.example.org"
$if $SERVER == "hub.example.org"
link {
...
}
$endif


$if module-loaded("something")
block {
}
block {
}
$endif


helpop {
        xyz
        xyz
$if module-loaded("something")
        zzz
        zzz
$endif
        xyz
        xyz
}

syzop

2019-05-17 15:15

administrator   ~0020677

Last edited: 2019-05-17 15:15

I will probably do it as follows:
1. Load the includes
2. Resolve define's globally (result: it won't matter where the $define is, as this will be done in configuration file pass 1)
3. The $if's based on defines can then be resolved (sections enabled or disabled)
4. Load the modules
5. The $if's based on module-loaded() can then be resolved (sections enabled or disabled)

Limitations:
1. You cannot have an include within an $if, but you can do it in the include itself.
So NOT:
$if module-loaded("something")
include "something.conf"
$endif

But YES by doing it in the included file itself:
$if module-loaded("something")
....
$endif


2. You cannot $define within an $if

I think even with these limitations it will be quite nice :)

syzop

2019-05-17 15:21

administrator   ~0020678

Operations supported in $if:
$XYZ == "something"
$XYZ != "something"
module-loaded("something")
!module-loaded("something")
defined($XYZ)
!defined($XYZ)

No || or &&

syzop

2019-05-17 20:52

administrator   ~0020679

Just committed some stuff. Most things done.
Still need to do variable name/value replacement (so you can use $IPADDR if you used $define IPADDR... before...). And also cleanups and fixing some small issues (memory leak).

NOTE TO SELF: I think I forgot phase 1 so far, it has only phase 2 atm.

Also document limitations

syzop

2019-05-18 13:35

administrator   ~0020680

Limitations:
- you cannot use an include within an $if module-loaded()... [because of of the config sequence, pretty much impossible to solve] [too bad]
- you cannot use a loadmodule within an $if module-loaded()... [because of of the config sequence, pretty much impossible to solve] [not a problem I think]
- you cannot use $define within an $if.... [because I add defines straight away, this could be changed.... some day..]

syzop

2019-05-18 14:15

administrator   ~0020682

I've put 90% of the stuff in src/conf_preprocessor.c to make it look a bit more clean.
Actually source should still receive some cleanup ;)

Still to do:
1. Warn on limitations (see previous)
2. Replacement of defines in variable name/values in the conf, so you can use "ip $IPADDR;"

syzop

2019-05-25 15:52

administrator   ~0020696

TODO: fix some memory leak(s)
Maybe support $else? Or not.. because that could imply $elseif or $else..$if.. which we are unlikely to support soon ;)

syzop

2019-08-18 16:10

administrator   ~0020833

Last edited: 2019-08-18 16:13

So I guess the current implementation is doing well.
TODO:
* It has 1 or 2 TODO/FIXME's that I still need to investigate
* Should warn on limitation (see few bugnotes up). It's not bad that there are a few limitations but we should really warn about them if possible.
* What, comments from above claim replacement of variables is still a TODO item? To my knowledge it is working already. Did not test within "" strings and such though.

syzop

2019-09-17 18:27

administrator   ~0020897

This does not appear to be working. Reported by Gottem and westor... so... I should definitely look into that.

syzop

2019-10-06 07:42

administrator   ~0020936

Was fixed in alpha3.

Only reason this issue is still open is due to some warnings that should be fired in some corner cases.

Gottem

2019-10-09 21:19

developer   ~0020949

Welllll my IRCd crashes hard when I use some conditionals. :D

My unrealircd.conf consists of just 2 remote includes, one for global network stuff and another for per-server things. The latter defines a variable $SERVER, then in the network one there is:
@if $SERVER != "hubberino.u5.home.lan"
    loadmodule "hideserver";
    hideserver {
        disable-map yes;
        disable-links yes;
        map-deny-message "*** Command /MAP is disabled for security reasons";
        links-deny-message "*** Command /LINKS is disabled for security reasons";
    };
@endif

@if $SERVER == "hubberino.u5.home.lan"
    require module {
        name "rmtkl";
    };

    deny module {
        name "hideserver";
        reason "top keks";
    };
@endif


The server conf is included *before* the network one, so the variable should be defined before the if stuff. Switching the .conf lines around doesn't matter anyways. :D Neither does removing *either* of the @if blocks by the way. Removing both makes the IRCd boot up nicely.

Have a nice lil' dump from ASAN:
Loading IRCd configuration..
=================================================================
==5420==ERROR: AddressSanitizer: heap-use-after-free on address 0x60700000cf48 at pc 0x5555555d45b1 bp 0x7fffffffe070 sp 0x7fffffffe068
READ of size 8 at 0x60700000cf48 thread T0
    #0 0x5555555d45b0 in preprocessor_resolve_conditionals_ce /home/gottemhams/_unrealircd/src/conf_preprocessor.c:401
    #1 0x55555560c7f2 in load_conf /home/gottemhams/_unrealircd/src/conf.c:2069
    #2 0x55555560bcff in remote_include /home/gottemhams/_unrealircd/src/conf.c:10198
    #3 0x55555560c28e in _conf_include /home/gottemhams/_unrealircd/src/conf.c:3136
    #4 0x55555560c92b in load_conf /home/gottemhams/_unrealircd/src/conf.c:2087
    #5 0x55555560d495 in init_conf /home/gottemhams/_unrealircd/src/conf.c:1879
    #6 0x5555555c0e2e in main /home/gottemhams/_unrealircd/src/ircd.c:1256
    #7 0x7ffff53dfb44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)
    0000008 0x5555555a14d8 (/home/gottemhams/ircd/bin/unrealircd+0x4d4d8)

0x60700000cf48 is located 56 bytes inside of 72-byte region [0x60700000cf10,0x60700000cf58)
freed by thread T0 here:
    #0 0x7ffff6f59527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
    #1 0x5555555db7e6 in config_entry_free /home/gottemhams/_unrealircd/src/conf.c:1211
    #2 0x5555555d467a in preprocessor_resolve_conditionals_ce /home/gottemhams/_unrealircd/src/conf_preprocessor.c:414
    #3 0x55555560c7f2 in load_conf /home/gottemhams/_unrealircd/src/conf.c:2069
    #4 0x55555560bcff in remote_include /home/gottemhams/_unrealircd/src/conf.c:10198
    #5 0x55555560c28e in _conf_include /home/gottemhams/_unrealircd/src/conf.c:3136
    #6 0x55555560c92b in load_conf /home/gottemhams/_unrealircd/src/conf.c:2087
    #7 0x55555560d495 in init_conf /home/gottemhams/_unrealircd/src/conf.c:1879
    0000008 0x5555555c0e2e in main /home/gottemhams/_unrealircd/src/ircd.c:1256
    #9 0x7ffff53dfb44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)

previously allocated by thread T0 here:
    #0 0x7ffff6f59885 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54885)
    #1 0x555555631146 in safe_alloc /home/gottemhams/_unrealircd/src/support.c:716
    #2 0x5555555ddcda in config_parse /home/gottemhams/_unrealircd/src/conf.c:1153
    #3 0x5555555de3d7 in config_load /home/gottemhams/_unrealircd/src/conf.c:805
    #4 0x55555560c756 in load_conf /home/gottemhams/_unrealircd/src/conf.c:2060
    #5 0x55555560bcff in remote_include /home/gottemhams/_unrealircd/src/conf.c:10198
    #6 0x55555560c28e in _conf_include /home/gottemhams/_unrealircd/src/conf.c:3136
    #7 0x55555560c92b in load_conf /home/gottemhams/_unrealircd/src/conf.c:2087
    0000008 0x55555560d495 in init_conf /home/gottemhams/_unrealircd/src/conf.c:1879
    #9 0x5555555c0e2e in main /home/gottemhams/_unrealircd/src/ircd.c:1256
    #10 0x7ffff53dfb44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)

SUMMARY: AddressSanitizer: heap-use-after-free /home/gottemhams/_unrealircd/src/conf_preprocessor.c:401 preprocessor_resolve_conditionals_ce
Shadow bytes around the buggy address:
  0x0c0e7fff9990: fd fd fd fd fd fd fd fa fa fa fa fa fd fd fd fd
  0x0c0e7fff99a0: fd fd fd fd fd fa fa fa fa fa fd fd fd fd fd fd
  0x0c0e7fff99b0: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c0e7fff99c0: fd fa fa fa fa fa fd fd fd fd fd fd fd fd fd fa
  0x0c0e7fff99d0: fa fa fa fa fd fd fd fd fd fd fd fd fd fa fa fa
=>0x0c0e7fff99e0: fa fa fd fd fd fd fd fd fd[fd]fd fa fa fa fa fa
  0x0c0e7fff99f0: fd fd fd fd fd fd fd fd fd fa fa fa fa fa fd fd
  0x0c0e7fff9a00: fd fd fd fd fd fd fd fa fa fa fa fa 00 00 00 00
  0x0c0e7fff9a10: 00 00 00 00 00 fa fa fa fa fa 00 00 00 00 00 00
  0x0c0e7fff9a20: 00 00 00 fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c0e7fff9a30: 00 fa fa fa fa fa 00 00 00 00 00 00 00 00 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Contiguous container OOB:fc
  ASan internal:           fe

syzop

2019-10-10 07:40

administrator   ~0020950

Thanks, I'll check it out this evening or tomorrow.

syzop

2019-11-27 13:34

administrator   ~0021129

I can reproduce the issue. Defined in included conf and used in another causes a crash. The other way around (defined in unrealircd.conf and used in eg network.conf) does not.. that's why I missed it I guess.

I will take a look...

syzop

2019-11-27 15:49

administrator   ~0021130

Bug from above fixed. The code to remove an @if block that didn't match didn't work properly.
Also, I tested @define in one included conf, and using it in another included conf. This works if they are in order but not in reverse order. That is as intended, though.

syzop

2019-11-27 16:48

administrator   ~0021131

And warning on limitations.

Only thing I couldn't raise a warning on is a @define within an @if. This is because it happens so super early in the parser process that it doesn't even know it is inside a @define. Hopefully that won't catch too many users... hmm.. ;)

Anyway, done for now!

Issue History

Date Modified Username Field Change
2019-05-17 15:09 syzop New Issue
2019-05-17 15:10 syzop Note Added: 0020676
2019-05-17 15:15 syzop Note Added: 0020677
2019-05-17 15:15 syzop Note Edited: 0020677
2019-05-17 15:21 syzop Note Added: 0020678
2019-05-17 20:52 syzop Note Added: 0020679
2019-05-17 20:52 syzop Assigned To => syzop
2019-05-17 20:52 syzop Status new => assigned
2019-05-18 13:35 syzop Note Added: 0020680
2019-05-18 14:05 syzop Relationship added child of 0005279
2019-05-18 14:15 syzop Note Added: 0020682
2019-05-25 15:52 syzop Note Added: 0020696
2019-08-18 15:17 syzop View Status private => public
2019-08-18 16:10 syzop Note Added: 0020833
2019-08-18 16:13 syzop Note Edited: 0020833
2019-08-18 16:13 syzop Note Edited: 0020833
2019-09-17 18:27 syzop Note Added: 0020897
2019-10-06 07:42 syzop Note Added: 0020936
2019-10-09 21:19 Gottem Note Added: 0020949
2019-10-10 07:40 syzop Note Added: 0020950
2019-10-14 14:55 syzop Relationship added related to 0004144
2019-11-27 13:34 syzop Note Added: 0021129
2019-11-27 15:49 syzop Note Added: 0021130
2019-11-27 16:48 syzop Status assigned => resolved
2019-11-27 16:48 syzop Resolution open => fixed
2019-11-27 16:48 syzop Fixed in Version => 5.0.0-rc2
2019-11-27 16:48 syzop Note Added: 0021131