🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.vms
Article #236

Re: More PHP vulnerabilities

#236
From: Dan Cross
Date: Sun, 22 Nov 2026 05:43
168 lines
5691 bytes
In article <11dtg8h$isan$1@dont-email.me>,
Arne Vajhøj <arne@vajhoej.dk> wrote:
>On 11/21/2026 6:58 PM, Dan Cross wrote:
>> In article <6b021bab$0$672$14726298@news.sunsite.dk>,
>> Arne Vajhøj <arne@vajhoej.dk> wrote:
>>> On 11/20/2026 3:24 PM, Arne Vajhøj wrote:
>>>> On 11/20/2026 3:10 PM, Simon Clubley wrote:
>>>>> [snip]
>>>> Doesn't C require/mandate short circuiting in cases like this??
>>>
>>> I believe the VMS landscape looks like:
>>>
>>>               Undefined(*) L to R    L to R
>>>                            all       short circuit
>>> [snip]
>>> VMS Fortran  .and.
>>>               .or.
>>> VMS Pascal   and                    and_then
>>>               or                     or_else
>>> C                         &         &&
>>>                            |         ||
>>> Ada          and                    and then
>>>               or                     or else
>>> Java                      &         &&
>>>                            |         ||
>>> Python                    &         and
>>>                            |         or
>>> PHP                       &         &&
>>>                            |         ||
>>>                                      and(**)
>>>                                      or(**)
>>> [snip]
>>
>> For C, Java, Python, and (probably?) PHP, you are mixing up
>> different categories of operators: `&` and `|` are bitwise
>> operators in those languages, while `&&` and `||` are boolean
>> operators.  Since they are intended to do differnt things, the
>> semantics are different.
>
>Those 4 are a bit different.
>
>Java has both bitwise & and | on integer types and logical & and | on
>booleans.

Eh...kinda.  It's true that Java has well-defined bitwise
operators on booleans, but it's really just expressing the
integer rules for a type that can only have two values.  It's
still a bitwise-operation.

>In C and Python bool are sort of an int so bitwise and logical
>are the same.
>
>PHP just auto converts booleans to ints for bitwise operator.
>
>But all 4 quacks like a duck.
>
>> I doubt that there are many many languages that would introduce
>> short-circuiting behavior for bitwise operators.  But note also
>> that we may see behaviors like this:
>>
>> ```c
>> 	#include <stdio.h>
>> 	int
>> 	main(void)
>> 	{
>> 		int a = 1, b = 2;
>>
>> 		if (a)
>> 			printf("a is true\n");
>> 		if (b)
>> 			printf("b is true\n");
>> 		if (a & b)
>> 			printf("both are true\n");
>> 		else
>> 			printf("but `&` is not a boolean operator\n");
>>
>> 		return 0;
>> 	}
>> ```
>
>Good point.
>
>The problem here is the use of int instead of bool.

Incorrect.

>#include <stdio.h>
>#include <stdbool.h>
>
>int main()
>{
>     bool a = 1, b = 2;

This does not do what you think that it does.

>     if (a)
>         printf("a is true\n");
>     if (b)
>         printf("b is true\n");
>     if (a & b)
>         printf("both are true\n");
>     else
>         printf("but `&` is not a boolean operator\n");
>
>     return 0;
>}
>
>Outputs a different result.

Because in this case, `a` and `b` are both equal to (integer) 1.
The assignment `bool b = 2` sets `b` to `true` (any non-zero
integer constant is "true" in a boolean context in C), and
`true` has the value 1 (C23, sec 6.4.4.6, para 3).

An object of type `bool` in C has exactly one value-holding bit,
and `sizeof(bool)*CHAR_BIT-1` padding bits (C23, sec 6.2.6.2,
para 1).

When applied to a bitwise operator like `&` or `|`, both `a` and
`b` will first be converted to a (signed) `int` based on the
rank of the `bool` type and the rules for integer promotions
(C23, sec 6.3.1.1).

```
term% cat bitwise.c
#include <stdbool.h>
#include <stdio.h>
int
main(void)
{
        bool a = 1, b = 2;
        if (a)
                printf("a is true\n");
        if (b)
                printf("b is true\n");
        if (a & b)
                printf("both are true (a = %d, b = %d)\n", a, b);
        else
                printf("but `&` is not a boolean operator\n");
        return 0;
}
term% make bitwise
cc -O2 -pipe    -o bitwise bitwise.c
term% ./bitwise
a is true
b is true
both are true (a = 1, b = 1)
term%
```

>But treating int's as booleans is an integrated part
>of C.

In C, `bool` is an integer type.  The usual arithmetic
conversions apply, including the integer promotion rules.

>And it has spilled over to many other languages.
>
>So yes - if working with int's instead of bool's,
>then bitwise operators can not be used as logical
>operators.

No.  In all cases, bitwise operators are doing bitwise
operations.  They are simply not boolean operators, even if
applied to boolean values.

	- Dan C.
Technical Details
Message-ID: <11dtvdd$m1q$1@reader2.panix.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
References: <11dnpep$2kvk6$2@dont-email.me> <6b021bab$0$672$14726298@news.sunsite.dk> <11dtb70$t8$1@reader2.panix.com> <11dtg8h$isan$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.os.vms
Subject: Re: More PHP vulnerabilities
Date: Sun, 22 Nov 2026 05:43:09 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <11dtvdd$m1q$1@reader2.panix.com>
References: <11dnpep$2kvk6$2@dont-email.me> <6b021bab$0$672$14726298@news.sunsite.dk> <11dtb70$t8$1@reader2.panix.com> <11dtg8h$isan$1@dont-email.me>
Injection-Date: Sun, 22 Nov 2026 05:43:09 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
	logging-data="22586"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)