Changeset: 7854fc048024 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7854fc048024
Modified Files:
        monetdb5/modules/mal/clients.c
        tools/merovingian/daemon/controlrunner.c
        tools/merovingian/utils/control.c
Branch: Nov2019
Log Message:

Allocation checks for crypto hash functions


diffs (87 lines):

diff --git a/monetdb5/modules/mal/clients.c b/monetdb5/modules/mal/clients.c
--- a/monetdb5/modules/mal/clients.c
+++ b/monetdb5/modules/mal/clients.c
@@ -318,6 +318,9 @@ CLTsetPrintTimeout(void *ret, int *secs)
 str CLTmd5sum(str *ret, str *pw) {
 #ifdef HAVE_MD5_UPDATE
        char *mret = mcrypt_MD5Sum(*pw, strlen(*pw));
+
+       if (!mret)
+               throw(MAL, "clients.md5sum", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        *ret = GDKstrdup(mret);
        free(mret);
        if(*ret == NULL)
@@ -333,6 +336,9 @@ str CLTmd5sum(str *ret, str *pw) {
 str CLTsha1sum(str *ret, str *pw) {
 #ifdef HAVE_SHA1_UPDATE
        char *mret = mcrypt_SHA1Sum(*pw, strlen(*pw));
+
+       if (!mret)
+               throw(MAL, "clients.sha1sum", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        *ret = GDKstrdup(mret);
        free(mret);
        if(*ret == NULL)
@@ -348,6 +354,9 @@ str CLTsha1sum(str *ret, str *pw) {
 str CLTripemd160sum(str *ret, str *pw) {
 #ifdef HAVE_RIPEMD160_UPDATE
        char *mret = mcrypt_RIPEMD160Sum(*pw, strlen(*pw));
+
+       if (!mret)
+               throw(MAL, "clients.ripemd160sum", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
        *ret = GDKstrdup(mret);
        free(mret);
        if(*ret == NULL)
@@ -387,6 +396,9 @@ str CLTsha2sum(str *ret, str *pw, int *b
                        throw(ILLARG, "clients.sha2sum", "wrong number of bits "
                                        "for SHA2 sum: %d", *bits);
        }
+
+       if (!mret)
+               throw(MAL, "clients.sha2sum", SQLSTATE(HY001) MAL_MALLOC_FAIL);
        *ret = GDKstrdup(mret);
        free(mret);
        if(*ret == NULL)
@@ -478,7 +490,8 @@ str CLTcheckPermission(Client cntxt, Mal
 
        (void)mb;
 
-       pwd = mcrypt_SHA1Sum(*pw, strlen(*pw));
+       if (!(pwd = mcrypt_SHA1Sum(*pw, strlen(*pw))))
+               throw(MAL, "clients.checkPermission", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
        msg = AUTHcheckCredentials(&id, cntxt, *usr, pwd, ch, algo);
        free(pwd);
        return msg;
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
@@ -170,6 +170,12 @@ control_authorise(
 
        pwd = mcrypt_hashPassword(algo,
                        getConfVal(_mero_props, "passphrase"), chal);
+       if (!pwd) {
+               Mfprintf(_mero_ctlout, "%s: Allocation failure during 
authentication\n", host);
+               mnstr_printf(fout, "!allocation failure\n");
+               mnstr_flush(fout);
+               return 0;
+       }
        if (strcmp(pwd, passwd) != 0) {
                free(pwd);
                Mfprintf(_mero_ctlout, "%s: permission denied "
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
@@ -303,6 +303,14 @@ char* control_send(
                                        return(strdup(sbuf));
                                }
 
+                               if (!phash) {
+                                       snprintf(sbuf, sizeof(sbuf), "cannot 
connect: "
+                                                       "allocation failure 
while establishing connection");
+                                       close_stream(fdout);
+                                       close_stream(fdin);
+                                       return(strdup(sbuf));
+                               }
+
                                /* now hash the password hash with the provided
                                 * challenge */
                                for (; *algs != NULL; algs++) {
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to