Bounds / sanity checking on OSWORD F

discussion of beeb/electron applications, languages, utils and educational s/w
dominicbeesley
Posts: 431
Joined: Tue Apr 30, 2013 11:16 am

Bounds / sanity checking on OSWORD F

Postby dominicbeesley » Sun Oct 15, 2017 6:40 pm

Hello all,

I've been experimenting with this today and it seems on the Master that there is little sanity checking of the string passed to OSWORD &F (set RTC) and if an odd string is passed in the time gets set to something weird.

Does anyone know if this behaviour was carried through to Arthur/Risc OS? I'd dig an ARC out of storage but I think if I got caught by my partner (who has been packing stuff away all weekend) I would be murdered

I'm adding this into my 6809 MOS and for now I'm going to go the easy route and not do any checking but if I did what should I do on encountering an out of bounds string:
- continue and set weird values
- ignore and return silently
- BRK, if so what error number/message?

D

User avatar
jgharston
Posts: 2728
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Bounds / sanity checking on OSWORD F

Postby jgharston » Sun Oct 15, 2017 10:36 pm

dominicbeesley wrote:I've been experimenting with this today and it seems on the Master that there is little sanity checking of the string passed to OSWORD &F (set RTC) and if an odd string is passed in the time gets set to something weird.
Does anyone know if this behaviour was carried through to Arthur/Risc OS? I'd dig an ARC out of storage but I think if I got caught by my partner (who has been packing stuff away all weekend) I would be murdered

I was looking at this a couple of days ago when trying to find some time to reply to your last email. ;)
Arthur and RISC OS effectively do:
IF len=5 THEN set from 5-byte centisecond time
ELSE IF len=8 THEN set time
ELSE IF len=15 THEN set date
ELSE IF len=24 THEN set date and time
ELSE return

MOS 3.20 does
IF len=15 THEN set date
ELSE IF len=8 THEN set time
ELSE IF len=24 THEN set date and time
ELSE return

Setting the date checks the day against a string "Sun.Mon.Tue.Wed.Thu.Fri.Sat." Looking at the code my first impression is that it doesn't enforce checking at the start of each day string, so a string "n"+CHR$1+"M" would get matched as day number ASC"o". It does a similar check for the month name, so "n"+CHR$1+"F" might get matched as month number ASC"e". Is that the sort of thing you're seeing?

dominicbeesley wrote:I'm adding this into my 6809 MOS and for now I'm going to go the easy route and not do any checking but if I did what should I do on encountering an out of bounds string:
- continue and set weird values
- ignore and return silently
- BRK, if so what error number/message?

OSWORD never ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever generate an error, they return an error condition. OSWORDs that do generate errors are broken. The programming convention is blah blah CALL OSWORD:result=controlblock?offset:blah blah

For using an unknown length byte with OSWORD 15 you should just return silently. Calls that use an unrecognisable day or month should just return silently. Ideally, the day should be ignored and be calculated from the date, but setting the date is a rarer operation than reading the date, so is reasonable for the caller to do the day=dayfromdate(d,m,y) calculation.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

dominicbeesley
Posts: 431
Joined: Tue Apr 30, 2013 11:16 am

Re: Bounds / sanity checking on OSWORD F

Postby dominicbeesley » Sun Oct 15, 2017 10:49 pm

Thanks JGH for the comprehensive answer. I've got it going pretty much as you have outlined. I'm starting to get tight for space is the ROM so my day/month tables are three chars.

Do you happen to have the address of these routines in the 3.20 MOS handy, I started wading through the disassembly but kept getting interrupted and never got further than the OS(BYTE|WORD) dispatch function and always seem to end up in the wrong place...

D

PS: Bugger I've just realised my clever shortened match routine won't work, matching on two chars for dates is no good...I'll make it the second and third...

User avatar
jgharston
Posts: 2728
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Bounds / sanity checking on OSWORD F

Postby jgharston » Sun Oct 15, 2017 11:08 pm

dominicbeesley wrote:Do you happen to have the address of these routines in the 3.20 MOS handy

&9640 onwards. I'll upload the latest comments in a mo, search through it for OSWORD &0F, link).

Checking in more detail, if the supplied data mismatches in *any* way, OSWORD &0F just returns.
The supplied string must be Day,00_Mon_0000.00:00:00 and if any character isn't there the call exits, if Day does not exactly match Sun,Mon,Tue,Wed,Thu,Fri,Sat ignoring case it exits, if Mon does not exactly match Jan,Feb,you get the picture. If the numbers are not decimal numbers, the call exits, if the hh is larger than 23 it exits, if mm/ss are larger than 59 the call exits.

The actual code is fairly inefficiently written, but very conservative in what it swallows. It can quite easily be optimised and still give the same results. I wouldn't be surprised if the code in MOS 3.50 is more efficient.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

dominicbeesley
Posts: 431
Joined: Tue Apr 30, 2013 11:16 am

Re: Bounds / sanity checking on OSWORD F

Postby dominicbeesley » Mon Oct 16, 2017 10:45 am

Thanks JGH,I'll have a look tonight - I went for a laissez faire option to get it working without running out of ROM space, I'm getting close to needing a second ROM slot for the MOS as the debugger takes up a few pages, the comments in the MOS320 src are a real help, I thank you for all your efforts!

Thanks for the commented code - looking much more clear now! I need to sort my MOS out into a two ROM job like the Master sooner rather than later, but before I do that I want to look at the whole issue of ROMS and how to get round the 16 ROM limit without resorting to hackery....might be time to start the modules thing I mentioned a while back?

User avatar
BeebMaster
Posts: 2470
Joined: Sun Aug 02, 2009 4:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Bounds / sanity checking on OSWORD F

Postby BeebMaster » Mon Oct 16, 2017 4:06 pm

In February 2013 I made an as-yet-unpublished picture set on clock setting with TIME$ and OSWORD 14 & 15.

MOS 3.20 will accept all kinds of rubbish being sent to it.

It accepts the day whether it's right or not; it isn't case sensitive and nor is the month:
CMOSTime13binfo only.jpg


It will accept an illegal day in the month, but corrects itself at the end of the 31st day:
CMOSTime17.jpg


It will in fact accept up to 99 in the day and illegal hour and minute numbers:
CMOSTime29.jpg


There appears to be (yet another) error in the Reference Manual:
CMOSTime72.jpg


Using OSWORD 14 with code 2 to convert BCD to string and then setting using OSWORD 15 with the string generated, you can still feed it dodgy data:
CMOSTime84.jpg
Image

dominicbeesley
Posts: 431
Joined: Tue Apr 30, 2013 11:16 am

Re: Bounds / sanity checking on OSWORD F

Postby dominicbeesley » Tue Oct 17, 2017 9:19 am

Thanks BeebMaster, that's pretty much where I got to, it's strange that there must be millions of run time clock chips in PCs carrying around those unnecessary bits for months > 12 and days > 31!

JGH: http://mdfs.net/Docs/Comp/BBC/Oswords needs a quick tweak - the reason code for date but not time is stated as 16 - should be 15, that had me going for a while!


Return to “software: other”

Who is online

Users browsing this forum: No registered users and 1 guest