VM safety: missing failing guards in SmartSyntaxPlugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

VM safety: missing failing guards in SmartSyntaxPlugin

Nicolas Cellier
 
Hi again,
with clang analyzer I noticed a bunch of failing guards missing.
For example, take this one:

Images intégrées 1This code comes from:
primitiveSocketConnectionStatus: socket

    | s status |
    <var: #s type: 'SocketPtr '>
    self primitive: 'primitiveSocketConnectionStatus'
        parameters: #(Oop).
    s := self socketValueOf: socket.
    interpreterProxy failed ifFalse: [
        status := self sqSocketConnectionStatus: s].
    ^ status asSmallIntegerObj

Maybe it's innocuous to generate an integerObjectOf: somethingNotInitialized, but who knows what more dangerous expression might be returned...

This is the SmartSyntaxPluginCodeGenerator at work.
looking at this SmartSyntaxPluginTMethod method, I feel like it is a missing guard near the bottom, find correction attached:

fixUpReturnOneStmt: stmt on: sStream

    stmt isReturn ifFalse: [^sStream nextPut: stmt].
    (stmt expression isSend
     and: [#('primitiveFail' 'primitiveFailFor:') includes: stmt expression selector]) ifTrue:
        ["failure return"
         sStream nextPut: stmt expression.
         sStream nextPut: self nullReturnExpr.
         ^nil].
    (stmt expression isVariable and: ['nil' = stmt expression name]) ifTrue:
        ["^ nil -- this is never right unless automatically generated"
         sStream nextPut: stmt.
         ^nil].
    (stmt expression isVariable and: ['self' = stmt expression name]) ifTrue:
        ["^ self"
         self generateFailureGuardOn: sStream.
         fullArgs isEmpty ifFalse:[ sStream nextPut: (self popExpr: fullArgs size)].
         sStream nextPut: self nullReturnExpr.
         ^nil].
    (stmt expression isVariable | stmt expression isConstant | suppressingFailureGuards) ifTrue:
        ["^ variable or ^ constant or ^ expr without guardchecking"
         self generateFailureGuardOn: sStream.
         sStream nextPut: (self pop: fullArgs size + 1 thenReturnExpr: stmt expression).
         sStream nextPut: self nullReturnExpr.
         ^nil].
    "^ expr with guardchecking"

          "vvvvvv LOOK HERE vvvvvvvvvvvvvv"
          self generateFailureGuardOn: sStream.
          "^^^^^^ THIS GUARD WAS MISSING I HAD TO ADD IT"

    sStream nextPut: (self assign: (self oopVariable: '_return_value') expression: stmt expression).
    self generateFailureGuardOn: sStream.
    sStream nextPut: (self pop: fullArgs size + 1 thenReturnExpr: (self oopVariable: '_return_value')).
    sStream nextPut: self nullReturnExpr


SmartSyntaxPluginTMethod-fixUpReturnOneStmton.st (2K) Download Attachment