Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
286ffe8c
Commit
286ffe8c
authored
Jan 10, 2014
by
antma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix missed inflateEnd call and enhance handling inflate return value
parent
d2460a8a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
35 deletions
+33
-35
mtproto-client.c
mtproto-client.c
+3
-17
queries.c
queries.c
+3
-18
tools.c
tools.c
+26
-0
tools.h
tools.h
+1
-0
No files found.
mtproto-client.c
View file @
286ffe8c
...
@@ -40,7 +40,6 @@
...
@@ -40,7 +40,6 @@
#include <netinet/in.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <poll.h>
#include <zlib.h>
#include "net.h"
#include "net.h"
#include "include.h"
#include "include.h"
...
@@ -1493,26 +1492,13 @@ void work_packed (struct connection *c, long long msg_id) {
...
@@ -1493,26 +1492,13 @@ void work_packed (struct connection *c, long long msg_id) {
int
l
=
prefetch_strlen
();
int
l
=
prefetch_strlen
();
char
*
s
=
fetch_str
(
l
);
char
*
s
=
fetch_str
(
l
);
size_t
dl
=
MAX_PACKED_SIZE
;
z_stream
strm
;
int
total_out
=
tinflate
(
s
,
l
,
buf
,
MAX_PACKED_SIZE
);
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
l
;
strm
.
next_in
=
(
void
*
)
s
;
strm
.
avail_out
=
MAX_PACKED_SIZE
;
strm
.
next_out
=
(
void
*
)
buf
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
);
if
(
verbosity
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
int
*
end
=
in_ptr
;
int
*
end
=
in_ptr
;
int
*
eend
=
in_end
;
int
*
eend
=
in_end
;
assert
(
dl
%
4
==
0
);
//assert (total_out
% 4 == 0);
in_ptr
=
buf
;
in_ptr
=
buf
;
in_end
=
in_ptr
+
strm
.
total_out
/
4
;
in_end
=
in_ptr
+
total_out
/
4
;
if
(
verbosity
>=
4
)
{
if
(
verbosity
>=
4
)
{
logprintf
(
"Unzipped data: "
);
logprintf
(
"Unzipped data: "
);
hexdump_in
();
hexdump_in
();
...
...
queries.c
View file @
286ffe8c
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include <string.h>
#include <string.h>
#include <memory.h>
#include <memory.h>
#include <stdlib.h>
#include <stdlib.h>
#include <zlib.h>
#include <unistd.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
@@ -215,26 +214,12 @@ void query_result (long long id UU) {
...
@@ -215,26 +214,12 @@ void query_result (long long id UU) {
fetch_int
();
fetch_int
();
int
l
=
prefetch_strlen
();
int
l
=
prefetch_strlen
();
char
*
s
=
fetch_str
(
l
);
char
*
s
=
fetch_str
(
l
);
size_t
dl
=
MAX_PACKED_SIZE
;
int
total_out
=
tinflate
(
s
,
l
,
packed_buffer
,
MAX_PACKED_SIZE
);
z_stream
strm
;
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
l
;
strm
.
next_in
=
(
void
*
)
s
;
strm
.
avail_out
=
MAX_PACKED_SIZE
;
strm
.
next_out
=
(
void
*
)
packed_buffer
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
);
if
(
verbosity
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
end
=
in_ptr
;
end
=
in_ptr
;
eend
=
in_end
;
eend
=
in_end
;
assert
(
dl
%
4
==
0
);
//assert (total_out
% 4 == 0);
in_ptr
=
packed_buffer
;
in_ptr
=
packed_buffer
;
in_end
=
in_ptr
+
strm
.
total_out
/
4
;
in_end
=
in_ptr
+
total_out
/
4
;
if
(
verbosity
>=
4
)
{
if
(
verbosity
>=
4
)
{
logprintf
(
"Unzipped data: "
);
logprintf
(
"Unzipped data: "
);
hexdump_in
();
hexdump_in
();
...
...
tools.c
View file @
286ffe8c
...
@@ -22,10 +22,13 @@
...
@@ -22,10 +22,13 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <openssl/err.h>
#include <openssl/err.h>
#include <zlib.h>
#include "interface.h"
#include "interface.h"
#include "tools.h"
#include "tools.h"
extern
int
verbosity
;
static
void
out_of_memory
(
void
)
{
static
void
out_of_memory
(
void
)
{
logprintf
(
"Out of memory
\n
"
);
logprintf
(
"Out of memory
\n
"
);
assert
(
0
&&
"Out of memory"
);
assert
(
0
&&
"Out of memory"
);
...
@@ -70,3 +73,26 @@ void ensure_ptr (void *p) {
...
@@ -70,3 +73,26 @@ void ensure_ptr (void *p) {
out_of_memory
();
out_of_memory
();
}
}
}
}
int
tinflate
(
void
*
input
,
int
ilen
,
void
*
output
,
int
olen
)
{
z_stream
strm
;
memset
(
&
strm
,
0
,
sizeof
(
strm
));
assert
(
inflateInit2
(
&
strm
,
16
+
MAX_WBITS
)
==
Z_OK
);
strm
.
avail_in
=
ilen
;
strm
.
next_in
=
input
;
strm
.
avail_out
=
olen
;
strm
.
next_out
=
output
;
int
err
=
inflate
(
&
strm
,
Z_FINISH
),
total_out
=
0
;
if
(
err
==
Z_OK
||
err
==
Z_STREAM_END
)
{
total_out
=
(
int
)
strm
.
total_out
;
if
(
err
==
Z_STREAM_END
&&
verbosity
>=
2
)
{
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
}
if
(
verbosity
&&
err
!=
Z_STREAM_END
)
{
logprintf
(
"inflate error = %d
\n
"
,
err
);
logprintf
(
"inflated %d bytes
\n
"
,
(
int
)
strm
.
total_out
);
}
inflateEnd
(
&
strm
);
return
total_out
;
}
tools.h
View file @
286ffe8c
...
@@ -24,6 +24,7 @@ void *talloc (size_t size);
...
@@ -24,6 +24,7 @@ void *talloc (size_t size);
void
*
trealloc
(
void
*
ptr
,
size_t
size
);
void
*
trealloc
(
void
*
ptr
,
size_t
size
);
void
*
talloc0
(
size_t
size
);
void
*
talloc0
(
size_t
size
);
char
*
tstrdup
(
const
char
*
s
);
char
*
tstrdup
(
const
char
*
s
);
int
tinflate
(
void
*
input
,
int
ilen
,
void
*
output
,
int
olen
);
void
ensure
(
int
r
);
void
ensure
(
int
r
);
void
ensure_ptr
(
void
*
p
);
void
ensure_ptr
(
void
*
p
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment