Changeset: dd9c25a04611 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dd9c25a04611
Modified Files:
        monetdb5/mal/mal.c
        monetdb5/mal/mal_atom.c
        monetdb5/mal/mal_authorize.c
        monetdb5/mal/mal_box.c
        monetdb5/mal/mal_builder.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_debugger.c
        monetdb5/mal/mal_factory.c
        monetdb5/mal/mal_function.c
        monetdb5/mal/mal_instruction.c
        monetdb5/mal/mal_instruction.h
        monetdb5/mal/mal_linker.c
        monetdb5/mal/mal_listing.c
        monetdb5/mal/mal_module.c
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_properties.c
        monetdb5/mal/mal_readline.c
        monetdb5/mal/mal_recycle.c
        monetdb5/mal/mal_runtime.c
        monetdb5/mal/mal_session.c
        monetdb5/mal/mal_stack.c
        monetdb5/modules/mal/cluster.c
        monetdb5/modules/mal/groupby.c
        monetdb5/modules/mal/joinpath.c
        monetdb5/modules/mal/mal_mapi.c
        monetdb5/modules/mal/remote.c
        monetdb5/modules/mal/tokenizer.c
        monetdb5/modules/mal/trader.c
        monetdb5/modules/mal/txtsim.c
Branch: default
Log Message:

Increase the defense lines
Although malloc failures for small objects are rare,
they may result in unforeseen crashes. This set extends
the defense lines, preferrably keeping the system running
in face of malloc errors.


diffs (truncated from 1370 to 300 lines):

diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -103,7 +103,7 @@
  * @image{base00,,,,.pdf}
  * @emph{Figure 2.1}
  * @end iftex
- * @-
+ * 
  * @node MAL Synopsis, Execution Engine, Architecture Overview,  Design  
Overview
  * @+ MonetDB Assembly Language (MAL)
  * The target language for a query compiler is
@@ -157,7 +157,6 @@
  * function modules.
  * @end itemize
  *
- * @-
  * @+ Critical sections and semaphores
  * MonetDB Version 5 is implemented as a collection of threads.
  * This calls for extreme
@@ -245,7 +244,8 @@ int mal_init(void){
 
        tstAligned();
        MCinit();
-       mdbInit();
+       if (mdbInit()) 
+               return -1;
        if (monet_memory == 0)
                monet_memory = MT_npages() * MT_pagesize();
        initNamespace();
diff --git a/monetdb5/mal/mal_atom.c b/monetdb5/mal/mal_atom.c
--- a/monetdb5/mal/mal_atom.c
+++ b/monetdb5/mal/mal_atom.c
@@ -19,7 +19,7 @@
 
 /*
  * @a M.L.Kersten
- * @- User Defined Types
+ *  User Defined Types
  * MonetDB supports an extensible type system to accomodate a wide
  * spectrum of database kernels and application needs.
  * The type administration keeps track of their properties and
@@ -46,7 +46,7 @@
  * A concrete example is the 'blob' datatype in the MonetDB atom module
  * library(see ../modules/atoms/blob.mx)
  *
- * @- Defining your own types
+ * Defining your own types
  * For the courageous at heart, you may enter the difficult world
  * of extending the kernel library. The easiest way is to derive
  * the atom modules from one shipped in the source distributed.
@@ -55,18 +55,18 @@
  * because you have to develop a handful routines complying with the
  * signatures required in the kernel library.
  * They are registered upon loading the @sc{atom} module.
- * @-
+ * 
  * The atom registration functions perform the necessary
  * type checks, but relies on the user to comply with this signature in
  * its C-implementation. The ruler calls are part of a module
  * initialization routine.
- * @-
+ * 
  * Functions passed to the GDK kernel are not directly accessible
  * as MAL routines, because their implementation requires a
  * GDK-specific signature. (See GDK documentation)
  * They are renamed to an non-parseable function, effectively shielding
  * them from the MAL programmer.
- * @-
+ * 
  * This feature is of particular interest to system experts.
  * It is not meant for end-users trying to intruduce record- or
  * struct-like objects in the database. They better decompose
@@ -224,7 +224,6 @@ int malAtomProperty(MalBlkPtr mb, InstrP
        return 0;
 }
 /*
- * @-
  * Atoms are constructed incrementally in the kernel using the
  * ATOMallocate function. It takes an existing type as a base
  * to derive a new one.
@@ -264,7 +263,6 @@ void malAtomDefinition(stream *out, str 
        }
 }
 /*
- * @-
  * User defined modules may introduce fixed sized types
  * to store information in BATs.
  */
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -18,10 +18,8 @@
  */
 
 /*
- * @f mal_authorize
  * @a M. Kersten, F. Groffen
- * @v 0.3
- * @+ Authorisation adminstration management
+ * Authorisation adminstration management
  * Authorisation of users is a key concept in protecting the server from
  * malicious and unauthorised users.  This file contains a number of
  * functions that administrate a set of BATs backing the authorisation
@@ -31,9 +29,6 @@
  * usernames, passwords and allowed scenarios for users of the server.
  *
  */
-/*
- * @-
- */
 #include "monetdb_config.h"
 #include "mal_authorize.h"
 #include "mal_private.h"
@@ -114,7 +109,6 @@ AUTHcommit(void)
 }
 
 /*
- * @-
  * Localize the authorization tables in the database.  The authorization
  * tables are a set of aligned BATs that store username, password (hashed)
  * and scenario permissions.
@@ -655,6 +649,8 @@ AUTHdecypherValue(str *ret, str *value) 
         * (a space would only uppercase the password) */
        int keylen = 0;
 
+       if( r == NULL)
+               throw(MAL, "decypherValue", MAL_MALLOC_FAIL);
        if (vaultKey == NULL)
                throw(MAL, "decypherValue", "The vault is still locked!");
 
@@ -694,6 +690,8 @@ AUTHcypherValue(str *ret, str *value) {
         * (a space would only uppercase the password) */
        int keylen = 0;
 
+       if( r == NULL)
+               throw(MAL, "cypherValue", MAL_MALLOC_FAIL);
        if (vaultKey == NULL)
                throw(MAL, "cypherValue", "The vault is still locked!");
 
diff --git a/monetdb5/mal/mal_box.c b/monetdb5/mal/mal_box.c
--- a/monetdb5/mal/mal_box.c
+++ b/monetdb5/mal/mal_box.c
@@ -248,11 +248,17 @@ newBox(str name)
        for (i = 0; i < topbox; i++)
                if (malbox[i] == NULL) {
                        obj= (Box) GDKzalloc(sizeof(BoxRecord));
+                       if( obj == NULL){
+                               showException(GDKout, MAL,"box.new", 
MAL_MALLOC_FAIL);
+                               return NULL;
+                       }
                        obj->name= GDKstrdup(name);
                        obj->sym=  newMalBlk(MAXVARS,STMT_INCREMENT);
                        obj->val = newGlobalStack(MAXVARS);
-                       if ( obj->val == NULL)
+                       if ( obj->val == NULL || obj->sym == NULL){
                                showException(GDKout, MAL,"box.new", 
MAL_MALLOC_FAIL);
+                               return NULL;
+                       }
                        MT_lock_init(&obj->lock,"M5_box_lock");
                        malbox[i] = obj;
                        break;
@@ -261,11 +267,17 @@ newBox(str name)
        if (i == topbox) {
                if ( topbox < MAXSPACES){
                        obj= (Box) GDKzalloc(sizeof(BoxRecord));
+                       if( obj == NULL){
+                               showException(GDKout, MAL,"box.new", 
MAL_MALLOC_FAIL);
+                               return NULL;
+                       }
                        obj->name= GDKstrdup(name);
                        obj->sym=  newMalBlk(MAXVARS,STMT_INCREMENT);
                        obj->val = newGlobalStack(MAXVARS);
-                       if ( obj->val == NULL)
+                       if ( obj->val == NULL || obj->sym == NULL){
                                showException(GDKout, MAL,"box.new", 
MAL_MALLOC_FAIL);
+                               return NULL;
+                       }
                        MT_lock_init(&obj->lock,"M5_box_lock");
                        malbox[topbox++] = obj;
                } else
diff --git a/monetdb5/mal/mal_builder.c b/monetdb5/mal/mal_builder.c
--- a/monetdb5/mal/mal_builder.c
+++ b/monetdb5/mal/mal_builder.c
@@ -18,11 +18,9 @@
  */
 
 /*
- * @f mal_builder
- * @a M. Kersten
- * @v 1.0
+ * author M. Kersten
  *
- * @* The MAL builder
+ * MAL builder
  * The MAL builder library containst the primitives to simplify construction
  * of programs by compilers. It has grown out of the MonetDB/SQL code 
generator.
  * The strings being passed as arguments are copied in the process.
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -90,6 +90,10 @@ MCinit(void)
                /* console */ 1 +
                /* client connections */ maxclients;
        mal_clients = GDKzalloc(sizeof(ClientRec) * MAL_MAXCLIENTS);
+       if( mal_clients == NULL){
+               showException(GDKout, MAL, "MCinit",MAL_MALLOC_FAIL);
+               mal_exit();
+       }
 }
 
 int
@@ -274,8 +278,7 @@ MCinitClientThread(Client c)
        cname[11] = '\0';
        t = THRnew(cname);
        if (t == 0) {
-               showException(c->fdout, MAL, "initClientThread",
-                               "Failed to initialize client");
+               showException(c->fdout, MAL, "initClientThread", "Failed to 
initialize client");
                MPresetProfiler(c->fdout);
                return -1;
        }
@@ -288,7 +291,12 @@ MCinitClientThread(Client c)
        c->mythread = t;
        c->errbuf = GDKerrbuf;
        if (c->errbuf == NULL) {
-               GDKsetbuf(GDKzalloc(GDKMAXERRLEN));
+               char *n = GDKzalloc(GDKMAXERRLEN);
+               if ( n == NULL){
+                       showException(GDKout, MAL, "initClientThread", "Failed 
to initialize client");
+                       return -1;
+               }
+               GDKsetbuf(n);
                c->errbuf = GDKerrbuf;
        } else
                c->errbuf[0] = 0;
diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c
--- a/monetdb5/mal/mal_debugger.c
+++ b/monetdb5/mal/mal_debugger.c
@@ -54,7 +54,7 @@ static mdbStateRecord *mdbTable;
  * The debugger flags overview
  */
 
-void
+int
 mdbInit(void)
 {
        /*
@@ -64,6 +64,11 @@ mdbInit(void)
         * space in each instruction.
         */
        mdbTable = GDKzalloc(sizeof(mdbStateRecord) * MAL_MAXCLIENTS);
+       if (mdbTable == NULL) {
+               showException(GDKout,MAL, "mdbInit",MAL_MALLOC_FAIL);
+               return -1;
+       }
+       return 0;
 }
 
 static char
@@ -472,8 +477,10 @@ retryRead:
                case 's':   /* step */
                        if (strncmp("span", b, 4) == 0) {
                                Lifespan span = setLifespan(mb);
-                               debugLifespan(cntxt, mb, span);
-                               GDKfree(span);
+                               if ( span){
+                                       debugLifespan(cntxt, mb, span);
+                                       GDKfree(span);
+                               }
                                continue;
                        } else if (strncmp("scenarios", b, 9) == 0) {
                                showAllScenarios(out);
diff --git a/monetdb5/mal/mal_factory.c b/monetdb5/mal/mal_factory.c
--- a/monetdb5/mal/mal_factory.c
+++ b/monetdb5/mal/mal_factory.c
@@ -19,7 +19,6 @@
 
 /*
  * @a M. Kersten
- * @v 0.0
  * @+ Factories
  * A convenient programming construct is the co-routine, which
  * is specified as an ordinary function, but maintains its
@@ -80,7 +79,7 @@
  * end random;
  * @end example
  *
- * @- Factory Ownership
+ * Factory Ownership
  * For simple cases, e.g. implementation of a random function,
  * it suffices to ensure that the state is secured between calls.
  * But, in a database context there are multiple clients
@@ -139,7 +138,7 @@
  * end random;
  * @end example
  *
- * @- Complex Factories
+ * Complex Factories
  * The factory scheme can be used to model
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to