diff options
author | Andre Heinecke <[email protected]> | 2018-07-18 10:57:51 +0000 |
---|---|---|
committer | Andre Heinecke <[email protected]> | 2018-07-18 10:57:51 +0000 |
commit | b78140daf7720132711314a4e5ed878b49da99f4 (patch) | |
tree | 8d3abbc2175c15d836c4829635359124e31cb790 /src | |
parent | qt: Handle encoding for diagnostics (diff) | |
download | gpgme-b78140daf7720132711314a4e5ed878b49da99f4.tar.gz gpgme-b78140daf7720132711314a4e5ed878b49da99f4.zip |
json: Fix memory errors in create_keylist_patterns
* src/gpgme-json.c (create_keylist_patterns): Reserve two
pointers more then linefeeds.
(create_keylist_patterns): Fix loop to count linebreaks.
(create_keylist_patterns): Use calloc for good measure.
--
This fixes crashes and memory corruption as cnt did not
match i.
Diffstat (limited to 'src')
-rw-r--r-- | src/gpgme-json.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/gpgme-json.c b/src/gpgme-json.c index 06f09ef0..87b40a2e 100644 --- a/src/gpgme-json.c +++ b/src/gpgme-json.c @@ -691,17 +691,17 @@ create_keylist_patterns (cjson_t request, const char *name) char *p; char *tmp; char **ret; - int cnt = 1; + int cnt = 2; /* Last NULL and one is not newline delimited */ int i = 0; if (get_keys (request, name, &keystring)) return NULL; - for (p = keystring; p; p++) + for (p = keystring; *p; p++) if (*p == '\n') cnt++; - ret = xmalloc (cnt * sizeof *ret); + ret = xcalloc (1, cnt * sizeof *ret); for (p = keystring, tmp = keystring; *p; p++) { @@ -712,8 +712,7 @@ create_keylist_patterns (cjson_t request, const char *name) tmp = p + 1; } /* The last key is not newline delimted. */ - ret[i++] = *tmp ? xstrdup (tmp) : NULL; - ret[i] = NULL; + ret[i] = *tmp ? xstrdup (tmp) : NULL; xfree (keystring); return ret; |