mvslovers/brexx370

Probable integer owerflow issue

Closed this issue · 3 comments

Hello everyone,
this time I have a problem with BREXX.V2R4M0.CMDLIB(IPLDATE), specifically with the following line:

rmcttod = _adr (rmct () + 124)

as far as I can understand the value should be 4 bytes (unsigned) and it seems to me that it is silently converted to a signed integer and therefore the value in rmcttod is negative. From this point on, nothing makes sense anymore. As a result I get a future IPL date and a negative uptime! The real uptime reported e.g. by DUPTIME is > 36 days.

Marco

Marco, please do me a favour, send me the content of rmcttod (= _adr (rmct () + 124)). I need to see which number it is. According to your investigation, it must be a negative number, but I wonder how this possibly can be,

tickfactor=1.024
rmcttod=_adr(rmct()+124)
say rmcttod
iplsec=RMCTTOD%1000*tickfactor
ipldays=iplsec%86400
iplrem=iplsec//86400%1
days1900=Rxdate('b')-ipldays
ipldate=Rxdate(,days1900,'B')
iplwday=Rxdate('WEEKDAY',days1900,'B')
cursec=time('s')-iplsec
do while cursec<0
cursec=cursec+86400
end
say 'Current Time 'time('L')
say 'IPL on 'iplwday' 'ipldate' at 'sec2time(cursec)
say 'MVS up for 'ipldays' days 'sec2time(iplrem)' hours'
exit

cvt: return _adr(16)
rmct: return _adr(cvt()+604)
_adr: return c2d(storage(d2x(arg(1)),4))

READY
rx ipldate
-1248752839
Current Time 16:15:04.659172
IPL on Sunday 27/06/2021 at 71:27:06
MVS up for -14 days 19:12:-2 hours
READY
duptime
SYSTEM TK4- HAS BEEN UP FOR 36 DAYS 02:28:45
READY

If I add the line:
call dumpit d2x(rmct()+124),4
the output is:
0003E564 (+00000000) | B5A29266 | .sk.
-1247636890
Current Time 16:34:07.536296
IPL on Sunday 27/06/2021 at 71:27:06
MVS up for -14 days 18:52:59 hours

B5A29266 read as a signed "dword" or "qword" is exactly -1247636890

Marco

The problem arises from treating an unsigned integer as an integer. If the integer exceeds the maximum of +2,147,483,647 it turns into a negative number. In BREXX V2R5M0 is a c2U() function integrated, which returns the unsigned integer as a numeric string. You can use the numeric string in calculations, then it is internally converted into a float number.