Compare Hex to Decimal

jpotter-varnish at jpotter-varnish at
Sat Apr 14 14:06:26 UTC 2018

Hi Michael,

I did something similar to this several years back using inline C: <>

I’m super-rusty on my C, so ask better minds, but I’d start by doing the if check in C and leaving the rest of the logic in VCL. I.e.
strtol() with a base of 16 (see <>) and then a direct check of that against gmtime() - delta (hopefully your unix hex timestamps in UTC?). Double-check the input to strtol is safe — this approach has untrusted inputs getting run through into C.


> On Apr 13, 2018, at 11:42 AM, Michael Kennedy <michael at> wrote:
> Hi,
> I have a URL that contains a Unix hex timestamp (something like 5ace8c5d). The timestamp should be within X minutes of now, and is used as part of an access control mechanism. I want to do something like this:
> if (std.time(req.http.x-hextime, now) < now - 1w) {
> ...
> }
> Is there an efficient way in VCL to either convert Hex to Dec so that this comparison can be done, or some other solution that does not involve changing the data in the URL.
> Thanks,
> Michael
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at <mailto:varnish-misc at>
> <>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list