From 49b13e8b24acbd6241754b1f76420aa6fdb1e0fb Mon Sep 17 00:00:00 2001 From: Sergei Rogachev Date: Sun, 18 Apr 2021 17:53:18 +0300 Subject: [PATCH] Fix incorrect response parsing in telebot_download_file Signed-off-by: Sergei Rogachev --- src/telebot.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/telebot.c b/src/telebot.c index 6710643..5072ad9 100644 --- a/src/telebot.c +++ b/src/telebot.c @@ -841,7 +841,20 @@ telebot_error_e telebot_download_file(telebot_handler_t handle, const char *file goto finish; } - ret = telebot_parser_get_file(obj, &file); + struct json_object *ok = NULL; + if (!json_object_object_get_ex(obj, "ok", &ok) || !json_object_get_boolean(ok)) + { + ret = TELEBOT_ERROR_OPERATION_FAILED; + goto finish; + } + + struct json_object *result = NULL; + if (!json_object_object_get_ex(obj, "result", &result)) { + ret = TELEBOT_ERROR_OPERATION_FAILED; + goto finish; + } + + ret = telebot_parser_get_file(result, &file); if (ret != TELEBOT_ERROR_NONE) goto finish;