mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 23:23:02 +01:00
A few small fixes
- Fix race condition in draw_peer() - Handle realloc_peer_list() error - Remove dead code in cmd_conference() - Reduce scope of a few variable variables - Fix possible buffer truncation in api.c
This commit is contained in:
parent
0554bf0240
commit
312b38d253
22
src/api.c
22
src/api.c
@ -175,36 +175,36 @@ void cmd_run(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
|||||||
|
|
||||||
void invoke_autoruns(WINDOW *window, ToxWindow *self)
|
void invoke_autoruns(WINDOW *window, ToxWindow *self)
|
||||||
{
|
{
|
||||||
struct dirent *dir;
|
char abspath_buf[PATH_MAX + 256];
|
||||||
char abspath_buf[PATH_MAX + 1], err_buf[PATH_MAX + 1];
|
char err_buf[PATH_MAX + 128];
|
||||||
size_t path_len;
|
|
||||||
DIR *d;
|
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if (user_settings->autorun_path[0] == '\0') {
|
if (user_settings->autorun_path[0] == '\0') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d = opendir(user_settings->autorun_path);
|
DIR *d = opendir(user_settings->autorun_path);
|
||||||
|
|
||||||
if (d == NULL) {
|
if (d == NULL) {
|
||||||
snprintf(err_buf, PATH_MAX + 1, "Autorun path does not exist: %s", user_settings->autorun_path);
|
snprintf(err_buf, sizeof(err_buf), "Autorun path does not exist: %s", user_settings->autorun_path);
|
||||||
api_display(err_buf);
|
api_display(err_buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct dirent *dir = NULL;
|
||||||
|
|
||||||
cur_window = window;
|
cur_window = window;
|
||||||
|
|
||||||
self_window = self;
|
self_window = self;
|
||||||
|
|
||||||
while ((dir = readdir(d)) != NULL) {
|
while ((dir = readdir(d)) != NULL) {
|
||||||
path_len = strlen(dir->d_name);
|
size_t path_len = strlen(dir->d_name);
|
||||||
|
|
||||||
if (!strcmp(dir->d_name + path_len - 3, ".py")) {
|
if (!strcmp(dir->d_name + path_len - 3, ".py")) {
|
||||||
snprintf(abspath_buf, PATH_MAX + 1, "%s%s", user_settings->autorun_path, dir->d_name);
|
snprintf(abspath_buf, sizeof(abspath_buf), "%s%s", user_settings->autorun_path, dir->d_name);
|
||||||
fp = fopen(abspath_buf, "r");
|
FILE *fp = fopen(abspath_buf, "r");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
snprintf(err_buf, PATH_MAX + 1, "Invalid path: %s", abspath_buf);
|
snprintf(err_buf, sizeof(err_buf), "Invalid path: %s", abspath_buf);
|
||||||
api_display(err_buf);
|
api_display(err_buf);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -916,7 +916,7 @@ void stop_current_call(ToxWindow *self)
|
|||||||
*/
|
*/
|
||||||
static void realloc_calls(uint32_t n)
|
static void realloc_calls(uint32_t n)
|
||||||
{
|
{
|
||||||
if (n <= 0) {
|
if (n == 0) {
|
||||||
free(CallControl.calls);
|
free(CallControl.calls);
|
||||||
CallControl.calls = NULL;
|
CallControl.calls = NULL;
|
||||||
return;
|
return;
|
||||||
|
@ -504,8 +504,6 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char msg[MAX_STR_SIZE];
|
|
||||||
|
|
||||||
switch (control) {
|
switch (control) {
|
||||||
case TOX_FILE_CONTROL_RESUME: {
|
case TOX_FILE_CONTROL_RESUME: {
|
||||||
/* transfer is accepted */
|
/* transfer is accepted */
|
||||||
@ -531,6 +529,7 @@ static void chat_onFileControl(ToxWindow *self, Tox *m, uint32_t friendnum, uint
|
|||||||
}
|
}
|
||||||
|
|
||||||
case TOX_FILE_CONTROL_CANCEL: {
|
case TOX_FILE_CONTROL_CANCEL: {
|
||||||
|
char msg[MAX_STR_SIZE];
|
||||||
snprintf(msg, sizeof(msg), "File transfer for '%s' was aborted.", ft->file_name);
|
snprintf(msg, sizeof(msg), "File transfer for '%s' was aborted.", ft->file_name);
|
||||||
close_file_transfer(self, m, ft, -1, msg, notif_error);
|
close_file_transfer(self, m, ft, -1, msg, notif_error);
|
||||||
break;
|
break;
|
||||||
|
@ -160,7 +160,7 @@ static void init_conference_logging(ToxWindow *self, Tox *m, uint32_t conference
|
|||||||
char conference_id[TOX_CONFERENCE_ID_SIZE];
|
char conference_id[TOX_CONFERENCE_ID_SIZE];
|
||||||
tox_conference_get_id(m, conferencenum, (uint8_t *) conference_id);
|
tox_conference_get_id(m, conferencenum, (uint8_t *) conference_id);
|
||||||
|
|
||||||
if (log_init(ctx->log, conferences[conferencenum].title, my_id, conference_id, LOG_TYPE_CHAT) != 0) {
|
if (log_init(ctx->log, conferences[self->num].title, my_id, conference_id, LOG_TYPE_CHAT) != 0) {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -656,7 +656,11 @@ static void update_peer_list(Tox *m, uint32_t conferencenum, uint32_t num_peers,
|
|||||||
memcpy(old_peer_list, chat->peer_list, old_num_peers * sizeof(ConferencePeer));
|
memcpy(old_peer_list, chat->peer_list, old_num_peers * sizeof(ConferencePeer));
|
||||||
}
|
}
|
||||||
|
|
||||||
realloc_peer_list(chat, num_peers);
|
if (realloc_peer_list(chat, num_peers) != 0) {
|
||||||
|
free(old_peer_list);
|
||||||
|
fprintf(stderr, "Warning: realloc_peer_list() failed in update_peer_list()\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint32_t i = 0; i < num_peers; ++i) {
|
for (uint32_t i = 0; i < num_peers; ++i) {
|
||||||
ConferencePeer *peer = &chat->peer_list[i];
|
ConferencePeer *peer = &chat->peer_list[i];
|
||||||
@ -971,15 +975,9 @@ static void draw_peer(ToxWindow *self, Tox *m, ChatContext *ctx, uint32_t i)
|
|||||||
const uint32_t peernum = conferences[self->num].name_list[peer_idx].peernum;
|
const uint32_t peernum = conferences[self->num].name_list[peer_idx].peernum;
|
||||||
const bool is_self = tox_conference_peer_number_is_ours(m, self->num, peernum, NULL);
|
const bool is_self = tox_conference_peer_number_is_ours(m, self->num, peernum, NULL);
|
||||||
const bool audio = conferences[self->num].audio_enabled;
|
const bool audio = conferences[self->num].audio_enabled;
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
|
||||||
|
|
||||||
/* truncate nick to fit in side panel without modifying list */
|
|
||||||
char tmpnick[TOX_MAX_NAME_LENGTH];
|
|
||||||
int maxlen = SIDEBAR_WIDTH - 2 - 2 * audio;
|
|
||||||
|
|
||||||
if (audio) {
|
if (audio) {
|
||||||
#ifdef AUDIO
|
#ifdef AUDIO
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
|
||||||
const ConferencePeer *peer = peer_in_conference(self->num, peernum);
|
const ConferencePeer *peer = peer_in_conference(self->num, peernum);
|
||||||
const bool audio_active = is_self
|
const bool audio_active = is_self
|
||||||
? !timed_out(conferences[self->num].last_sent_audio, 2)
|
? !timed_out(conferences[self->num].last_sent_audio, 2)
|
||||||
@ -996,8 +994,14 @@ static void draw_peer(ToxWindow *self, Tox *m, ChatContext *ctx, uint32_t i)
|
|||||||
wattroff(ctx->sidebar, aud_attr);
|
wattroff(ctx->sidebar, aud_attr);
|
||||||
waddch(ctx->sidebar, ' ');
|
waddch(ctx->sidebar, ' ');
|
||||||
#endif
|
#endif
|
||||||
|
} else {
|
||||||
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* truncate nick to fit in side panel without modifying list */
|
||||||
|
char tmpnick[TOX_MAX_NAME_LENGTH];
|
||||||
|
int maxlen = SIDEBAR_WIDTH - 2 - 2 * audio;
|
||||||
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
memcpy(tmpnick, &conferences[self->num].name_list[peer_idx].name, maxlen);
|
memcpy(tmpnick, &conferences[self->num].name_list[peer_idx].name, maxlen);
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
|
@ -807,7 +807,7 @@ static void delete_blocked_friend(uint32_t bnum)
|
|||||||
/* deletes contact from friendlist and puts in blocklist */
|
/* deletes contact from friendlist and puts in blocklist */
|
||||||
void block_friend(Tox *m, uint32_t fnum)
|
void block_friend(Tox *m, uint32_t fnum)
|
||||||
{
|
{
|
||||||
if (Friends.num_friends <= 0) {
|
if (Friends.num_friends == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,9 +389,6 @@ void cmd_conference(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
|
|||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio support disabled by compile-time option.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio support disabled by compile-time option.");
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Unknown conference type %d", type);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_conference_win(m, conferencenum, type, NULL, 0) == -1) {
|
if (init_conference_win(m, conferencenum, type, NULL, 0) == -1) {
|
||||||
|
@ -368,10 +368,10 @@ int rename_logfile(const char *src, const char *dest, const char *selfkey, const
|
|||||||
if (rename(newpath, new_backup) != 0) {
|
if (rename(newpath, new_backup) != 0) {
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (rename(oldpath, newpath) != 0) {
|
|
||||||
goto on_error;
|
if (rename(oldpath, newpath) != 0) {
|
||||||
}
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log != NULL) {
|
if (log != NULL) {
|
||||||
|
@ -114,25 +114,23 @@ static PyObject *python_api_get_status_message(PyObject *self, PyObject *args)
|
|||||||
|
|
||||||
static PyObject *python_api_get_all_friends(PyObject *self, PyObject *args)
|
static PyObject *python_api_get_all_friends(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
size_t i, ii;
|
|
||||||
FriendsList friends;
|
FriendsList friends;
|
||||||
PyObject *cur, *ret;
|
char pubkey_buf[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
||||||
char pubkey_buf[TOX_PUBLIC_KEY_SIZE * 2 + 1];
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "")) {
|
if (!PyArg_ParseTuple(args, "")) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
friends = api_get_friendslist();
|
friends = api_get_friendslist();
|
||||||
ret = PyList_New(0);
|
PyObject *ret = PyList_New(0);
|
||||||
|
|
||||||
for (i = 0; i < friends.num_friends; i++) {
|
for (size_t i = 0; i < friends.num_friends; i++) {
|
||||||
for (ii = 0; ii < TOX_PUBLIC_KEY_SIZE; ii++) {
|
for (size_t ii = 0; ii < TOX_PUBLIC_KEY_SIZE; ii++) {
|
||||||
snprintf(pubkey_buf + ii * 2, 3, "%02X", friends.list[i].pub_key[ii] & 0xff);
|
snprintf(pubkey_buf + ii * 2, 3, "%02X", friends.list[i].pub_key[ii] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
pubkey_buf[TOX_PUBLIC_KEY_SIZE * 2] = '\0';
|
pubkey_buf[TOX_PUBLIC_KEY_SIZE * 2] = '\0';
|
||||||
cur = Py_BuildValue("(s,s)", friends.list[i].name, pubkey_buf);
|
PyObject *cur = Py_BuildValue("(s,s)", friends.list[i].name, pubkey_buf);
|
||||||
PyList_Append(ret, cur);
|
PyList_Append(ret, cur);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,14 +262,14 @@ PyMODINIT_FUNC PyInit_toxic_api(void)
|
|||||||
|
|
||||||
void terminate_python(void)
|
void terminate_python(void)
|
||||||
{
|
{
|
||||||
struct python_registered_func *cur, *old;
|
|
||||||
|
|
||||||
if (python_commands.name != NULL) {
|
if (python_commands.name != NULL) {
|
||||||
free(python_commands.name);
|
free(python_commands.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct python_registered_func *cur = NULL;
|
||||||
|
|
||||||
for (cur = python_commands.next; cur != NULL;) {
|
for (cur = python_commands.next; cur != NULL;) {
|
||||||
old = cur;
|
struct python_registered_func *old = cur;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
free(old->name);
|
free(old->name);
|
||||||
free(old);
|
free(old);
|
||||||
|
@ -235,11 +235,12 @@ void *event_loop(void *p)
|
|||||||
UNUSED_VAR(p); /* DINDUNOTHIN */
|
UNUSED_VAR(p); /* DINDUNOTHIN */
|
||||||
|
|
||||||
XEvent event;
|
XEvent event;
|
||||||
int pending;
|
|
||||||
|
|
||||||
while (Xtra.display) {
|
while (Xtra.display) {
|
||||||
/* NEEDMOEVENTSFODEMPROGRAMS */
|
/* NEEDMOEVENTSFODEMPROGRAMS */
|
||||||
|
|
||||||
|
int pending = 0;
|
||||||
|
|
||||||
XLockDisplay(Xtra.display);
|
XLockDisplay(Xtra.display);
|
||||||
|
|
||||||
if ((pending = XPending(Xtra.display))) {
|
if ((pending = XPending(Xtra.display))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user