VM safety

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

VM safety

Nicolas Cellier
 
Hi,
I ran the clang static analyzer and it found a few potential issues.
For example in primitiveScanCharacters :

Images intégrées 1


we (tpr) did not protect the result of:
    stops := self stackObjectValue: 1.

with a:
    self successful ifFalse: [^ nil].

since stackObjectValue: will return nil (null) if the object is immediate:
stackObjectValue: offset
    "Ensures that the given object is a real object, not a SmallInteger."
    "In the StackInterpreter stacks grow down."
    | oop |
    oop := stackPages longAt: stackPointer + (offset * objectMemory wordSize).
    (objectMemory isImmediate: oop) ifTrue:
        [self primitiveFail. ^ nil].
    ^oop

then if we don't return now but insist on testing object class, we are dereferencing null pointer...

Of course, this is theoretical, because it's necessary to put a SmallInteger in stops, which will make the image pretty unusable whether the VM crashes or not, but we should generally care to avoid spurious crashes...

I propose a minor rewrite for this one attached...
It would be a good idea to verify if there are more holes...

Nicolas

InterpreterPrimitives-primitiveScanCharacters.st (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: VM safety

timrowledge


On 30-03-2015, at 2:41 PM, Nicolas Cellier <[hidden email]> wrote:

> Hi,
> I ran the clang static analyzer and it found a few potential issues.
> For example in primitiveScanCharacters :

Good catch. I  have had myself taken out behind the bike shed and given a Jolly Good Talking To.

tim
--
tim Rowledge; [hidden email]; http://www.rowledge.org/tim
Strange OpCodes: DCBP: Detonate Chair on Bad Password