ntpsec | Authenticated out-of-bounds write in ntp_parser.y (#510)

Hal Murray hmurray at megapathdsl.net
Thu Nov 1 10:28:57 UTC 2018


esr at thyrsus.com said:
> I'm a little reluctant to add C macroloogy at this point. Plans for Go
> translation aren't *on* the horizon at this point, but they're not far over
> it.

The current code has things like:
#define CS_LEAP                 1
#define CS_STRATUM              2
#define CS_PRECISION            3
#define CS_ROOTDELAY            4
...

That makes it hard to insert something.  Is there any way to get the next 
number.  I'd like to do something like
#magic foo++
#define xxx $foo


> On the other hand generating one nice table from declarative markup with a
> Python helper would map over well to Go when we get there, and is the sort of
> "do things as declratively as possible, as high level as possible" technique
> that Ian should be learning. 

The places where it gets used:
        { CS_LEAP,      RW, "leap" },           /* 1 */
        { CS_STRATUM,   RO, "stratum" },        /* 2 */
        { CS_PRECISION, RO, "precision" },      /* 3 */
        { CS_ROOTDELAY, RO, "rootdelay" },      /* 4 */
That's to translate a string to a magic number which happens to be the index 
into a table.

and
        case CS_LEAP:
                ctl_putuint(sys_var[CS_LEAP].text, sys_vars.sys_leap);
                break;

        case CS_STRATUM:
                ctl_putuint(sys_var[CS_STRATUM].text, sys_vars.sys_stratum);
                break;

        case CS_PRECISION:
                ctl_putint(sys_var[CS_PRECISION].text, sys_vars.sys_precision);
                break;
That's to translate the named slot into a printed value.

It's possible that we don't need a name for the index.  If we extend the first 
table with a value to be printed and a tag for the type of value, then we can 
pass around a pointer to the slot rather than a magic number.

The key idea is to collect all the info in one place.  I don't know if a 
pre-processor is necessary or appropriate.


-- 
These are my opinions.  I hate spam.





More information about the devel mailing list