Changeset: a8dcc5bc8a38 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a8dcc5bc8a38 Modified Files: monetdb5/mal/mal_atom.c monetdb5/mal/mal_builder.c monetdb5/mal/mal_debugger.c monetdb5/mal/mal_import.c monetdb5/modules/atoms/xml.c tools/merovingian/daemon/argvcmds.c tools/merovingian/daemon/client.c tools/merovingian/daemon/controlrunner.c tools/merovingian/daemon/proxy.c tools/merovingian/utils/control.c tools/merovingian/utils/database.c tools/merovingian/utils/properties.c tools/merovingian/utils/properties.h Branch: default Log Message:
Merge with Jan2014 branch. diffs (truncated from 309 to 300 lines): 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 @@ -55,7 +55,7 @@ int malAtomProperty(MalBlkPtr mb, InstrP assert(pci != 0); name = getFunctionId(pci); tpe = getTypeIndex(getModuleId(pci), (int)strlen(getModuleId(pci)), TYPE_any); - if (tpe < 0 || tpe >= GDKatomcnt) + if (tpe < 0 || tpe >= GDKatomcnt || tpe >= MAXATOMS) return 0; assert(pci->fcn != NULL); switch (name[0]) { 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 @@ -437,7 +437,7 @@ pushNilType(MalBlkPtr mb, InstrPtr q, ch if (q == NULL) return NULL; idx= getTypeIndex(tpe, -1, TYPE_any); - if( idx < 0) + if( idx < 0 || idx >= GDKatomcnt || idx >= MAXATOMS) return NULL; cst.vtype=TYPE_void; cst.val.oval= oid_nil; 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 @@ -1203,8 +1203,7 @@ str runMALDebugger(Client cntxt, Symbol s) { cntxt->itrace = 'n'; - runMAL(cntxt, s->def, 0, 0); - return MAL_SUCCEED; + return runMAL(cntxt, s->def, 0, 0); } /* Utilities diff --git a/monetdb5/mal/mal_import.c b/monetdb5/mal/mal_import.c --- a/monetdb5/mal/mal_import.c +++ b/monetdb5/mal/mal_import.c @@ -391,8 +391,10 @@ callString(Client c, str s, int listing) if (old != s) GDKfree(s); b = (buffer *) GDKmalloc(sizeof(buffer)); - if (b == NULL) + if (b == NULL){ + GDKfree(qry); return -1; + } buffer_init(b, qry, len); if (MCpushClientInput(c, bstream_create(buffer_rastream(b, "callString"), b->len), listing, "") < 0) { GDKfree(b); diff --git a/monetdb5/modules/atoms/xml.c b/monetdb5/modules/atoms/xml.c --- a/monetdb5/modules/atoms/xml.c +++ b/monetdb5/modules/atoms/xml.c @@ -578,7 +578,7 @@ XMLconcat(xml *ret, xml *left, xml *righ throw(MAL, "xml.concat", MAL_MALLOC_FAIL); snprintf(buf, len, "A%s %s", *left + 1, *right + 1); } else if (**left == 'C') { - len = strlen(*left) + strlen(*right); + len = strlen(*left) + strlen(*right) +2; buf = GDKmalloc(len); if (buf == NULL) throw(MAL, "xml.concat", MAL_MALLOC_FAIL); diff --git a/tools/merovingian/daemon/argvcmds.c b/tools/merovingian/daemon/argvcmds.c --- a/tools/merovingian/daemon/argvcmds.c +++ b/tools/merovingian/daemon/argvcmds.c @@ -89,7 +89,6 @@ command_create(int argc, char *argv[]) char path[2048]; char *p; char *dbfarm; - struct stat sb; confkeyval phrase[2]; if (argc != 2) { @@ -100,26 +99,23 @@ command_create(int argc, char *argv[]) dbfarm = argv[1]; /* check if dbfarm actually exists */ - if (stat(dbfarm, &sb) == -1) { - strncpy(path, dbfarm, sizeof(path) - 1); - path[sizeof(path) - 1] = '\0'; - p = path; - /* try to create the dbfarm */ - while ((p = strchr(p + 1, '/')) != NULL) { - *p = '\0'; - /* coverity[toctou] */ - if (stat(path, &sb) == -1 && mkdir(path, 0755)) { - fprintf(stderr, "unable to create directory '%s': %s\n", - path, strerror(errno)); - return(1); - } - *p = '/'; - } - if (mkdir(path, 0755)) { - fprintf(stderr, "unable to create directory '%s': %s\n", - path, strerror(errno)); + strncpy(path, dbfarm, sizeof(path) - 1); + path[sizeof(path) - 1] = '\0'; + p = path; + while ((p = strchr(p + 1, '/')) != NULL) { + *p = '\0'; + if (mkdir(path, 0755) == -1 && errno != EEXIST) { + fprintf(stderr, + "unable to create directory '%s': %s\n", + path, strerror(errno)); return(1); } + *p = '/'; + } + if (mkdir(dbfarm, 0755) == -1 && errno != EEXIST) { + fprintf(stderr, "unable to create directory '%s': %s\n", + dbfarm, strerror(errno)); + return(1); } phrase[0].key = NULL; diff --git a/tools/merovingian/daemon/client.c b/tools/merovingian/daemon/client.c --- a/tools/merovingian/daemon/client.c +++ b/tools/merovingian/daemon/client.c @@ -226,7 +226,7 @@ handleClient(int sock, char isusock) } } - if (*database == '\0') { + if (database == NULL || *database == '\0') { /* we need to have a database, if we haven't gotten one, * complain */ mnstr_printf(fout, "!monetdbd: please specify a database\n"); diff --git a/tools/merovingian/daemon/controlrunner.c b/tools/merovingian/daemon/controlrunner.c --- a/tools/merovingian/daemon/controlrunner.c +++ b/tools/merovingian/daemon/controlrunner.c @@ -641,6 +641,7 @@ static void ctl_handle_client( } val = strchr(p, '='); + assert(val != NULL); /* see above */ *val++ = '\0'; if (*val == '\0') val = NULL; diff --git a/tools/merovingian/daemon/proxy.c b/tools/merovingian/daemon/proxy.c --- a/tools/merovingian/daemon/proxy.c +++ b/tools/merovingian/daemon/proxy.c @@ -185,7 +185,10 @@ startProxy(int psock, stream *cfdin, str } /* block until the server acknowledges that it has psock * connected with itself */ - recv(ssock, buf, 1, 0); + if (recv(ssock, buf, 1, 0) < 0) { + close(ssock); + return(newErr("could not receive initial byte: %s", strerror(errno))); + } close(ssock); close(psock); close_stream(cfdin); diff --git a/tools/merovingian/utils/control.c b/tools/merovingian/utils/control.c --- a/tools/merovingian/utils/control.c +++ b/tools/merovingian/utils/control.c @@ -63,6 +63,7 @@ char* control_send( stream *fdin = NULL; stream *fdout = NULL; + *ret = NULL; /* gets overwritten in case of success */ if (port == -1) { struct sockaddr_un server; /* UNIX socket connect */ @@ -111,13 +112,14 @@ char* control_send( /* try reading length */ len = recv(sock, rbuf, 2, 0); if (len == 2) - len += recv(sock, rbuf + len, sizeof(rbuf) - len, 0); + len += recv(sock, rbuf + len, sizeof(rbuf) - len - 1, 0); /* perform login ritual */ if (len <= 2) { snprintf(sbuf, sizeof(sbuf), "no response from monetdbd"); close(sock); return(strdup(sbuf)); } + rbuf[len] = 0; /* we only understand merovingian:1 and :2 (backwards compat * <=Aug2011) and mapi v9 on merovingian */ if (strncmp(rbuf, "merovingian:1:", strlen("merovingian:1:")) == 0) { @@ -296,12 +298,12 @@ char* control_send( if (fdin != NULL) { /* stream.h is sooo broken :( */ memset(rbuf, '\0', sizeof(rbuf)); - if (mnstr_read_block(fdin, rbuf, sizeof(rbuf) - 1, 1) < 0) { + if ((len = mnstr_read_block(fdin, rbuf, sizeof(rbuf) - 1, 1)) < 0) { close_stream(fdout); close_stream(fdin); return(strdup("no response from monetdbd after login")); } - rbuf[strlen(rbuf) - 1] = '\0'; + rbuf[len - 1] = '\0'; } else { if ((len = recv(sock, rbuf, sizeof(rbuf), 0)) <= 0) { close(sock); diff --git a/tools/merovingian/utils/database.c b/tools/merovingian/utils/database.c --- a/tools/merovingian/utils/database.c +++ b/tools/merovingian/utils/database.c @@ -161,10 +161,9 @@ char* db_create(char* dbname) { } /* recursive helper function to delete a directory */ -static char* deletedir(char *dir) { +static char* deletedir(const char *dir) { DIR *d; struct dirent *e; - struct stat s; char buf[8192]; char path[4096]; @@ -174,45 +173,33 @@ static char* deletedir(char *dir) { * probably already deleted */ if (errno == ENOENT) return(NULL); + if (errno == ENOTDIR) { + if (unlink(dir) == -1 && errno != ENOENT) { + snprintf(buf, sizeof(buf), + "unable to unlink file %s: %s", + dir, strerror(errno)); + return(strdup(buf)); + } + return NULL; + } snprintf(buf, sizeof(buf), "unable to open dir %s: %s", dir, strerror(errno)); return(strdup(buf)); } while ((e = readdir(d)) != NULL) { - snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); - if (stat(path, &s) == -1) { - snprintf(buf, sizeof(buf), "unable to stat file %s: %s", - path, strerror(errno)); - closedir(d); - return(strdup(buf)); - } - - if (S_ISREG(s.st_mode) || S_ISLNK(s.st_mode) || S_ISSOCK(s.st_mode)) { - if (unlink(path) == -1) { - snprintf(buf, sizeof(buf), "unable to unlink file %s: %s", - path, strerror(errno)); - closedir(d); - return(strdup(buf)); - } - } else if (S_ISDIR(s.st_mode)) { + /* ignore . and .. */ + if (strcmp(e->d_name, ".") != 0 && + strcmp(e->d_name, "..") != 0) { char* er; - /* recurse, ignore . and .. */ - if (strcmp(e->d_name, ".") != 0 && - strcmp(e->d_name, "..") != 0 && - (er = deletedir(path)) != NULL) - { + snprintf(path, sizeof(path), "%s/%s", dir, e->d_name); + if ((er = deletedir(path)) != NULL) { closedir(d); return(er); } - } else { - /* fifos, block, char devices etc, we don't do */ - snprintf(buf, sizeof(buf), "not a regular file: %s", path); - closedir(d); - return(strdup(buf)); } } closedir(d); - if (rmdir(dir) == -1) { + if (rmdir(dir) == -1 && errno != ENOENT) { snprintf(buf, sizeof(buf), "unable to remove directory %s: %s", dir, strerror(errno)); return(strdup(buf)); diff --git a/tools/merovingian/utils/properties.c b/tools/merovingian/utils/properties.c --- a/tools/merovingian/utils/properties.c +++ b/tools/merovingian/utils/properties.c @@ -65,7 +65,7 @@ getDefaultProps(void) * Returns 0 when the properties could be written to the file. */ inline int -writeProps(confkeyval *ckv, char *path) +writeProps(confkeyval *ckv, const char *path) { char file[1024]; FILE *cnf; @@ -122,7 +122,7 @@ writePropsBuf(confkeyval *ckv, char **bu * when reading the property file succeeded. */ inline int -readProps(confkeyval *ckv, char *path) +readProps(confkeyval *ckv, const char *path) { char file[1024]; FILE *cnf; diff --git a/tools/merovingian/utils/properties.h b/tools/merovingian/utils/properties.h --- a/tools/merovingian/utils/properties.h +++ b/tools/merovingian/utils/properties.h @@ -25,9 +25,9 @@ #define MEROPROPFILE ".merovingian_properties" _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list