Changeset: a9f5af241221 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/a9f5af241221
Modified Files:
sql/backends/monet5/vaults/fits/fits.c
Branch: default
Log Message:
Fix some file name manipulation bugs.
diffs (75 lines):
diff --git a/sql/backends/monet5/vaults/fits/fits.c
b/sql/backends/monet5/vaults/fits/fits.c
--- a/sql/backends/monet5/vaults/fits/fits.c
+++ b/sql/backends/monet5/vaults/fits/fits.c
@@ -578,23 +578,22 @@ str FITSdir(Client cntxt, MalBlkPtr mb,
s = stmt;
while ((ep = readdir(dp)) != NULL && !msg) {
- char *filename = SQLescapeString(ep->d_name);
- if (!filename) {
- msg = createException(MAL, "fits.listdir",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
- break;
- }
-
- snprintf(fname, BUFSIZ, "%s%s", dir, filename);
+ snprintf(fname, sizeof(fname), "%s/%s", dir,
ep->d_name);
status = 0;
fits_open_file(&fptr, fname, READONLY, &status);
if (status == 0) {
- snprintf(stmt, BUFSIZ, ATTACHDIR, fname);
+ char *filename = SQLescapeString(fname);
+ if (!filename) {
+ msg = createException(MAL,
"fits.listdir", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ break;
+ }
+ snprintf(stmt, sizeof(stmt), ATTACHDIR,
filename);
+ GDKfree(filename);
TRC_DEBUG(FITS, "Executing: %s\n", s);
msg = SQLstatementIntern(cntxt, s,
"fits.listofdir", TRUE, FALSE, NULL);
fits_close_file(fptr, &status);
}
- GDKfree(filename);
}
(void)closedir(dp);
} else
@@ -608,7 +607,6 @@ str FITSdirpat(Client cntxt, MalBlkPtr m
str msg = MAL_SUCCEED;
str dir = *getArgReference_str(stk, pci, 1);
str pat = *getArgReference_str(stk, pci, 2);
- char *filename = NULL;
fitsfile *fptr;
char *s;
int status = 0;
@@ -619,7 +617,7 @@ str FITSdirpat(Client cntxt, MalBlkPtr m
(void)mb;
globbuf.gl_offs = 0;
- snprintf(fulldirectory, BUFSIZ, "%s%s", dir, pat);
+ snprintf(fulldirectory, sizeof(fulldirectory), "%s/%s", dir, pat);
glob(fulldirectory, GLOB_DOOFFS, NULL, &globbuf);
TRC_DEBUG(FITS, "Fulldir: %s - Size: %zu\n", fulldirectory,
globbuf.gl_pathc);
@@ -632,15 +630,15 @@ str FITSdirpat(Client cntxt, MalBlkPtr m
char fname[BUFSIZ];
s = stmt;
- snprintf(fname, BUFSIZ, "%s", globbuf.gl_pathv[j]);
- filename = SQLescapeString(fname);
- if (!filename) {
- throw(MAL, "fits.listdirpat", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
- }
+ strcpy_len(fname, globbuf.gl_pathv[j], sizeof(fname));
status = 0;
- fits_open_file(&fptr, filename, READONLY, &status);
+ fits_open_file(&fptr, fname, READONLY, &status);
if (status == 0) {
- snprintf(stmt, BUFSIZ, ATTACHDIR, filename);
+ char *filename = SQLescapeString(fname);
+ if (!filename) {
+ throw(MAL, "fits.listdirpat", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
+ snprintf(stmt, sizeof(stmt), ATTACHDIR, filename);
GDKfree(filename);
TRC_DEBUG(FITS, "Executing: %s\n", s);
msg = SQLstatementIntern(cntxt, s, "fits.listofdirpat",
TRUE, FALSE, NULL);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]