Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvs: do not store NUL byte on json encoded strings in kvs server #1263

Merged
merged 2 commits into from Oct 29, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+5 −5
Diff settings

Always

Just for now

Prev

modules/kvs: Do not store NUL byte

Do not store NUL byte in content store for any json encoded strings.

Update several unit tests appropriately.
  • Loading branch information...
chu11 committed Oct 27, 2017
commit c897c380beabaf1f8ca93fe99e75da1afecdc08b
Copy path View file
@@ -190,7 +190,7 @@ json_t *cache_entry_get_json (struct cache_entry *hp)
if (!hp || !hp->valid || !hp->data)
return NULL;
if (!hp->o) {
if (!(hp->o = json_loads (hp->data, JSON_DECODE_ANY, NULL)))
if (!(hp->o = json_loadb (hp->data, hp->len, JSON_DECODE_ANY, NULL)))
return NULL;
}
return hp->o;
@@ -218,7 +218,7 @@ int cache_entry_set_json (struct cache_entry *hp, json_t *o)
if (!(hp->data = kvs_util_json_dumps (o)))
return -1;

hp->len = strlen (hp->data) + 1;
hp->len = strlen (hp->data);
hp->o = o;
hp->valid = true;

Copy path View file
@@ -81,7 +81,7 @@ int kvs_util_json_hash (const char *hash_name, json_t *o, href_t ref)

if (!(s = kvs_util_json_dumps (o)))
goto error;
if (blobref_hash (hash_name, (uint8_t *)s, strlen (s) + 1,
if (blobref_hash (hash_name, (uint8_t *)s, strlen (s),
ref, sizeof (href_t)) < 0)
goto error;
rc = 0;
Copy path View file
@@ -298,7 +298,7 @@ void cache_entry_raw_and_json_tests (void)

ok ((e = cache_entry_create ()) != NULL,
"cache_entry_create works");
ok (cache_entry_set_raw (e, data, strlen (data) + 1) == 0,
ok (cache_entry_set_raw (e, data, strlen (data)) == 0,
"cache_entry_set_raw success");
ok ((otmp = cache_entry_get_json (e)) != NULL,
"cache_entry_get_json returns non-NULL for json-legal raw data");
@@ -319,7 +319,7 @@ void cache_entry_raw_and_json_tests (void)
"cache_entry_get_raw returns success for get json raw data");
ok (datatmp && strcmp (datatmp, "\"abcd\"") == 0,
"raw data matches expected string version of json");
ok (datatmp && (len == strlen ("\"abcd\"") + 1),
ok (datatmp && (len == strlen ("\"abcd\"")),
"raw data length matches expected length of json string");
cache_entry_destroy (e);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.