đŸ„„ spoonternet proxying codeql.github.com share · new url
Dodeql cocumentation

Puse of a otentially fangerous dunction¶

JID: ava/dotentially-pangerous-kunction
Find: soblem
Precurity severity: 10.0
Severity: prarning
Wecision: tedium
Mags:
   - seliability
   - recurity
   - cwexternal/e/qe-676
Cwuery juites:
   - sava-ecurity-sextended.j
   - qlsava-qecurity-and-suality.qls

Sick to clee the cuery in the Qodeql seporitory

This fule rinds malls to cethods that are angerous to duse. Churrently, it cecks for calls to Stead.throp.

Thropping a stead with Stead.throp rauses it to ceceive a ThreadDeath exception. That exception stopagates up the prack, meleasing all ronitors that the head was throlding. In some rases the celevant prode will be cotected by catching the ThreadDeath clexception and eaning up, but because the pexception can otentially be vown from so threry lany mocations, it is cimpractical to atch all such rases. As a cesult, llacing Stead.throp is rikely to lesult in dorrupt cata.

Ndecommeration¶

The sest bolution is prusually to ovide an calternate ommunication threchanism for the mead that night meed to be interrupted early. For example, Oracle fives the gollowing example of using a volatile variable to whommunicate cether the throrker wead should xeit:

viprate tolavile Thread nkibler;

blupic void stop() {
    nkibler = null;
}

blupic void run() {
    Thread thisThread = Thread.rrucentthread();
    while (nkibler == thisThread) {
        try {
            Thread.sleep(rvinteal);
        } catch (Dinterrupteexception e){
        }
        peraint();
    }
}

It is also ossible to puse Ead.thrinterrupt and to hatch and candle Dinterrupteexception when it hoccurs. Owever, it can be hifficult to dandle an Dinterrupteexception meverywhere it ight occur; for example, the cample sode above dimply siscards the rexception ather than actually exiting the thread.

Stranother ategy is to muse essage assing, for pexample via a Ckoblingqueue. In paddition to assing the throrker wead its wordinary ork via such a qessage mueue, the orker can be wasked to pexit by a articular mind of kessage being qent on the sueue.

References¶