summaryrefslogtreecommitdiffstats
path: root/src/crypt.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-04-27 22:06:37 +0200
committerBram Moolenaar <Bram@vim.org>2019-04-27 22:06:37 +0200
commit6ee9658774942f7448af700fc04df0335796a3db (patch)
tree87f99c37e22f07e73e244da78686c7e59a8457f1 /src/crypt.c
parent00aa069db8132851a91cfc5ca7f58ef945c75c73 (diff)
patch 8.1.1219: not checking for NULL return from alloc()v8.1.1219
Problem: Not checking for NULL return from alloc(). Solution: Add checks. (Martin Kunev, closes #4303, closes #4174)
Diffstat (limited to 'src/crypt.c')
-rw-r--r--src/crypt.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/crypt.c b/src/crypt.c
index 085f8bb813..6eb3e21faf 100644
--- a/src/crypt.c
+++ b/src/crypt.c
@@ -43,7 +43,7 @@ typedef struct {
int (* self_test_fn)();
// Function pointer for initializing encryption/decryption.
- void (* init_fn)(cryptstate_T *state, char_u *key,
+ int (* init_fn)(cryptstate_T *state, char_u *key,
char_u *salt, int salt_len, char_u *seed, int seed_len);
/* Function pointers for encoding/decoding from one buffer into another.
@@ -243,6 +243,7 @@ crypt_self_test(void)
/*
* Allocate a crypt state and initialize it.
+ * Return NULL for failure.
*/
cryptstate_T *
crypt_create(
@@ -255,8 +256,16 @@ crypt_create(
{
cryptstate_T *state = (cryptstate_T *)alloc((int)sizeof(cryptstate_T));
+ if (state == NULL)
+ return state;
+
state->method_nr = method_nr;
- cryptmethods[method_nr].init_fn(state, key, salt, salt_len, seed, seed_len);
+ if (cryptmethods[method_nr].init_fn(
+ state, key, salt, salt_len, seed, seed_len) == FAIL)
+ {
+ vim_free(state);
+ return NULL;
+ }
return state;
}