Author: chromatic
Date: Wed Nov 26 18:17:11 2008
New Revision: 33253
Modified:
trunk/src/pmc/namespace.pmc
Log:
[PMC] Added PMC_IS_NULL checks to set_pmc_keyed_str vtable entry of NameSpace
to avoid dereferencing a NULL PMC for its value. See CID #155 from Coverity
Scan.
Modified: trunk/src/pmc/namespace.pmc
==============================================================================
--- trunk/src/pmc/namespace.pmc (original)
+++ trunk/src/pmc/namespace.pmc Wed Nov 26 18:17:11 2008
@@ -61,8 +61,7 @@
/* Handle vtable methods with two underscores at the start. */
if (sub->vtable_index == -1) {
- if (string_str_index(interp, key,
- CONST_STRING(interp, "__"), 0) == 0) {
+ if (string_str_index(interp, key, CONST_STRING(interp, "__"), 0) == 0)
{
STRING * const meth_name = string_substr(interp, key, 2,
(INTVAL)(string_length(interp, key) - 2), NULL, 0);
sub->vtable_index =
@@ -232,8 +231,12 @@
*/
VTABLE void set_pmc_keyed_str(STRING *key, PMC *value) {
- const int val_is_NS = value->vtable->base_type ==
enum_class_NameSpace;
PMC *new_tuple = NULL;
+ const int val_is_NS = PMC_IS_NULL(value)
+ ? 0
+ :value->vtable->base_type ==
enum_class_NameSpace;
+
+ /* don't need this everywhere yet */
PMC * const old = (PMC *)parrot_hash_get(INTERP, NS_HASH(SELF),
key);
/* If it's a sub... */
@@ -243,18 +246,17 @@
return;
}
-
/* If it's an NCI method */
- if (value->vtable->base_type == enum_class_NCI) {
- Parrot_NameSpace_attributes * const nsinfo =
PARROT_NAMESPACE(SELF);
- PMC * const classobj = VTABLE_get_class(interp, SELF);
+ if (!PMC_IS_NULL(value) && VTABLE_isa(INTERP, value,
CONST_STRING(INTERP, "NCI"))) {
+ Parrot_NameSpace_attributes * const nsinfo =
PARROT_NAMESPACE(SELF);
+ PMC * const classobj = VTABLE_get_class(interp, SELF);
/* Insert it in class, if there is a class */
add_to_class(INTERP, nsinfo, classobj, key, value);
}
/* If it's a multi-sub... */
- if (value->vtable->base_type == enum_class_MultiSub) {
+ if (!PMC_IS_NULL(value) && VTABLE_isa(INTERP, value,
CONST_STRING(INTERP, "MultiSub"))) {
if (VTABLE_elements(interp, value) > 0) {
Parrot_NameSpace_attributes * const nsinfo =
PARROT_NAMESPACE(SELF);
@@ -321,7 +323,7 @@
}
VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
- PMC *ns = SELF;
+ PMC *ns = SELF;
if (key->vtable->base_type == enum_class_String) {
SELF.set_pmc_keyed_str(VTABLE_get_string(INTERP, key), value);