Giter Site home page Giter Site logo

telebot's People

Contributors

damaxi avatar denzen84 avatar erickpires avatar ilyabrin avatar jakob-stark avatar kasymovga avatar nachtalb avatar nekijbt avatar ozbek avatar p4vook avatar pt300 avatar richiefreedom avatar smartnode avatar wmealing avatar xdqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telebot's Issues

Building under Debian Stretch for Raspberry Pi fails

I tried to build from source the testprogram echobot on my Raspberry Pi but building process fails under Debian Stretch. I remember, that it worked with Jessie but something changed now.
The mainreason for this that the packages "json" and "libcurl" are not available anymore with exact these names. But cmake checks in CMakeList.txt exactly for these packages and fails.
Any idea how to fix that?

disable_notification is not working ?

It seems the notification sound is always there and the disable_notification is not present in the JSON debug printout ?
Or did I miss something ?
There seems to be a code treating it in the telebot-core_send-message() but then why it does not work ?

run makefile console error in Centos 7.8

/www/wwwroot/telebot/src/telebot-parser.c: In function ‘telebot_parser_get_photos’:
/www/wwwroot/telebot/src/telebot-parser.c:881:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int index = 0; index < array_len; index++)
^
/www/wwwroot/telebot/src/telebot-parser.c: In function ‘telebot_parser_get_poll_answer’:
/www/wwwroot/telebot/src/telebot-parser.c:1447:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int index = 0; index < answer->count_option_ids; index++)
^
/www/wwwroot/telebot/src/telebot-parser.c: In function ‘telebot_parser_get_poll’:
/www/wwwroot/telebot/src/telebot-parser.c:1578:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int index = 0; index < poll->count_options; index++)
^
/www/wwwroot/telebot/src/telebot-parser.c: In function ‘telebot_parser_get_user_profile_photos’:
/www/wwwroot/telebot/src/telebot-parser.c:1624:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 0; i < 4; i++)
^
/www/wwwroot/telebot/src/telebot-parser.c:1629:14: error: redefinition of ‘i’
for (int i = 0; i < total; i++)
^
/www/wwwroot/telebot/src/telebot-parser.c:1624:14: note: previous definition of ‘i’ was here
for (int i = 0; i < 4; i++)
^
/www/wwwroot/telebot/src/telebot-parser.c:1629:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 0; i < total; i++)
^
/www/wwwroot/telebot/src/telebot-parser.c:1635:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int j = 0; j < subtotal; j++)
^
/www/wwwroot/telebot/src/telebot-parser.c:1644:9: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 0; i < 4; i++)
^
make[3]: *** [CMakeFiles/telebot.dir/src/telebot-parser.c.o] Error 1
make[2]: *** [CMakeFiles/telebot.dir/all] Error 2
make[1]: *** [test/CMakeFiles/echobot.dir/rule] Error 2
make: *** [echobot] Error 2

Bot crashes when two identic messages were sent in a row

I use example, provided in echobot.c.
When I try to send two identic messages ("abcd" or "test") in a row bot crashes with following error:

corrupted size vs. prev_size while consolidating
[1]    60895 abort (core dumped)    ./echobot

My environment;

$ uname -a
Linux ppc 5.4.38-gentoo #21 SMP Wed Jul 22 21:10:25 MSK 2020 x86_64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz GenuineIntel GNU/Linux

Bot crashes at telebot_destroy(handle);

Hi,

I wrote simple bot that sends a message from command line. It sends message normally and crashes after call telebot_destroy(handle); .

telebot_handler_t handle;
if (telebot_create(&handle, token) != TELEBOT_ERROR_NONE) {
        printf("Telebot create failed\n");
        return -1;
    }
telebot_error_e ret;
if (!strcmp(argv[1],"--sendtext")) {
    		ret = telebot_send_message(handle, group_id, argv[2], "", false, false, 0, "");
    		if (ret != TELEBOT_ERROR_NONE) {
    			printf("Failed to send text message: %d \n", ret);
    		}
    } else {
    	printf("Unrecognized command\n");
    }
    telebot_destroy(handle);
}

Download image

I need to download the transmitted picture. I wrote the following small code:

	if (message->photo[1].file_size > 0) {
		char file_id[TELEBOT_FILE_ID_SIZE];
		strcpy(file_id,message->photo[1].file_id);
		ret = telebot_download_file(file_id, "photos/file_7.jpg");
		if (ret != TELEBOT_ERROR_NONE) {
			printf("Failed to download file: %d \n", ret);
		}
	}

But it does not work, it returns -1. In the process of debugging, it was revealed that a variable file_path was not obtained in the function of the telebot_error_e telebot_download_file(char *file_id, char *path).

ret = telebot_parser_get_file_path(obj, &file_path);
json_object_put(obj);

if (file_path == NULL) {
	printf("if (file_path == NULL) {\n");
	return TELEBOT_ERROR_OPERATION_FAILED;
}

Specifically, the problem in this function call:

telebot_error_e telebot_parser_get_file_path(struct json_object *obj,
char **path) {

if (json_object_object_get_ex (obj, "file_path", &file_path)) {
	*path = strdup(json_object_get_string(file_path));
	json_object_put (file_path);
}
else {
	*path = NULL;
	return TELEBOT_ERROR_OPERATION_FAILED;
}

}

This function returns TELEBOT_ERROR_OPERATION_FAILED. The system displays the following debugging messages:

[DEBUG][telebot_core_curl_perform:100]Response: {"ok":true,"result":[{"update_id":940457749,
"message":{"message_id":163,"from":{"id":183246257,"is_bot":false,"first_name":"\u0421\u0435\u0440\u0433\u0435\u0439","last_name":"\u0414\u043e\u043b\u0438\u043d","username":"dlinyj","language_code":"ru"},"chat":{"id":183246257,"first_name":"\u0421\u0435\u0440\u0433\u0435\u0439","last_name":"\u0414\u043e\u043b\u0438\u043d","username":"dlinyj","type":"private"},"date":1504612315,"photo":[{"file_id":"AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABPxIpZ1qrqh9gTgAAgI","file_size":704,"width":90,"height":15},{"file_id":"AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABPioQiHmnf3cgjgAAgI","file_size":5111,"width":320,"height":52},{"file_id":"AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABAHAh8adkcv3gzgAAgI","file_size":20592,"width":800,"height":129},{"file_id":"AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABP7c6v1gPEDDgDgAAgI","file_size":42989,"width":1280,"height":206}]}}]}
file_id = AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABPioQiHmnf3cgjgAAgI
[DEBUG][telebot_core_curl_perform:100]Response: {"ok":true,"result":{"file_id":"AgADAgADEKgxG9_kcUkSKsR2nOYdSvfrDw4ABPioQiHmnf3cgjgAAgI","file_size":5111,"file_path":"photos/file_14.jpg"}}
Failed to download file: -1
[DEBUG][telebot_core_curl_perform:100]Response: {"ok":true,"result":{"message_id":164,"from":{"id":405310886,"is_bot":true,"first_name":"hipcrt_bot","username":"hipcrt_bot"},"chat":{"id":183246257,"first_name":"\u0421\u0435\u0440\u0433\u0435\u0439","last_name":"\u0414\u043e\u043b\u0438\u043d","username":"dlinyj","type":"private"},"date":1504612316,"photo":[{"file_id":"AgADAgAD5KcxG568eUn9Ofw4oE4jWP88Sw0ABAueH2XiToz4NFEPAAEC","file_size":1769,"file_path":"photos/file_12.jpg","width":90,"height":90},{"file_id":"AgADAgAD5KcxG568eUn9Ofw4oE4jWP88Sw0ABLEyzOcAAQyVyDVRDwABAg","file_size":13258,"width":320,"height":320},{"file_id":"AgADAgAD5KcxG568eUn9Ofw4oE4jWP88Sw0ABOHzFRhiJI_CM1EPAAEC","file_size":15608,"width":400,"height":400}]}}
[DEBUG][telebot_core_curl_perform:100]Response: {"ok":true,"result":{"message_id":165,"from":{"id":405310886,"is_bot":true,"first_name":"hipcrt_bot","username":"hipcrt_bot"},"chat":{"id":183246257,"first_name":"\u0421\u0435\u0440\u0433\u0435\u0439","last_name":"\u0414\u043e\u043b\u0438\u043d","username":"dlinyj","type":"private"},"date":1504612316,"text":"getphoto"}}

What am I doing wrong?

telebot uses 32 bit int for chat id which needs up to 56 bits

The example echobot fails to send messages to some group chats (and maybe some private chats too). In general it is safe to use 32 bit signed integer for all integer types as notet in the telegram bot api description. However there is one exception, that is the chat ids, which may use up to 56 bits (https://core.telegram.org/bots/api#chat). The telebot library also uses 32 bit signed integer (int) to store these chat ids. Apperently thats the cause for those random failure to send data to a chat.

first steps using echobot

HI,

I´m having troubles to test echobot example.

I have a bot called SaborDelivery (@luisgama_bot ) .

this bot is running ok between my telegram app ( under debian 8 ) and my cell phone, but when I´m try to use echobot:

Welcome to Echobot
Token: 268963290:AAHprXUwmtHf7Kt1mlR19riL74WiYBdPFRs
[ERROR][telebot_core_curl_perform:84]Failed to curl_easy_perform
Error: Couldn't connect to server (7)
Failed to get bot information

Am I doing anything wrong?

Thanks

User editing already send message will result in crash.

If the user presses the arrow up key in Telegram to access his last written message and then edits that message the echobot will crash with Segmentation Fault in line 66.
message.from, message.text and message.chat are all NULL

Telebot crashes if user send less then 3 characters.

I have played around with echobot.c and found that it crashes if I send 2 letters. No problems if I send 3 or more letters. Got errors:
[DEBUG][telebot_core_curl_perform:142]Response: {"ok":true,"result":[{"update_id":345541365, "message":{"message_id":86,"from":{"id":337925211,"is_bot":false,"first_name":"Loosing","last_name":"Control","username":"Cartoonboy","language_code":"en"},"chat":{"id":337925211,"first_name":"Loosing","last_name":"Control","username":"Cartoonboy","type":"private"},"date":1594114626,"text":"du"}}]} corrupted size vs. prev_size Aborted (core dumped)
or

[DEBUG][telebot_core_curl_perform:142]Response: {"ok":true,"result":[{"update_id":345541357, "message":{"message_id":76,"from":{"id":337925211,"is_bot":false,"first_name":"Loosing","last_name":"Control","username":"Cartoonboy","language_code":"en"},"chat":{"id":337925211,"first_name":"Loosing","last_name":"Control","username":"Cartoonboy","type":"private"},"date":1594113760,"text":"ll"}}]} malloc(): invalid next size (unsorted) Aborted (core dumped)

The only change I made in echobot.c was function "telebot_send_dice(....)" which can be called by "/dice".
So, if I send bot "du" or other two characters it crashes and to make bot work properly again i need to call "/dice" command and start bot again, otherwise it crashes receiving last command "du".

And I'm lack of inline keyboard))))) I saw in doc's that it is in TODO mood, and I hope you will do it in recent future. Yep, I am that one strange guy who wants to write bot using C in 2020)))))

P.S. it also crashes if user sends emoji or sticker

docs?

so i want to make a tg bot with this lib but i dont find any biginer frendly spreedsheet or exemple i dont understand the lib

Error on file send

Hello, I get an error, when I try to send a file. There is no problem with text messages.

The code:

...
int someid = 0;
char str[4096];

snprintf(str, SIZE_OF_ARRAY(str), "/path/to/a/document.extension");
ret = telebot_send_document(handle, someid, str, true, "", "aaa", "", false,0,"");

if (ret != TELEBOT_ERROR_NONE) {
    printf("Failed to send message: %d \n", ret);
}
...

The error message:

[ERROR][telebot_core_curl_perform:129]Failed to curl_easy_perform
Error: Failed to open/read local data from file/application (26)
Failed to send message: -1 

How to compile on Windows?

I would like to use your library, but could not figure out how to compile it on Windows. Can you help me out?

I get following error:
C:\Program Files (x86)\CodeBlocks\MinGW\include\pthread.h|196|error: unknown type name 'uintptr_t'

Failed to send file as document, server response is 400

ret = telebot_send_document(handle, sstgbconf.user_id, sstgbconf.docfile, true, false, 0, NULL); if (ret != TELEBOT_ERROR_NONE) { printf("Failed to send document: %d \n", ret); }

The result is:

[ERROR][telebot_core_curl_perform:95]Wrong HTTP response received, response: 400
Failed to send document: -1

Possibly changes in Telegram API ?

Failed to curl_easy_perform

the library output is giving me
[ERROR][telebot_core_curl_perform:92]Failed to curl_easy_perform Error: URL using bad/illegal format or missing URL (3)

echobot leaks memory

I modified the echobot loop so that it will break after the 5th iteration and checked with valgrind for memory leaks. Note that I was sending the bot no messages during this test.

[DEBUG][telebot_core_curl_perform:131]Response: {"ok":true,"result":[]}
[DEBUG][telebot_core_curl_perform:131]Response: {"ok":true,"result":[]}
[DEBUG][telebot_core_curl_perform:131]Response: {"ok":true,"result":[]}
[DEBUG][telebot_core_curl_perform:131]Response: {"ok":true,"result":[]}
[DEBUG][telebot_core_curl_perform:131]Response: {"ok":true,"result":[]}
==607==
==607== HEAP SUMMARY:
==607==     in use at exit: 2,465 bytes in 60 blocks
==607==   total heap usage: 164,433 allocs, 164,373 frees, 16,521,774 bytes allocated
==607==
==607== 2,465 (560 direct, 1,905 indirect) bytes in 5 blocks are definitely lost in loss record 12 of 12
==607==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==607==    by 0x56731A3: curl_formadd (in /usr/lib/x86_64-linux-gnu/libcurl.so.4.5.0)
==607==    by 0x4E44266: telebot_core_get_updates (telebot-core.c:251)
==607==    by 0x4E4A364: telebot_get_updates (telebot.c:172)
==607==    by 0x108F80: main (echobot.c:61)
==607==
==607== LEAK SUMMARY:
==607==    definitely lost: 560 bytes in 5 blocks
==607==    indirectly lost: 1,905 bytes in 55 blocks
==607==      possibly lost: 0 bytes in 0 blocks
==607==    still reachable: 0 bytes in 0 blocks
==607==         suppressed: 0 bytes in 0 blocks
==607==
==607== For counts of detected and suppressed errors, rerun with: -v
==607== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

Here the changes I made to echobot.c:
line 53:

int i = 5;
while(1){
       if(i==0) break;
       i--;

More Extensive Documentation?

So far for me the header files are sufficient, but I was wondering whether it would be worth creating a Wiki page to get new users started? I was also wondering whether the ability to display a couple of clickable options to the user is implemented (obviously this exposes how new I am to the telegram bot api in general).

Thank you very much for this effort!
The API framework appears pretty robust and stable so far

free(): invalid pointer - in telebot_put_user

Hi. My app using telebot is crashing in telebot_put_user. I updated to last commit "Fix memory corruption caused by a variable name mistake."

_#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7b81537 in __GI_abort () at abort.c:79
#2 0x00007ffff7bd93e8 in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7cf7390 "%s\n")
at ../sysdeps/posix/libc_fatal.c:155
#3 0x00007ffff7be06da in malloc_printerr (str=str@entry=0x7ffff7cf5045 "free(): invalid pointer") at malloc.c:5347
#4 0x00007ffff7be1894 in _int_free (av=, p=, have_lock=0) at malloc.c:4173
#5 0x00007ffff7f97e77 in telebot_put_user () from /usr/local/lib/libtelebot.so.4.7.0
#6 0x00007ffff7f98257 in telebot_put_message () from /usr/local/lib/libtelebot.so.4.7.0
#7 0x00007ffff7f95502 in telebot_put_updates () from /usr/local/lib/libtelebot.so.4.7.0
#8 0x00005555555618ba in main (argc=1, argv=0x7fffffffe4f8) at telebot.cpp:1292
_
telebot.cpp:1292 --> telebot_put_updates(updates, count);

while (1)
    {
        ret = telebot_get_updates(handle, offset, 20, 0, update_types, 0, &updates, &count);
        if (ret != TELEBOT_ERROR_NONE)
            continue;

        //printf("Number of updates: %d\n", count);
        for (index = 0; index < count; index++)
        {
            message = updates[index].message;
            //
            if (message.text)
            {
                char str[1024];
                std::vector<string> tokens;
                if (strstr(message.text, "/start"))
                {
                    //
                    ret = telebot_send_message(handle, message.chat->id, str, "HTML",
                        false, false, updates[index].message.message_id, "");
                    //
                    printf("msg: %s\n", str);
                }
            }
            offset = updates[index].update_id + 1;
        }
        telebot_put_updates(updates, count);

        sleep(1);
    }

    telebot_destroy(handle);```

Does not compile statically

When I try to build a static binary for echobot, linker fails with a lot of "undefined reference to symbol (libcurl, libjsonc functions)" errors.

Fails to build under gcc 9.2.0

[ 16%] Building C object CMakeFiles/telebot.dir/src/telebot-parser.c.o
[ 33%] Building C object CMakeFiles/telebot.dir/src/telebot-core.c.o
[ 50%] Building C object CMakeFiles/telebot.dir/src/telebot.c.o
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c: In function ‘telebot_get_updates’:
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:159:26: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  159 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                          ^~~~~~~~~~~~~~~~~~~                 ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:162:26: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  162 |                 snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str,
      |                          ^~~~~~~~~~~~~~~~~~~                ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:165:18: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  165 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str,"]");
      |                  ^~~~~~~~~~~~~~~~~~~                ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c: In function ‘telebot_set_webhook’:
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:329:26: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  329 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                          ^~~~~~~~~~~~~~~~~~~                 ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:332:26: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  332 |                 snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str,
      |                          ^~~~~~~~~~~~~~~~~~~                ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:335:18: error: passing argument 1 to restrict-qualified parameter aliases with argument 4 [-Werror=restrict]
  335 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str, "]");
      |                  ^~~~~~~~~~~~~~~~~~~                ~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c: In function ‘telebot_get_updates’:
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:165:50: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  165 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str,"]");
      |                                                  ^
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:165:9: note: ‘snprintf’ output between 2 and 1025 bytes into a destination of size 1024
  165 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str,"]");
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:159:59: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  159 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                                                           ^
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:159:17: note: ‘snprintf’ output 2 or more bytes (assuming 1025) into a destination of size 1024
  159 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  160 |                         telebot_update_type_str[allowed_updates[i]]);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c: In function ‘telebot_set_webhook’:
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:335:50: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  335 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str, "]");
      |                                                  ^
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:335:9: note: ‘snprintf’ output between 2 and 1025 bytes into a destination of size 1024
  335 |         snprintf(allowed_updates_str, 1024, "%s%s", allowed_updates_str, "]");
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:329:59: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
  329 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                                                           ^
/home/alice/at/2019-10-18_19:03:05/telebot/src/telebot.c:329:17: note: ‘snprintf’ output 2 or more bytes (assuming 1025) into a destination of size 1024
  329 |                 snprintf(allowed_updates_str, 1024, "%s%s,", allowed_updates_str,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  330 |                         telebot_update_type_str[allowed_updates[i]]);
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/telebot.dir/build.make:89: CMakeFiles/telebot.dir/src/telebot.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/telebot.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Crash on messages forwarded from chats

Telebot crashes when freeing updates object if one of the messages was a forward from a chat.

I traced the problem to line 488 in telebot-parser.c, which seems to be a mistake when copy pasting similar code.

struct json_object *forward_from_chat = NULL;
if (json_object_object_get_ex(obj, "forward_from_chat", &forward_from_chat))
{
msg->forward_from = malloc(sizeof(telebot_user_t));
if (telebot_parser_get_chat(forward_from_chat, msg->forward_from_chat) != TELEBOT_ERROR_NONE)
{
ERR("Failed to get <forward from> from message object");
TELEBOT_SAFE_FREE(msg->forward_from_chat);
}
}

It ought to be msg->forward_from_chat = malloc(sizeof(telebot_chat_t));.

This causes a bug in which msg->forward_from is overwritten with a pointer to uninitialized memory. This causes issues during freeing, as telebot_put_user sees non-null pointers and tries to free them. This causes memory corruption and an eventual crash.

too frequent fatal errors

my bot stops working many times. sometimes even stops after a minute after starting.
most errors are:
free(): invalid pointer (I don't use free() in my code)
double free or corruption (out)
unable to get forwarded from

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.