On Mon, 22 Mar 2021, at 22:30, Paul Gilmartin wrote:
> On Mon, 22 Mar 2021 19:41:10 +0000, Jeremy Nicoll wrote:
>
> >On Mon, 22 Mar 2021, at 19:27, Rich Tabor wrote:
> >
> > LINKAGE SECTION.
> > 01 FLD1 PIC X(08).
> > 01 FLD2 PIC X(08).
> > 01 FLD3 PIC X(20).
> > ...
> > /* REXX */
> > CBLPGM = 'TST01'
> > FLD1 = SUBSTR('AAAAAAAAAAAAAAAA',1,80)
> > FLD2 = SUBSTR('BBBBBBBBBBBBBBBB',1,80)
> > FLD3 = SUBSTR('CCCCCCCCCCCCCCCC',1,80)
> > SAY 'FLD1 =' FLD1
> > SAY 'FLD2 =' FLD2
> > SAY 'FLD3 =' FLD3
> > ADDRESS LINKPGM CBLPGM "FLD1 FLD2 FLD3"
> >
> >
> >The logic inside support for "linkpgm" knows that the first value it
> >receives is the program name, not a variable containing it, and the
> >other values are the name of variables. Linkpgm will (in this case)
> >build the parm list with three parm addresses in it.
> The lengths don't match. Is this an invitation to buffer overflow?
I considered questioning that when the earlier poster posted the
code and decided not to. I thought it was probably safe, if not
sensible.
address linkpgm will invoke the cobol program with R1 pointing
at a block of storage containing 3 addresses, with the top bit set
on the last one. Each of those addresses points to the storage
where a field value is held.
I'd expect the latter three addresses to point at either the actual
locations in rexx's variable storage where the values of fields
FLD1/2/3 are, or copies of them.
Importantly though, I would have thought that the COBOL
> > LINKAGE SECTION.
> > 01 FLD1 PIC X(08).
> > 01 FLD2 PIC X(08).
> > 01 FLD3 PIC X(20).
would mean the COBOL compiler would only generate code that
could reference the first 8/8/20 bytes of those longer areas of
memory.
If however the invoked program had been written in some
other language, eg assembler, I think there'd be nothing to
stop the assembler routine from writing into the 80-byte
areas that contain the rest of each rexx variable's value. I
have no idea what would happen if it tried to write more
than 80 bytes to each area.
> Is it simply incumbent on the programmer to ensure that the
> actual parameters are no shorter than the formal parameters?
I don't know. When I did this, long ago, albeit calling code
written in assembler, I made sure the lengths were the same.
> I assume the names don't matter; only the addresses.
I thought I had a vague recollection that the named variables
needed to have sensible variable names ie ones with name
lengths of no more than 8 characters, no special characters,
not part of a stem etc... but a quick look at a current manual
didn't back that up.
See:
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/com.ibm.zos.v2r2.ikja300/ikja30034.htm
See also the interesting discussion about how storage is handled
for fields in attchmvs and linkmvs cases, at
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.2.0/com.ibm.zos.v2r2.ikja300/ikja30031.htm
--
Jeremy Nicoll - my opinions are my own.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN