Changeset: 31c03f56112d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/31c03f56112d
Modified Files:
monetdb5/mal/mal_authorize.c
monetdb5/modules/mal/pcre.c
monetdb5/modules/mal/remote.c
monetdb5/modules/mal/tokenizer.c
sql/backends/monet5/sql.c
Branch: default
Log Message:
Hold the iterator a little longer on these cases
diffs (truncated from 302 to 300 lines):
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
@@ -456,10 +456,12 @@ AUTHcheckCredentials(
/* find the corresponding password to the user */
passi = bat_iterator(pass);
tmp = (str)BUNtvar(passi, p);
- bat_iterator_end(&passi);
assert (tmp != NULL);
/* decypher the password (we lose the original tmp here) */
- rethrow("checkCredentials", tmp, AUTHdecypherValue(&pwd, tmp));
+ tmp = AUTHdecypherValue(&pwd, tmp);
+ bat_iterator_end(&passi);
+ if (tmp)
+ return tmp;
/* generate the hash as the client should have done */
hash = mcrypt_hashPassword(algo, pwd, challenge);
@@ -651,10 +653,10 @@ AUTHchangePassword(Client cntxt, const c
assert(p != BUN_NONE);
passi = bat_iterator(pass);
tmp = BUNtvar(passi, p);
- bat_iterator_end(&passi);
assert (tmp != NULL);
/* decypher the password */
msg = AUTHdecypherValue(&hash, tmp);
+ bat_iterator_end(&passi);
if (msg)
return msg;
if (strcmp(hash, oldpass) != 0){
@@ -710,19 +712,25 @@ AUTHsetPassword(Client cntxt, const char
assert (p != BUN_NONE);
useri = bat_iterator(user);
tmp = BUNtvar(useri, p);
- bat_iterator_end(&useri);
assert (tmp != NULL);
- if (strcmp(tmp, username) == 0)
+ if (strcmp(tmp, username) == 0) {
+ bat_iterator_end(&useri);
throw(INVCRED, "setPassword", "The administrator cannot set its
own password, use changePassword instead");
+ }
/* see if the user is valid */
p = AUTHfindUser(username);
- if (p == BUN_NONE)
+ if (p == BUN_NONE) {
+ bat_iterator_end(&useri);
throw(MAL, "setPassword", "no such user '%s'", username);
+ }
id = p;
/* cypher the password */
- rethrow("setPassword", tmp, AUTHcypherValue(&hash, passwd));
+ tmp = AUTHcypherValue(&hash, passwd);
+ bat_iterator_end(&useri);
+ if (tmp)
+ return tmp;
/* ok, just overwrite the password field for this user */
assert (p != BUN_NONE);
assert(id == p);
@@ -841,10 +849,12 @@ AUTHgetPasswordHash(str *ret, Client cnt
throw(MAL, "getPasswordHash", "user '%s' does not exist",
username);
i = bat_iterator(pass);
tmp = BUNtvar(i, p);
- bat_iterator_end(&i);
assert (tmp != NULL);
/* decypher the password */
- rethrow("changePassword", tmp, AUTHdecypherValue(&passwd, tmp));
+ tmp = AUTHdecypherValue(&passwd, tmp);
+ bat_iterator_end(&i);
+ if (tmp)
+ return tmp;
*ret = passwd;
return(NULL);
@@ -1039,12 +1049,14 @@ AUTHgetRemoteTableCredentials(const char
{
BUN p;
BATiter i;
- str tmp;
- str pwhash;
+ str tmp, pwhash;
- if (strNil(local_table)) {
+ *uri = NULL;
+ *username = NULL;
+ *password = NULL;
+
+ if (strNil(local_table))
throw(ILLARG, "getRemoteTableCredentials", "local table should
not be nil");
- }
p = lookupRemoteTableKey(local_table);
if (p == BUN_NONE) {
@@ -1059,17 +1071,32 @@ AUTHgetRemoteTableCredentials(const char
assert(p != BUN_NONE);
i = bat_iterator(rt_uri);
- *uri = BUNtvar(i, p);
+ *uri = GDKstrdup(BUNtvar(i, p));
bat_iterator_end(&i);
i = bat_iterator(rt_remoteuser);
- *username = BUNtvar(i, p);
+ *username = GDKstrdup(BUNtvar(i, p));
bat_iterator_end(&i);
+ if (!*uri || !*username) {
+ GDKfree(*uri);
+ GDKfree(*username);
+ *uri = NULL;
+ *username = NULL;
+ throw(MAL, "getRemoteTableCredentials", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
+
i = bat_iterator(rt_hashedpwd);
tmp = BUNtvar(i, p);
+ tmp = AUTHdecypherValue(&pwhash, tmp);
bat_iterator_end(&i);
- rethrow("getRemoteTableCredentials", tmp, AUTHdecypherValue(&pwhash,
tmp));
+ if (tmp) {
+ GDKfree(*uri);
+ GDKfree(*username);
+ *uri = NULL;
+ *username = NULL;
+ return tmp;
+ }
*password = pwhash;
diff --git a/monetdb5/modules/mal/pcre.c b/monetdb5/modules/mal/pcre.c
--- a/monetdb5/modules/mal/pcre.c
+++ b/monetdb5/modules/mal/pcre.c
@@ -2193,6 +2193,7 @@ PCREjoin(bat *r1, bat *r2, bat lid, bat
BAT *result1 = NULL, *result2 = NULL;
char *msg = MAL_SUCCEED, *esc = "";
bit ci;
+ BATiter bi;
if ((left = BATdescriptor(lid)) == NULL)
goto fail;
@@ -2231,10 +2232,6 @@ PCREjoin(bat *r1, bat *r2, bat lid, bat
msg = createException(MAL, "pcre.join", SQLSTATE(42000) "At the
moment, only one value is allowed for the escape input at pcre join");
goto fail;
}
- BATiter bi;
- bi = bat_iterator(escape);
- esc = BUNtvar(bi, 0);
- bat_iterator_end(&bi);
if (BATcount(caseignore) != 1) {
msg = createException(MAL, "pcre.join", SQLSTATE(42000) "At the
moment, only one value is allowed for the case ignore input at pcre join");
goto fail;
@@ -2242,7 +2239,10 @@ PCREjoin(bat *r1, bat *r2, bat lid, bat
bi = bat_iterator(caseignore);
ci = *(bit*)BUNtail(bi, 0);
bat_iterator_end(&bi);
+ bi = bat_iterator(escape);
+ esc = BUNtvar(bi, 0);
msg = pcrejoin(result1, result2, left, right, candleft, candright, esc,
ci, anti);
+ bat_iterator_end(&bi);
if (msg)
goto fail;
*r1 = result1->batCacheid;
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -320,14 +320,9 @@ RMTconnect(Client cntxt, MalBlkPtr mb, M
static str
RMTconnectTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- char *local_table;
- char *remoteuser = NULL;
- char *passwd = NULL;
- char *uri = NULL;
- char *tmp;
- char *ret;
- str scen;
- str msg;
+ char *local_table = NULL, *tmp = NULL, *ret = NULL,
+ *remoteuser = NULL, *passwd = NULL, *uri = NULL;
+ str scen, msg;
ValPtr v;
(void)mb;
@@ -344,20 +339,29 @@ RMTconnectTable(Client cntxt, MalBlkPtr
remoteuser = GDKstrdup("");
if (!passwd)
passwd = GDKstrdup("");
+ if (!remoteuser || !passwd) {
+ GDKfree(uri);
+ GDKfree(remoteuser);
+ GDKfree(passwd);
+ throw(MAL, "remote.connect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ }
+
/* The password we just got is hashed. Add the byte \1 in front to
* signal this fact to the mapi. */
size_t pwlen = strlen(passwd);
char *pwhash = (char*)GDKmalloc(pwlen + 2);
if (pwhash == NULL) {
+ GDKfree(uri);
GDKfree(remoteuser);
GDKfree(passwd);
throw(MAL, "remote.connect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
}
snprintf(pwhash, pwlen + 2, "\1%s", passwd);
+ GDKfree(passwd);
msg = RMTconnectScen(&ret, &uri, &remoteuser, &pwhash, &scen, NULL);
-
- GDKfree(passwd);
+ GDKfree(uri);
+ GDKfree(remoteuser);
GDKfree(pwhash);
if (msg == MAL_SUCCEED) {
diff --git a/monetdb5/modules/mal/tokenizer.c b/monetdb5/modules/mal/tokenizer.c
--- a/monetdb5/modules/mal/tokenizer.c
+++ b/monetdb5/modules/mal/tokenizer.c
@@ -507,6 +507,7 @@ takeOid(oid id, str *val)
{
int i, depth;
str parts[MAX_TKNZR_DEPTH];
+ BATiter iters[MAX_TKNZR_DEPTH];
size_t lngth = 0;
str s;
@@ -520,16 +521,18 @@ takeOid(oid id, str *val)
id = GET_h(id);
for (i = depth - 1; i >= 0; i--) {
- BATiter bi = bat_iterator(tokenBAT[i].val);
- parts[i] = (str) BUNtvar(bi, id);
- bat_iterator_end(&bi);
+ iters[i] = bat_iterator(tokenBAT[i].val);
+ parts[i] = (str) BUNtvar(iters[i], id);
id = BUNtoid(tokenBAT[i].idx, id);
lngth += strlen(parts[i]);
}
*val = (str) GDKmalloc(lngth+depth+1);
- if( *val == NULL)
+ if (*val == NULL) {
+ for (i = 0; i < depth; i++)
+ bat_iterator_end(&iters[i]);
throw(MAL, "tokenizer.takeOid", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ }
s = *val;
for (i = 0; i < depth; i++) {
@@ -538,6 +541,8 @@ takeOid(oid id, str *val)
*s++ = '/';
}
*s = '\0';
+ for (i = 0; i < depth; i++)
+ bat_iterator_end(&iters[i]);
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3328,16 +3328,12 @@ sql_sessions_wrap(Client cntxt, MalBlkPt
str
sql_rt_credentials_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci)
{
- BAT *urib = NULL;
- BAT *unameb = NULL;
- BAT *hashb = NULL;
+ BAT *urib = NULL, *unameb = NULL, *hashb = NULL;
bat *uri = getArgReference_bat(stk, pci, 0);
bat *uname = getArgReference_bat(stk, pci, 1);
bat *hash = getArgReference_bat(stk, pci, 2);
str *table = getArgReference_str(stk, pci, 3);
- str uris = NULL;
- str unames = NULL;
- str hashs = NULL;
+ str uris = NULL, unames = NULL, hashs = NULL;
str msg = MAL_SUCCEED;
(void)mb;
(void)cntxt;
@@ -3366,14 +3362,18 @@ sql_rt_credentials_wrap(Client cntxt, Ma
BBPkeepref(*uname = unameb->batCacheid);
BBPkeepref(*hash = hashb->batCacheid);
- if (hashs) GDKfree(hashs);
+ GDKfree(uris);
+ GDKfree(unames);
+ GDKfree(hashs);
return MAL_SUCCEED;
lbailout:
MT_lock_unset(&mal_contextLock);
msg = createException(SQL, "sql.remote_table_credentials",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
bailout:
- if (hashs) GDKfree(hashs);
+ GDKfree(uris);
+ GDKfree(unames);
+ GDKfree(hashs);
if (urib) BBPunfix(urib->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list