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

Fix #821: crash in kvs due to NULL arg in Jget_str() #822

Merged
merged 3 commits into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/common/libutil/shortjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static __inline__ bool
Jget_int (JSON o, const char *name, int *ip)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && ip)
*ip = json_object_get_int (n);
return (n != NULL);
}
Expand All @@ -134,7 +134,7 @@ static __inline__ bool
Jget_double (JSON o, const char *name, double *dp)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && dp)
*dp = json_object_get_double (n);
return (n != NULL);
}
Expand All @@ -145,7 +145,7 @@ static __inline__ bool
Jget_int64 (JSON o, const char *name, int64_t *ip)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && ip)
*ip = json_object_get_int64 (n);
return (n != NULL);
}
Expand All @@ -156,7 +156,7 @@ static __inline__ bool
Jget_str (JSON o, const char *name, const char **sp)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && sp)
*sp = json_object_get_string (n);
return (n != NULL);
}
Expand All @@ -167,7 +167,7 @@ static __inline__ bool
Jget_obj (JSON o, const char *name, JSON *op)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && op)
*op = n;
return (n != NULL);
}
Expand All @@ -178,7 +178,7 @@ static __inline__ bool
Jget_bool (JSON o, const char *name, bool *bp)
{
JSON n = Jobj_get (o, name);
if (n)
if (n && bp)
*bp = json_object_get_boolean (n);
return (n != NULL);
}
Expand Down Expand Up @@ -235,7 +235,8 @@ Jget_ar_len (JSON o, int *ip)
{
if (json_object_get_type (o) != json_type_array)
return false;
*ip = json_object_array_length (o);
if (ip)
*ip = json_object_array_length (o);
return true;
}

Expand All @@ -248,7 +249,8 @@ Jget_ar_obj (JSON o, int n, JSON *op)
return false;
if (n < 0 || n > json_object_array_length (o))
return false;
*op = json_object_array_get_idx (o, n);
if (op)
*op = json_object_array_get_idx (o, n);
return true;
}

Expand All @@ -265,7 +267,8 @@ Jget_ar_int (JSON o, int n, int *ip)
return false;
if (!(m = json_object_array_get_idx (o, n)))
return false;
*ip = json_object_get_int (m);
if (ip)
*ip = json_object_get_int (m);
return true;
}

Expand All @@ -282,7 +285,8 @@ Jget_ar_str (JSON o, int n, const char **sp)
return false;
if (!(m = json_object_array_get_idx (o, n)))
return false;
*sp = json_object_get_string (m);
if (sp)
*sp = json_object_get_string (m);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ check_SCRIPTS = \
t4000-issues-test-driver.t \
issues/t0441-kvs-put-get.sh \
issues/t0505-msg-handler-reg.lua \
issues/t0821-kvs-segfault.sh \
lua/t0001-send-recv.t \
lua/t0002-rpc.t \
lua/t0003-events.t \
Expand Down
7 changes: 7 additions & 0 deletions t/issues/t0821-kvs-segfault.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh -e
# kvs put test="large string", get test.x fails without panic

TEST=issue0821
flux kvs put ${TEST}="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
flux kvs get ${TEST}.x && test $? -eq 1
flux kvs get ${TEST} # fails if broker died