From c840b636c305efea097f822e8602038f9bc0a82d Mon Sep 17 00:00:00 2001 From: vvaltman Date: Sun, 31 Aug 2014 21:24:39 +0400 Subject: [PATCH] Fixed secert_chat_file read --- loop.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/loop.c b/loop.c index e383325..668e733 100644 --- a/loop.c +++ b/loop.c @@ -554,12 +554,12 @@ void read_secret_chat (int fd) { void read_secret_chat_file (void) { if (binlog_enabled) { return; } - int secret_chat_fd = open (get_secret_chat_filename (), O_CREAT | O_RDWR, 0600); + int secret_chat_fd = open (get_secret_chat_filename (), O_RDWR, 0600); if (secret_chat_fd < 0) { return; } //assert (secret_chat_fd >= 0); int x; - assert (read (secret_chat_fd, &x, 4) == 4); - assert (x == SECRET_CHAT_FILE_MAGIC); + if (read (secret_chat_fd, &x, 4) < 4) { close (secret_chat_fd); return; } + if (x != SECRET_CHAT_FILE_MAGIC) { close (secret_chat_fd); return; } assert (read (secret_chat_fd, &x, 4) == 4); assert (!x); // version assert (read (secret_chat_fd, &x, 4) == 4);