In article <11e2…@dont-email.me>, Simon Clubley <club…@remove_me.eisner.decus.org-Earth.UFP> wrote:
>On 2026-11-20, Arne Vajhøj <ar…@vajhoej.dk> wrote:
>> On 11/20/2026 3:10 PM, Simon Clubley wrote:
>>> On 2026-11-20, Arne Vajhøj <ar…@vajhoej.dk> wrote:
>>>> On 11/19/2026 4:25 PM, Arne Vajhøj wrote:
>>>>> echo file_get_contents("http://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>>> //echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>>> echo file_get_contents("https://arnepc5.vajhoej.dk/reveal.aspx", false, >>>>> stream_context_create($sslctxopts)) . "\n"; >>>>> echo file_get_contents("HTTPS://arnepc5.vajhoej.dk/reveal.aspx") . "\n"; >>>>> echo file_get_contents("httpS://arnepc5.vajhoej.dk/reveal.aspx") . "\n";
>>>>
>>>>> $ php another.php >>>>> Port = 80 >>>>> Port = 443 >>>>> Port = 80 >>>>> Port = 80
>>>> And for the curious - before fix: >>>> >>>> use_ssl = resource->scheme && (ZSTR_LEN(resource->scheme) > 4) && >>>> ZSTR_VAL(resource->scheme)[4] == 's';
>>> >>> I really hope that line was always compiled by a short-circuiting >>> compiler and that line always successfully triggered short-circuiting... >>> >>> Don't be surprised if everyone is now looking for similar constructs >>> that rely on short-circuiting to be safe.
>> Doesn't C require/mandate short circuiting in cases like this?? >>
> >As Dan has pointed out, yes. However, I absolutely hate that style of >coding (and the use of short circuiting in general) - it is way too fragile. > >It depends on the compiler behaving as expected and it depends on someone >not making some edit change that happens to have the unexpected side-effect >of disabling any working short circuiting.
I'm going to have to push back on this. Short-circuiting of boolean operators, in C, is a defined part _of the language_ and is specified by an international standard. If a compiler is miscompiling them, then that's a compiler bug or a language that is not C.
>Seriously. Please consider not using short circuiting and instead writing >your code so it works regardless of whether your compiler short-circuits >or not. (Or it suddenly decides to stop short-circuiting one day).
This begs the question: what other parts of the language should we not use?
>Oh, and before you all start mocking me, please read this: > >https://www.redhat.com/en/blog/security-flaws-caused-compiler-optimizations
Apples and oranges, I'm afraid; that post concerns optimizations in the face of _undefined behavior_, which is a concept that is specified in the C standard. But short-circuiting is well-defined.
>Even Linux has been caught out in the past by compilers not behaving >as expected.
Linux is full of bugs, and that's exactly what this is. The compiler is right; Linux was wrong. Here's the TAP/TUN example from that post: 1? static unsigned int tun_chr_poll(struct file *file, poll_table * wait) 2? { 3? struct tun_file *tfile = file->private_data; 4? struct tun_struct *tun = __tun_get(tfile); 5? struct sock *sk = tun->sk; 6? unsigned int mask = 0; 7? if (!tun) 8? return POLLERR; The issue here is that dereferncing a NULL pointer is undefined behavior, which is behavior for which the C standard imposes abolutely _no_ requirements. Thus, a compiler is free to assume that it does not exist/does not occur; in this case, on line 5, we dereference `tun` (to get its `sk` member). But since deref'ing a NULL pointer is UB, the compiler is free to assume that it doesn't happen; then, on line 7, the compiler elides the conditional (and return) since it "knows" that `tun` cannot be nil, since it was dereferenced on line 5. But this is _qualitatively different_ than relying on short-circuiting for `&&` and `||`, which (again) is explicitly defined by the language. - Dan C.