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
19851f9e
Commit
19851f9e
authored
Jan 13, 2014
by
vysheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #37 from antma/master
checks strndup result & enhance configure.ac
parents
06a26ebc
6b87e312
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
86 additions
and
25 deletions
+86
-25
binlog.c
binlog.c
+5
-1
configure.ac
configure.ac
+4
-2
interface.c
interface.c
+8
-5
loop.c
loop.c
+5
-3
lua-tg.c
lua-tg.c
+2
-0
main.c
main.c
+3
-1
mtproto-client.c
mtproto-client.c
+5
-0
mtproto-common.c
mtproto-common.c
+5
-0
net.c
net.c
+5
-0
queries.c
queries.c
+16
-6
structures.c
structures.c
+2
-0
tools.c
tools.c
+25
-7
tools.h
tools.h
+1
-0
No files found.
binlog.c
View file @
19851f9e
...
@@ -16,7 +16,11 @@
...
@@ -16,7 +16,11 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#ifdef USE_LUA
#ifdef USE_LUA
# include "lua-tg.h"
# include "lua-tg.h"
#endif
#endif
...
@@ -100,7 +104,7 @@ void replay_log_event (void) {
...
@@ -100,7 +104,7 @@ void replay_log_event (void) {
if
(
verbosity
)
{
if
(
verbosity
)
{
logprintf
(
"id = %d, name = %.*s ip = %.*s port = %d
\n
"
,
id
,
l1
,
name
,
l2
,
ip
,
port
);
logprintf
(
"id = %d, name = %.*s ip = %.*s port = %d
\n
"
,
id
,
l1
,
name
,
l2
,
ip
,
port
);
}
}
alloc_dc
(
id
,
strndup
(
ip
,
l2
),
port
);
alloc_dc
(
id
,
t
strndup
(
ip
,
l2
),
port
);
}
}
rptr
=
in_ptr
;
rptr
=
in_ptr
;
break
;
break
;
...
...
configure.ac
View file @
19851f9e
...
@@ -99,15 +99,17 @@ AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
...
@@ -99,15 +99,17 @@ AC_ARG_ENABLE(liblua,[--enable-liblua/--disable-liblua],
])
])
# Checks for header files.
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h malloc.h
stdlib.h string.h sys/socket.h unistd
.h])
AC_CHECK_HEADERS([fcntl.h malloc.h
netdb.h stdlib.h string.h unistd.h arpa/inet.h mach/mach.h netinet/in.h sys/file.h sys/socket.h termios
.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_C_INLINE
# Checks for library functions.
# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_REALLOC
AC_CHECK_FUNCS([
memset select strdup strndup
])
AC_CHECK_FUNCS([
alarm endpwent memset memmove mkdir select socket strdup strndup uname
])
AC_SUBST(EXTRA_LIBS)
AC_SUBST(EXTRA_LIBS)
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Makefile])
...
...
interface.c
View file @
19851f9e
...
@@ -17,7 +17,10 @@
...
@@ -17,7 +17,10 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <assert.h>
#include <assert.h>
...
@@ -675,7 +678,7 @@ void interpreter (char *line UU) {
...
@@ -675,7 +678,7 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
do_send_photo
(
CODE_input_media_uploaded_photo
,
id
,
strndup
(
s
,
t
));
do_send_photo
(
CODE_input_media_uploaded_photo
,
id
,
t
strndup
(
s
,
t
));
}
else
if
(
IS_WORD
(
"send_video"
))
{
}
else
if
(
IS_WORD
(
"send_video"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -684,7 +687,7 @@ void interpreter (char *line UU) {
...
@@ -684,7 +687,7 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
do_send_photo
(
CODE_input_media_uploaded_video
,
id
,
strndup
(
s
,
t
));
do_send_photo
(
CODE_input_media_uploaded_video
,
id
,
t
strndup
(
s
,
t
));
}
else
if
(
IS_WORD
(
"send_text"
))
{
}
else
if
(
IS_WORD
(
"send_text"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -693,7 +696,7 @@ void interpreter (char *line UU) {
...
@@ -693,7 +696,7 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
do_send_text
(
id
,
strndup
(
s
,
t
));
do_send_text
(
id
,
t
strndup
(
s
,
t
));
}
else
if
(
IS_WORD
(
"fwd"
))
{
}
else
if
(
IS_WORD
(
"fwd"
))
{
GET_PEER
;
GET_PEER
;
int
num
=
next_token_int
();
int
num
=
next_token_int
();
...
@@ -950,7 +953,7 @@ void interpreter (char *line UU) {
...
@@ -950,7 +953,7 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
do_send_photo
(
CODE_input_media_uploaded_audio
,
id
,
strndup
(
s
,
t
));
do_send_photo
(
CODE_input_media_uploaded_audio
,
id
,
t
strndup
(
s
,
t
));
}
else
if
(
IS_WORD
(
"send_document"
))
{
}
else
if
(
IS_WORD
(
"send_document"
))
{
GET_PEER
;
GET_PEER
;
int
t
;
int
t
;
...
@@ -959,7 +962,7 @@ void interpreter (char *line UU) {
...
@@ -959,7 +962,7 @@ void interpreter (char *line UU) {
printf
(
"Empty file name
\n
"
);
printf
(
"Empty file name
\n
"
);
RET
;
RET
;
}
}
do_send_photo
(
CODE_input_media_uploaded_document
,
id
,
strndup
(
s
,
t
));
do_send_photo
(
CODE_input_media_uploaded_document
,
id
,
t
strndup
(
s
,
t
));
}
else
if
(
IS_WORD
(
"load_audio"
))
{
}
else
if
(
IS_WORD
(
"load_audio"
))
{
long
long
num
=
next_token_int
();
long
long
num
=
next_token_int
();
if
(
num
==
NOT_FOUND
)
{
if
(
num
==
NOT_FOUND
)
{
...
...
loop.c
View file @
19851f9e
...
@@ -16,13 +16,15 @@
...
@@ -16,13 +16,15 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#define READLINE_CALLBACKS
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#define _GNU_SOURCE
#endif
#define READLINE_CALLBACKS
#include <assert.h>
#include <assert.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#ifdef READLINE_GNU
#ifdef READLINE_GNU
...
...
lua-tg.c
View file @
19851f9e
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#ifdef USE_LUA
#ifdef USE_LUA
#include "lua-tg.h"
#include "lua-tg.h"
...
...
main.c
View file @
19851f9e
...
@@ -16,8 +16,10 @@
...
@@ -16,8 +16,10 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#define _GNU_SOURCE
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
...
...
mtproto-client.c
View file @
19851f9e
...
@@ -17,6 +17,11 @@
...
@@ -17,6 +17,11 @@
Copyright Nikolay Durov, Andrey Lopatin 2012-2013
Copyright Nikolay Durov, Andrey Lopatin 2012-2013
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _FILE_OFFSET_BITS 64
#define _FILE_OFFSET_BITS 64
#include <assert.h>
#include <assert.h>
...
...
mtproto-common.c
View file @
19851f9e
...
@@ -17,6 +17,11 @@
...
@@ -17,6 +17,11 @@
Copyright Nikolay Durov, Andrey Lopatin 2012-2013
Copyright Nikolay Durov, Andrey Lopatin 2012-2013
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _FILE_OFFSET_BITS 64
#define _FILE_OFFSET_BITS 64
#include <assert.h>
#include <assert.h>
...
...
net.c
View file @
19851f9e
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <string.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
...
...
queries.c
View file @
19851f9e
...
@@ -16,6 +16,11 @@
...
@@ -16,6 +16,11 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _FILE_OFFSET_BITS 64
#define _FILE_OFFSET_BITS 64
#include <string.h>
#include <string.h>
#include <memory.h>
#include <memory.h>
...
@@ -386,7 +391,7 @@ int send_code_on_answer (struct query *q UU) {
...
@@ -386,7 +391,7 @@ int send_code_on_answer (struct query *q UU) {
if
(
phone_code_hash
)
{
if
(
phone_code_hash
)
{
tfree_str
(
phone_code_hash
);
tfree_str
(
phone_code_hash
);
}
}
phone_code_hash
=
strndup
(
s
,
l
);
phone_code_hash
=
t
strndup
(
s
,
l
);
want_dc_num
=
-
1
;
want_dc_num
=
-
1
;
return
0
;
return
0
;
}
}
...
@@ -1462,6 +1467,7 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
...
@@ -1462,6 +1467,7 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
int
fd
=
open
(
file_name
,
O_RDONLY
);
int
fd
=
open
(
file_name
,
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
rprintf
(
"No such file '%s'
\n
"
,
file_name
);
rprintf
(
"No such file '%s'
\n
"
,
file_name
);
tfree_str
(
file_name
);
return
;
return
;
}
}
struct
stat
buf
;
struct
stat
buf
;
...
@@ -1469,6 +1475,7 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
...
@@ -1469,6 +1475,7 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
long
long
size
=
buf
.
st_size
;
long
long
size
=
buf
.
st_size
;
if
(
size
<=
0
)
{
if
(
size
<=
0
)
{
rprintf
(
"File has zero length
\n
"
);
rprintf
(
"File has zero length
\n
"
);
tfree_str
(
file_name
);
close
(
fd
);
close
(
fd
);
return
;
return
;
}
}
...
@@ -1483,6 +1490,14 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
...
@@ -1483,6 +1490,14 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
f
->
part_size
*=
2
;
f
->
part_size
*=
2
;
}
}
if
(
f
->
part_size
>
(
512
<<
10
))
{
close
(
fd
);
rprintf
(
"Too big file. Maximal supported size is %d.
\n
"
,
(
512
<<
10
)
*
1000
);
tfree
(
f
,
sizeof
(
*
f
));
tfree_str
(
file_name
);
return
;
}
f
->
id
=
lrand48
()
*
(
1ll
<<
32
)
+
lrand48
();
f
->
id
=
lrand48
()
*
(
1ll
<<
32
)
+
lrand48
();
f
->
to_id
=
to_id
;
f
->
to_id
=
to_id
;
f
->
media_type
=
type
;
f
->
media_type
=
type
;
...
@@ -1496,11 +1511,6 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
...
@@ -1496,11 +1511,6 @@ void do_send_photo (int type, peer_id_t to_id, char *file_name) {
f
->
key
=
talloc
(
32
);
f
->
key
=
talloc
(
32
);
secure_random
(
f
->
key
,
32
);
secure_random
(
f
->
key
,
32
);
}
}
if
(
f
->
part_size
>
(
512
<<
10
))
{
close
(
fd
);
rprintf
(
"Too big file. Maximal supported size is %d"
,
(
512
<<
10
)
*
1000
);
return
;
}
if
(
f
->
media_type
==
CODE_input_media_uploaded_video
&&
!
f
->
encr
)
{
if
(
f
->
media_type
==
CODE_input_media_uploaded_video
&&
!
f
->
encr
)
{
f
->
media_type
=
CODE_input_media_uploaded_thumb_video
;
f
->
media_type
=
CODE_input_media_uploaded_thumb_video
;
send_file_thumb
(
f
);
send_file_thumb
(
f
);
...
...
structures.c
View file @
19851f9e
...
@@ -17,7 +17,9 @@
...
@@ -17,7 +17,9 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif
#include <assert.h>
#include <assert.h>
#include <string.h>
#include <string.h>
...
...
tools.c
View file @
19851f9e
...
@@ -17,6 +17,10 @@
...
@@ -17,6 +17,10 @@
Copyright Vitaly Valtman 2013
Copyright Vitaly Valtman 2013
*/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <assert.h>
#include <assert.h>
...
@@ -30,6 +34,8 @@
...
@@ -30,6 +34,8 @@
#include "tools.h"
#include "tools.h"
#ifdef DEBUG
#ifdef DEBUG
#define RES_PRE 8
#define RES_AFTER 8
#define MAX_BLOCKS 1000000
#define MAX_BLOCKS 1000000
void
*
blocks
[
MAX_BLOCKS
];
void
*
blocks
[
MAX_BLOCKS
];
void
*
free_blocks
[
MAX_BLOCKS
];
void
*
free_blocks
[
MAX_BLOCKS
];
...
@@ -37,18 +43,13 @@ int used_blocks;
...
@@ -37,18 +43,13 @@ int used_blocks;
int
free_blocks_cnt
;
int
free_blocks_cnt
;
#endif
#endif
#ifdef DEBUG
#define RES_PRE 8
#define RES_AFTER 8
#endif
extern
int
verbosity
;
extern
int
verbosity
;
long
long
total_allocated_bytes
;
long
long
total_allocated_bytes
;
static
void
out_of_memory
(
void
)
{
static
void
out_of_memory
(
void
)
{
logprintf
(
"Out of memory
\n
"
);
fprintf
(
stderr
,
"Out of memory
\n
"
);
assert
(
0
&&
"Out of memory"
);
exit
(
1
);
}
}
int
tsnprintf
(
char
*
buf
,
int
len
,
const
char
*
format
,
...)
{
int
tsnprintf
(
char
*
buf
,
int
len
,
const
char
*
format
,
...)
{
...
@@ -166,6 +167,23 @@ char *tstrdup (const char *s) {
...
@@ -166,6 +167,23 @@ char *tstrdup (const char *s) {
#endif
#endif
}
}
char
*
tstrndup
(
const
char
*
s
,
size_t
n
)
{
#ifdef DEBUG
size_t
l
=
0
;
for
(
l
=
0
;
l
<
n
&&
s
[
l
];
l
++
)
{
}
char
*
p
=
talloc
(
l
+
1
);
memcpy
(
p
,
s
,
l
);
p
[
l
]
=
0
;
return
p
;
#else
char
*
p
=
strndup
(
s
,
n
);
if
(
p
==
NULL
)
{
out_of_memory
();
}
return
p
;
#endif
}
void
ensure
(
int
r
)
{
void
ensure
(
int
r
)
{
if
(
!
r
)
{
if
(
!
r
)
{
logprintf
(
"Open SSL error
\n
"
);
logprintf
(
"Open SSL error
\n
"
);
...
...
tools.h
View file @
19851f9e
...
@@ -24,6 +24,7 @@ void *talloc (size_t size);
...
@@ -24,6 +24,7 @@ void *talloc (size_t size);
void
*
trealloc
(
void
*
ptr
,
size_t
old_size
,
size_t
size
);
void
*
trealloc
(
void
*
ptr
,
size_t
old_size
,
size_t
size
);
void
*
talloc0
(
size_t
size
);
void
*
talloc0
(
size_t
size
);
char
*
tstrdup
(
const
char
*
s
);
char
*
tstrdup
(
const
char
*
s
);
char
*
tstrndup
(
const
char
*
s
,
size_t
n
);
int
tinflate
(
void
*
input
,
int
ilen
,
void
*
output
,
int
olen
);
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