Fix SEGV on empty /restful/meshms/.../conversationlist.json

This commit is contained in:
Andrew Bettison 2014-06-26 14:53:59 +09:30
parent 776d4de894
commit 6c16b95a38

View File

@ -206,7 +206,8 @@ static int restful_meshms_conversationlist_json(httpd_request *r, const char *re
enum meshms_status status; enum meshms_status status;
if (meshms_failed(status = meshms_conversations_list(&r->sid1, NULL, &r->u.mclist.conv))) if (meshms_failed(status = meshms_conversations_list(&r->sid1, NULL, &r->u.mclist.conv)))
return http_request_meshms_response(r, 0, NULL, status); return http_request_meshms_response(r, 0, NULL, status);
meshms_conversation_iterator_start(&r->u.mclist.iter, r->u.mclist.conv); if (r->u.mclist.conv != NULL)
meshms_conversation_iterator_start(&r->u.mclist.iter, r->u.mclist.conv);
http_request_response_generated(&r->http, 200, CONTENT_TYPE_JSON, restful_meshms_conversationlist_json_content); http_request_response_generated(&r->http, 200, CONTENT_TYPE_JSON, restful_meshms_conversationlist_json_content);
return 1; return 1;
} }
@ -246,7 +247,7 @@ static int restful_meshms_conversationlist_json_content_chunk(struct http_reques
r->u.mclist.phase = LIST_ROWS; r->u.mclist.phase = LIST_ROWS;
return 1; return 1;
case LIST_ROWS: case LIST_ROWS:
if (r->u.mclist.iter.current == NULL) { if (r->u.mclist.conv == NULL || r->u.mclist.iter.current == NULL) {
r->u.mclist.phase = LIST_END; r->u.mclist.phase = LIST_END;
// fall through... // fall through...
} else { } else {