The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Exploit Condition Handling in LE © 2009 IBM Corporation Enterprise COBOL for z/OS ibm Exploit Condition Handling in LE SHARE Session 1540 August 27, 2009 Denver

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by , 2016-06-20 23:12:04

Exploit Condition Handling in LE - IBM

Exploit Condition Handling in LE © 2009 IBM Corporation Enterprise COBOL for z/OS ibm Exploit Condition Handling in LE SHARE Session 1540 August 27, 2009 Denver

Enterprise COBOL for z/OS ibm

Exploit Condition Handling in LE © 2009 IBM Corporation

SHARE Session 1540
August 27, 2009 Denver
Tom Ross

Exploit Condition Handling in LE

Enterprise COBOL for z/OS ibm

Condition Handling with LE - basics

Language Environment defines a condition as any
event that can require the attention of a running
application or the HLL routine supporting the
application.

A condition is also known as an exception, interrupt,
or signal.

Language Environment makes it possible to respond
to events that in the past might have caused a routine
to abend, including hardware-detected errors or
operating system-detected errors.

2 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling with LE - basics

All applications running under LE can use LE condition handling

– Respond to events, log them, fix them, stop or do nothing

LE always gets control first for conditions

– LE coordinates with subsystems such as IMS and CICS

• So you don’t have to!

– Even for most conditions with TRAP(OFF)

• TRAP(ON) is required for normal program behavior and IBM support

– It is possible to handle some conditions outside of LE with SPIE

• If you do it right ☺

LE then gives the application a chance to handle a condition

– Some conditions are ignored depending on language rules

• For example, overflow is not a condition in COBOL, but it is in PL/I!

3 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling with LE - basics

Condition handler

– A program that is registered with LE to get control during condition
processing

Stack-frame based

– Each program that gets called has a frame on the stack
– Main program is at stack frame zero
– Condition handlers can be registered at different stack frames

Condition token

– 12-byte field that contains information about each condition

Cursors

– RESUME cursor points to point at which execution will resume
– HANDLE cursor points to the current condition handler

4 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Example Scenario

Application that gets ABENDs from time to time

– Some ABENDs should cause the application to stop and be re-run
– Others could be logged and processed later, but application could

continue to run if you could just find a way

• Example: processing a million records, one is bad but don’t want to re-
run the entire job just for one bad record
• In this case, want to use RESUME using LE features rather than ABEND

– Want to write the code to handle errors in COBOL, not assembler

• Could also use PL/I, C or LE-conforming assembler using this approach

The answer is a user-written LE condition handler!

5 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Example Scenario

In order to do condition handling with RESUME in the
case of processing many input records, your
application might have to be redesigned

It would be easiest to RESUME at a point where you
would read the next record

Alternatives

– Inline code that processes record data
– Called subprogram that processes record data
– Paragraphs to process record data

Let’s look at all three cases

6 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Scenario – start here - inline

LOOP.
PERFORM UNTIL EOF
READ INDATA
AT END SET EOF TO TRUE
NOT AT END

***************************************************************

* Process the record data with inline statements that *

* might fail with bad data. *

***************************************************************

ADD NUMBER-FROM-INPUT-RECORD to ACCUMULATOR

COMPUTE PAYOUT = (CURRENT-AGE * BEN-FACTOR) / ADJUSTMENT

COMPUTE LINE-TOTPRC = HOLD-PRICE * (LINE-QUAN / 100)

END-READ

END-PERFORM

7 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Example Scenario

How do you handle conditions in COBOL?

First, register a condition handler
– Explicit by CALL
– Implicit by run-time option

8 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Scenario –
register handler explicitly

01 PGMPTR USAGE PROCEDURE-POINTER.
01 DATA-PTR USAGE POINTER.

PROCEDURE DIVISION.

***************************************************************

* Put name and address of user-written condition handler *

* into PROCEDURE-POINTER data item to pass to cond manager. *

***************************************************************

SET PGMPTR TO ENTRY 'USERHDLR'

***************************************************************

* Register the user-written condition handler with the *

* LE condition manager. *

***************************************************************

CALL 'CEEHDLR' USING PGMPTR DATA-PTR OMITTED.

LOOP.

PERFORM UNTIL EOF

READ INDATA

AT END SET EOF TO TRUE

NOT AT END

***************************************************************

* these statements might fail with bad data. *

***************************************************************

etc, etc

9 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Scenario –
register handler by run-time option

LE runtime option USRHDLR

– // PARM.GO='/USRHDLR(HDLER1,USERHDLR)'

– Automatically registers condition handlers

• HDLER1 for Stack Frame Zero, IE: Main Program, after any other
condition handlers have been given a chance to process the condition
• USERHDLR to handle conditions BEFORE any other condition handler

– HDLER1 cannot resume in program in which condition
occurred

– USERHDLR can resume in program which got the condition

Add condition handling to your application with no programming
changes to the application!

10 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH – set explicit resume point – Case 1

01 RECOVERY-AREA EXTERNAL.

05 RECOVERY-POINT POINTER.

05 RECOVERY-IN-PROGRESS PIC X(1).

...

LOOP.

MOVE SPACES TO RECOVERY-IN-PROGRESS

*----------------------------------------------------------------

* Set up resume point where handler could resume

*----------------------------------------------------------------

CALL 'CEE3SRP' USING RECOVERY-POINT, OMITTED

*----------------------------------------------------------------
* NOTE: the SERVICE LABEL is required.
*----------------------------------------------------------------

SERVICE LABEL
IF RECOVERY-IN-PROGRESS = 'Y' THEN

DISPLAY 'Just had a data exception‘

MOVE SPACES TO RECOVERY-IN-PROGRESS
END-IF

PERFORM UNTIL EOF

READ INDATA AT END SET EOF TO TRUE

*----------------------------------------------------------------

* these statements might fail with bad data. *

*----------------------------------------------------------------

etc, etc

11 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – USERHDLR with explicit resume point

01 RECOVERY-AREA EXTERNAL. POINTER.
05 RECOVERY-POINT PIC X(1).
05 RECOVERY-IN-PROGRESS

LINKAGE SECTION.

01 CURRENT-CONDITION.

05 FILLER PIC X(8).

COPY CEEIGZCT.

05 FILLER PIC X(4).

01 TOKEN PIC X(4).

01 RESULT-CODE PIC S9(9) BINARY.

88 RESUME VALUE +10.

88 PERCOLATE VALUE +20.

01 NEW-CONDITION PIC X(12).

PROCEDURE DIVISION USING CURRENT-CONDITION, TOKEN,
RESULT-CODE, NEW-CONDITION.

IF CEE347 OF CURRENT-CONDITION THEN
MOVE 'Y' TO RECOVERY-IN-PROGRESS
CALL 'CEEMRCE' USING RECOVERY-POINT, OMITTED
SET RESUME TO TRUE

ELSE
SET PERCOLATE TO TRUE

END-IF
GOBACK

12 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Example Scenario

How do you use symbolic feedback codes from LE?

***************************************************************

* Mapping for the 12-byte Language Environment Feedback *

* code, passed from the LE Condition Manager. *

***************************************************************

01 CURRENT-CONDITION.

05 FIRST-8-BYTES.

* CEE conditions (general LE conditions)

COPY CEEIGZCT.

* IGZ conditions (COBOL-specific conditions)

COPY IGZIGZCT.

10 C-SEVERITY PIC 9(4) USAGE COMP-5.

10 C-MSGNO PIC 9(4) USAGE COMP-5.

10 C-FC-OTHER PIC X.

10 C-FAC-ID PIC X(3).

05 C-I-S-INFO PIC 9(9) USAGE COMP-5.

13 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

**************************************************************

** IGZIGZCT COPY **

** **

** IBM Language Environment **

** **

** Licensed Materials - Property of IBM **

** **

** 5694-A01 5688-198 © Copyright IBM Corp. 1993, 2007 **

** All rights reserved **

** **

**************************************************************

* Condition Token Declarations

*

88 IGZ001 VALUE X"0000000141C9C7E9".

88 IGZ002 VALUE X"0003000259C9C7E9".

88 IGZ003 VALUE X"0001000349C9C7E9".

88 IGZ004 VALUE X"0003000459C9C7E9".

88 IGZ005 VALUE X"0003000559C9C7E9".

88 IGZ006 VALUE X"0003000659C9C7E9".

88 IGZ007 VALUE X"0003000759C9C7E9".

88 IGZ008 VALUE X"0000000841C9C7E9".

88 IGZ009 VALUE X"0004000961C9C7E9".

88 IGZ00A VALUE X"0000000A41C9C7E9".

etc

etc

14 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

* Symbolic *

* Condition ABEND Error description *

* Token Code (U10xx ABENDs are VS COBOL II equivalents)*

* ------- ----- ------------------------------------- *

* IGZ006: U1006 SSRANGE error, reference outside of table*

* IGZ00F: U1015 Recursive call to routine *

* IGZ013: U1035 Unsuccessful OPEN or CLOSE of file *

* IGZ01Q: U1058 Exponent overflow occurred *

* CEE341: 0C1 Operations exception *

* CEE342: 0C2 Privileged-Operation Exception *

* CEE343 0C3 Execute exception *

* CEE344 0C4 Protection exception *

* CEE345 0C5 Addressing exception *

* CEE346 0C6 Specification exception *

* CEE347 0C7 Data exception *

* CEE348 0C8 Fixed-point overflow *

* CEE349 0C9 Fixed-point divide exception *

* CEE34A 0CA Decimal-overflow exception *

* CEE34B 0CB Decimal-divide exception *

* CEE34C 0CC Exponent-overflow exception *

* CEE34D 0CD Exponent-underflow exception *

* CEE34E 0CE Significance exception *

* CEE34F 0CF Floating-point divide exception *

* CEE35I xxxx System or User ABEND xxxx *

* CEE3DD S806 Module not found. *

*****************************************************************

15 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – no resume point – subroutine Case 2

***************************************************************

* Put name and address of user-written condition handler *

* into PROCEDURE-POINTER data item to pass to cond manager. *

***************************************************************

SET PGMPTR TO ENTRY 'USERHDLR'

***************************************************************

* Register the user-written condition handler with the *

* LE condition manager. *

***************************************************************

CALL 'CEEHDLR' USING PGMPTR DATA-PTR FC.

LOOP.

PERFORM UNTIL EOF

READ INDATA AT END SET EOF TO TRUE
NOT AT END
*----------------------------------------------------------------
* Call subroutine to process data from the record
*----------------------------------------------------------------

CALL ‘CBLSUB' USING DATA-FIELDS-FROM-INPUT-RECORD
END-READ
*----------------------------------------------------------------
* Control will return here with ‘normal’ move resume cursor
*----------------------------------------------------------------
END-PERFORM

16 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – USERHDLR without resume point

*-----------------------------------------------------------------
* Move resume cursor RELATIVE resume types:
*
* TYPE-0 = resume in instruction following instruction that failed
* NOTE: not the following STATEMENT
* TYPE-1 = resume in caller of failing program, process next record.
*-----------------------------------------------------------------

01 TYPE-0 PIC S9(9) BINARY VALUE 0.
01 TYPE-1 PIC S9(9) BINARY VALUE 1.

PROCEDURE DIVISION USING CUR-COND, TOKEN, R-CODE, NEW-COND.
*-----------------------------------------------------------------
* If data exception, move resume cursor RELATIVE and resume
*-----------------------------------------------------------------

IF CEE347 OF CUR-COND THEN
CALL "CEEMRCR" USING TYPE-1 FC

SET RESUME TO TRUE
ELSE

SET PERCOLATE TO TRUE
END-IF
GOBACK

17 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – use TOKEN

***************************************************************

* Put name and address of user-written condition handler *

* into PROCEDURE-POINTER data item to pass to cond manager. *

***************************************************************

SET PGMPTR TO ENTRY 'USERHDLR'

***************************************************************

* Register the user-written condition handler with the *

* LE condition manager. Use DATA-PTR as TOKEN *

***************************************************************

CALL 'CEEHDLR' USING PGMPTR DATA-PTR FC.

LOOP.

PERFORM UNTIL EOF

READ INDATA AT END SET EOF TO TRUE
NOT AT END
SET DATA-PTR TO ADDRESS OF DATA-FIELDS-FROM-RECORD

*----------------------------------------------------------------
* Call subroutine to process data from the record
*----------------------------------------------------------------

CALL ‘CBLSUB' USING DATA-FIELDS-FROM-INPUT-RECORD
END-READ
*----------------------------------------------------------------
* Control will return here with move relative resume cursor
*----------------------------------------------------------------
END-PERFORM

18 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – USERHDLR using TOKEN

*-----------------------------------------------------------------

* Let’s write lower case COBOL!

*-----------------------------------------------------------------

Linkage Section.

01 Token Pointer.

Procedure Division Using Cur-Cond, Token, R-Code, New-Cond.
*-----------------------------------------------------------------
* For data exceptions, interrogate fields of record to find bad data
*-----------------------------------------------------------------

If CEE347 of Cur-Cond Then
Set Address of Local-Field-Descriptions to Token

If Customer-Name not alphabetic-upper Then
Display ‘Bad customer name‘

End-If
If Customer-Number not numeric Then

Display ‘Bad customer number‘
End-If

Set Resume to True © 2009 IBM Corporation
ELSE

Set Percolate to True
End-If
Goback

19 Exploit Condition Handling in LE

Enterprise COBOL for z/OS ibm

CH Scenario – unregister specific handler

SET PGMPTR TO ENTRY 'USERHDLR'
CALL 'CEEHDLR' USING PGMPTR DATA-PTR FC.

LOOP.

PERFORM UNTIL EOF

READ INDATA AT END SET EOF TO TRUE
NOT AT END
SET DATA-PTR TO ADDRESS OF DATA-FIELDS-FROM-RECORD

*----------------------------------------------------------------
* Call subroutine to process data from the record
*----------------------------------------------------------------

CALL ‘CBLSUB' USING DATA-FIELDS-FROM-INPUT-RECORD
END-READ
*----------------------------------------------------------------
* Control will return here with ‘normal’ move resume cursor
*----------------------------------------------------------------
END-PERFORM

*----------------------------------------------------------------
* Unregister handler for other processing in this program
* if we get data exceptions errors after this we want to ABEND
*----------------------------------------------------------------

CALL 'CEEHDLU' USING PGMPTR OMITTED

20 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling Example - Paragraphs

In this case, another style of COBOL coding is shown

– Maybe no loop or subroutine

This example also shows doing the condition
handling within the same COBOL program that is
getting exceptions

This example maps to what some users are already
doing with assembler

– You could use this style to convert from assembler ESPIE
handler to LE condition handler with minimum code changes

21 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – example with paragraphs – Case 3

*----------------------------------------------------------------
* Open the input file.
*----------------------------------------------------------------

OPEN-IT.
OPEN INPUT F1
IF FILE-STATUS NOT = 0 THEN
PERFORM UNEXPECTED-ERROR.

*----------------------------------------------------------------
* Read all of the records in the file and process them.
*----------------------------------------------------------------

PROCESS-RECORDS.
PERFORM PROCESS-DATA UNTIL EOF
CLOSE F1
STOP RUN.

*----------------------------------------------------------------
* Read record and process data – exception could occur here
*----------------------------------------------------------------

PROCESS-DATA.
PERFORM READ-RCD
IF NOT EOF THEN
ADD 1 TO R1-CTR.

*----------------------------------------------------------------
* Read a record from file F1.
*----------------------------------------------------------------

READ-RCD.
READ F1
IF FILE-STATUS > 10 THEN
PERFORM UNEXPECTED-ERROR.

22 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – explicit resume point – paragraphs

*----------------------------------------------------------------
* Open the input file.
*----------------------------------------------------------------

OPEN-IT.
OPEN INPUT F1
IF FILE-STATUS NOT = 0 THEN
PERFORM UNEXPECTED-ERROR.

*----------------------------------------------------------------
* Register a condition handler.
*----------------------------------------------------------------

SET PROCPTR TO ENTRY 'A1C3CHAX'
CALL 'CEEHDLR' USING PROCPTR, TOKEN, OMITTED
*----------------------------------------------------------------
* Set up the resume point where the condition handler
* can resume to (which is the next COBOL statement below).
*----------------------------------------------------------------
MOVE SPACES TO RECOVERY-IN-PROGRESS
CALL 'CEE3SRP' USING RECOVERY-POINT, OMITTED
*----------------------------------------------------------------
* We get here for one of two cases.
* 1) We just successfully called CEE3SRP, so keep going.
* 2) We just incurred a condition, go to error handle paragraph
*----------------------------------------------------------------
SERVICE LABEL
IF RECOVERY-IN-PROGRESS = 'Y' THEN

MOVE SPACES TO RECOVERY-IN-PROGRESS
GO TO PROGRAM-CHECK-OCCURED
END-IF

23 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

CH Scenario – explicit resume point – paragraphs

*----------------------------------------------------------------
* Read all of the records in the file and process them.
*----------------------------------------------------------------

PROCESS-RECORDS.
PERFORM PROCESS-DATA UNTIL EOF
CLOSE F1
STOP RUN.

*----------------------------------------------------------------
* Read record and process data – exception could occur here
*----------------------------------------------------------------

PROCESS-DATA.
PERFORM READ-RCD
IF NOT EOF THEN
ADD 1 TO R1-CTR.

*----------------------------------------------------------------
* Read a record from file F1.
*----------------------------------------------------------------

READ-RCD.
READ F1
IF FILE-STATUS > 10 THEN
PERFORM UNEXPECTED-ERROR.

*----------------------------------------------------------------
* Control comes to this paragraph if program check occurs
* while processing a record. Display bogus record and continue
*----------------------------------------------------------------

PROGRAM-CHECK-OCCURED.
DISPLAY 'DATA EXCEPTION ENCOUNTERED, RECORD = ' R1 '
GO TO PROCESS-DATA.

24 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Condition Handling – using ESPIE or ESTAE with LE

You can use your own ESPIE or ESTAE to get control
in your assembler routines under LE if you do it right


If an assembler program issues an ESPIE or ESTAE
when LE is running, and it remains in effect after
leaving the program, it can lead to ABENDs and
unexpected results.

– ☺ There is no problem if the ESPIE is reset or ESTAE is
cancelled before leaving the assembler program and before
calling LE services

25 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Default Condition Handler example

How does it work?
– LE registers the condition handler for you at initialization
How to specify?

//GO EXEC PGM=SSRANGE
// PARM.GO='/USRHDLR(HANDLEM1,HANDLEM2)‘

Example: Program SSRANGE runs and accesses an area beyond
the bounds of a table:

setup COMPUTE NEG = -2.
MOVE SPACE TO TABLE-1 (NEG)
error DISPLAY ‘Running after Sev 1 error!’
resume

26 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

Default Condition Handler © 2009 IBM Corporation

How does it work?
– One way to look at it when resume is chosen:

Enclave1 LE
COND
SSRANGE MGR

Error HANDLEM2
Resume Pt
Set Resume
GOBACK

27 Exploit Condition Handling in LE

Enterprise COBOL for z/OS ibm

Default Condition Handler © 2009 IBM Corporation

How does it work?
– One way to look at it when resume is NOT chosen:

Enclave1 LE
COND
SSRANGE MGR

Error HANDLEM2
Resume Pt
Set Not
Handled
GOBACK

28 Exploit Condition Handling in LE

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

Now some examples of using features of LE to
enhance your condition handler

– CEEMGET – get message text
– CEE3GRN – get routine name
– CEE3GRO – get routine offset
– CEEGQDT - retrieving ABEND code from Q_DATA

29 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

PROCEDURE DIVISION USING CURRENT-CONDITION TOKEN RESULT-CODE

NEW-CONDITION.

INIT.

*****************************************************************

* The GET-CONDITION-INFORMATION paragraph gets the error *

* message text for the message that corresponds to the *

* condition that the condition manager is currently handling. *

*****************************************************************

PERFORM GET-CONDITION-INFORMATION.

*********************************************************

SELECT-CONDITION.

*****************************************************************

* This is the main CASE statement for the routine. *

* Select action based on LE/370 message number for the *

* error that caused this condition handler to get control. *

**

30 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

GET-CONDITION-INFORMATION.
***************************************************************
* Retrieve the error message for the current condition. *
***************************************************************

CALL "CEEMGET" USING CURRENT-CONDITION, ERROR-MSG(1:80),
MSG-PTR, FC

IF SEVERITY = 1 THEN
MOVE Spaces to ERROR-MSG(MSG-PTR + 1:)
CALL "CEEMGET" USING CURRENT-CONDITION,
ERROR-MSG(MSG-PTR + 1:80),
MSG-PTR, FC

END-IF

IF SEVERITY > 0 THEN

DISPLAY "CALL to CEEMGET failed with Severity = " SEVERITY

DISPLAY " and message number = " MSGNO

GOBACK

END-IF

31 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

* GET-CONDITION-INFORMATION (continued)

***************************************************************

* Retrieve the name of the program that incurred the error *

***************************************************************

CALL "CEE3GRN" USING FAILING-PROG, FC.

IF SEVERITY > 0 THEN

DISPLAY "CEE3GRN failed Sev= " SEVERITY “ msg= " MSGNO

GOBACK

END-IF

***************************************************************

* Retrieve the offset of the error *

***************************************************************

CALL "CEE3GRO" USING FAILING-OFST, FC.

IF SEVERITY > 0 THEN

DISPLAY "CEE3GRO failed Sev= " SEVERITY " msg= " MSGNO

GOBACK

END-IF

DISPLAY "Offset of error is " FAILING-OFST.

32 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

PROCEDURE DIVISION USING CURRENT-CONDITION TOKEN RESULT-CODE
NEW-CONDITION.

SELECT-CONDITION.
EVALUATE TRUE

*****************************************************************

* Symbolic Feedback Code IGZ006 corresponds to msg IGZ0006 *

* Message 0006 = Reference to table addressed area outside*

* the region of the table *

* This condition is equivalent to VS COBOL II U1006 abend *

*****************************************************************

WHEN IGZ006 OF CURRENT-CONDITION

PERFORM HANDLE-1006

*****************************************************************

* Symbolic Feedback Code IGZ00F corresponds to msg IGZ0015 *

* Message 0015 = Recursive call to routine *

* This condition is equivalent to VS COBOL II U1015 abend *

*****************************************************************

WHEN IGZ00F OF CURRENT-CONDITION

PERFORM HANDLE-1015

33 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

How to get ABEND code with user-written condition handler

* LE raises condition CEE35I for a system or user ABEND. This *

* code uses CEEGQDT to get the Q_DATA and then the ABEND code. *

*****************************************************************

WHEN CEE35I OF CURRENT-CONDITION

*****************************************************************

* Get Q_DATA for the condition we are handling *

*****************************************************************

CALL "CEEGQDT" USING CURRENT-CONDITION Q-DATA-TOKEN FC

IF SEVERITY > 0 THEN

DISPLAY "CEEGQDT fail sev= "SEVERITY " msg= " MSGNO

GOBACK

END-IF

*****************************************************************

* Set up pointers to get the ABEND code *

*****************************************************************

SET ADDRESS OF Q-DATA-PTRS TO Q-DATA-TOKEN

SET ADDRESS OF ABEND-CODE TO Q-DATA-ABEND-CODE-PTR

*****************************************************************

* Select handler code based on ABEND code *

*****************************************************************

EVALUATE ABEND-CODE

WHEN 777

DISPLAY "Severe Error! Condition Handling "

"should not get control for IMS Abends"

SET PERCOLATE TO TRUE

WHEN OTHER

CONTINUE

34 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

LINKAGE SECTION.

01 ABEND-CODE PIC S9(9) USAGE BINARY.

***************************************************************

* This definition of the LE Feedback Code used for *

* LE services as opposed to user conditions *

***************************************************************

01 FC.

05 SEVERITY PIC 9(4) USAGE BINARY.

05 MSGNO PIC 9(4) USAGE BINARY.

05 FC-OTHER PIC X.

05 FAC-ID PIC X(3).

05 I-S-INFO PIC 9(9) USAGE BINARY.

***************************************************************

* Data items for retrieving Q_DATA. *

* Q_DATA token is a pointer to a list of pointers that *

* address the individual Q_DATA fields, which are *

* a parameter count, an abend code, and a reason code. *

***************************************************************

77 Q-DATA-TOKEN USAGE POINTER.

01 Q-DATA-PTRS USAGE POINTER.

05 Q-DATA-PARM-COUNT-PTR.

05 Q-DATA-ABEND-CODE-PTR.

05 Q-DATA-REASON-CODE-PTR.

35 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

RESUME-EXECUTION.

*****************************************************************

* When handling conditions with facility ID of IGZ, we must *

* move the RESUME CURSOR before resuming. *

* NOTE: Do not try resume for all IGZ conditions, just the ones *

* you want to handle. For example, you don’t want to resume *

* if you got a “Recursive call was attempted”. *

*****************************************************************

IF C-FAC-ID = ‘IGZ’ THEN

***************************************************************

* Resume execution at point after current statement *

***************************************************************

CALL "CEEMRCR" USING TYPE-1 FC.

IF SEVERITY > 0 THEN

DISPLAY "CALL to CEEMRCR failed with Severity = " SEVERITY

DISPLAY " and message number = " MSGNO

END-IF

***************************************************************

* Mark the condition as handled *

***************************************************************

SET RESUME TO TRUE

END-IF

36 Exploit Condition Handling in LE © 2009 IBM Corporation

Enterprise COBOL for z/OS ibm

COBOL user-written condition handler

***************************************************************

* Data items for MOVE RESUME CURSOR (CEEMRCR) *

***************************************************************

01 TYPE-0 PIC S9(9) USAGE BINARY VALUE ZERO.

01 TYPE-1 PIC S9(9) USAGE BINARY VALUE 1.

***************************************************************

* RESULT-CODE is passed back to the Language Environment *

* condition manager to indicate what it should do *

* with this condition: resume, percolate, or promote. *

***************************************************************

01 RESULT-CODE PIC S9(9) USAGE BINARY.

88 RESUME VALUE 10.

88 PERCOLATE VALUE 20.

88 PROMOTE VALUE 30.

88 PROMOTE-SF VALUE 31.

37 Exploit Condition Handling in LE © 2009 IBM Corporation


Click to View FlipBook Version