Changeset: fa8cf2214d6e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fa8cf2214d6e
Modified Files:
clients/mapiclient/dotmonetdb.c
gdk/gdk_bbp.c
monetdb5/extras/rapi/rapi.c
monetdb5/mal/mal_linker.c
tools/mserver/mserver5.c
tools/mserver/shutdowntest.c
Branch: Aug2018
Log Message:
merged
diffs (169 lines):
diff --git a/clients/mapiclient/dotmonetdb.c b/clients/mapiclient/dotmonetdb.c
--- a/clients/mapiclient/dotmonetdb.c
+++ b/clients/mapiclient/dotmonetdb.c
@@ -15,18 +15,22 @@ parse_dotmonetdb(char **user, char **pas
{
char *cfile;
FILE *config = NULL;
- char buf[1024];
+ char buf[FILENAME_MAX];
if ((cfile = getenv("DOTMONETDBFILE")) == NULL) {
/* no environment variable: use a default */
if ((config = fopen(".monetdb", "r")) == NULL) {
if ((cfile = getenv("HOME")) != NULL) {
- snprintf(buf, sizeof(buf), "%s%c.monetdb",
cfile, DIR_SEP);
- config = fopen(buf, "r");
- if (config)
- cfile = strdup(buf);
- else
+ int len = snprintf(buf, sizeof(buf),
"%s%c.monetdb", cfile, DIR_SEP);
+ if (len == -1 || len >= FILENAME_MAX) {
cfile = NULL;
+ } else {
+ config = fopen(buf, "r");
+ if (config)
+ cfile = strdup(buf);
+ else
+ cfile = NULL;
+ }
}
} else {
cfile = strdup(".monetdb");
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1997,7 +1997,7 @@ BBPinsert(BAT *bn)
bool lock = locked_by == 0 || locked_by != pid;
char dirname[24];
bat i;
- int idx = threadmask(pid);
+ int idx = threadmask(pid), len = 0;
/* critical section: get a new BBP entry */
if (lock) {
@@ -2063,7 +2063,9 @@ BBPinsert(BAT *bn)
#endif
if (*BBP_bak(i) == 0)
- snprintf(BBP_bak(i), sizeof(BBP_bak(i)), "tmp_%o", (unsigned)
i);
+ len = snprintf(BBP_bak(i), sizeof(BBP_bak(i)), "tmp_%o",
(unsigned) i);
+ if (len == -1 || len >= FILENAME_MAX)
+ return 0;
BBP_logical(i) = BBP_bak(i);
/* Keep the physical location around forever */
@@ -2071,11 +2073,13 @@ BBPinsert(BAT *bn)
BBPgetsubdir(dirname, i);
if (*dirname) /* i.e., i >= 0100 */
- snprintf(BBP_physical(i), sizeof(BBP_physical(i)),
+ len = snprintf(BBP_physical(i), sizeof(BBP_physical(i)),
"%s%c%o", dirname, DIR_SEP, (unsigned) i);
else
- snprintf(BBP_physical(i), sizeof(BBP_physical(i)),
+ len = snprintf(BBP_physical(i), sizeof(BBP_physical(i)),
"%o", (unsigned) i);
+ if (len == -1 || len >= FILENAME_MAX)
+ return 0;
BATDEBUG fprintf(stderr, "#%d = new %s(%s)\n", (int) i,
BBPname(i), ATOMname(bn->ttype));
}
diff --git a/monetdb5/extras/rapi/rapi.c b/monetdb5/extras/rapi/rapi.c
--- a/monetdb5/extras/rapi/rapi.c
+++ b/monetdb5/extras/rapi/rapi.c
@@ -173,13 +173,15 @@ static char *RAPIinitialize(void) {
static char *RAPIinstalladdons(void) {
int evalErr;
ParseStatus status;
- char rlibs[BUFSIZ];
+ char rlibs[FILENAME_MAX];
char rapiinclude[BUFSIZ];
SEXP librisexp;
+ int len;
// r library folder, create if not exists
- snprintf(rlibs, sizeof(rlibs), "%s%c%s", GDKgetenv("gdk_dbpath"),
DIR_SEP,
- "rapi_packages");
+ len = snprintf(rlibs, sizeof(rlibs), "%s%c%s", GDKgetenv("gdk_dbpath"),
DIR_SEP, "rapi_packages");
+ if (len == -1 || len >= FILENAME_MAX)
+ return "cannot create rapi_packages directory because the path
is too large";
if (mkdir(rlibs, S_IRWXU) != 0 && errno != EEXIST) {
return "cannot create rapi_packages directory";
diff --git a/monetdb5/mal/mal_linker.c b/monetdb5/mal/mal_linker.c
--- a/monetdb5/mal/mal_linker.c
+++ b/monetdb5/mal/mal_linker.c
@@ -363,6 +363,7 @@ locate_file(const char *basename, const
if (strcmp(e->d_name, "..") == 0 ||
strcmp(e->d_name, ".") == 0)
continue;
if (strcmp(e->d_name + strlen(e->d_name) -
strlen(ext), ext) == 0) {
+ int len;
strs[lasts] =
GDKmalloc(strlen(fullname) + sizeof(DIR_SEP)
+ strlen(e->d_name) +
sizeof(PATH_SEP) + 1);
if (strs[lasts] == NULL) {
@@ -372,7 +373,14 @@ locate_file(const char *basename, const
(void)closedir(rdir);
return NULL;
}
- sprintf(strs[lasts], "%s%c%s%c",
fullname, DIR_SEP, e->d_name, PATH_SEP);
+ len = sprintf(strs[lasts], "%s%c%s%c",
fullname, DIR_SEP, e->d_name, PATH_SEP);
+ if (len == -1 || len >= FILENAME_MAX) {
+ while (lasts >= 0)
+ GDKfree(strs[lasts--]);
+ GDKfree(fullname);
+ (void)closedir(rdir);
+ return NULL;
+ }
lasts++;
}
if (lasts >= MAXMULTISCRIPT)
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -236,7 +236,7 @@ main(int argc, char **av)
int i, grpdebug = 0, debug = 0, setlen = 0, listing = 0;
str dbinit = NULL;
str err = MAL_SUCCEED;
- char prmodpath[1024];
+ char prmodpath[FILENAME_MAX];
char *modpath = NULL;
char *binpath = NULL;
str *monet_script;
@@ -521,8 +521,10 @@ main(int argc, char **av)
if (p != NULL) {
*p = '\0';
for (i = 0; libdirs[i] != NULL; i++) {
- snprintf(prmodpath, sizeof(prmodpath),
"%s%c%s%cmonetdb5",
- binpath, DIR_SEP,
libdirs[i], DIR_SEP);
+ int len = snprintf(prmodpath,
sizeof(prmodpath), "%s%c%s%cmonetdb5",
+
binpath, DIR_SEP, libdirs[i], DIR_SEP);
+ if (len == -1 || len >= FILENAME_MAX)
+ continue;
if (stat(prmodpath, &sb) == 0) {
modpath = prmodpath;
break;
diff --git a/tools/mserver/shutdowntest.c b/tools/mserver/shutdowntest.c
--- a/tools/mserver/shutdowntest.c
+++ b/tools/mserver/shutdowntest.c
@@ -100,7 +100,7 @@ static str monetdb_initialize(void) {
volatile int setlen = 0; /* use volatile for setjmp */
str retval = MAL_SUCCEED;
char *err;
- char prmodpath[1024];
+ char prmodpath[FILENAME_MAX];
char *modpath = NULL;
char *binpath = NULL;
@@ -156,8 +156,10 @@ static str monetdb_initialize(void) {
if (p != NULL) {
*p = '\0';
for (i = 0; libdirs[i] != NULL; i++) {
- snprintf(prmodpath, sizeof(prmodpath),
"%s%c%s%cmonetdb5",
+ int len = snprintf(prmodpath,
sizeof(prmodpath), "%s%c%s%cmonetdb5",
binpath, DIR_SEP,
libdirs[i], DIR_SEP);
+ if (len == -1 || len >= FILENAME_MAX)
+ continue;
if (stat(prmodpath, &sb) == 0) {
modpath = prmodpath;
break;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list