jids - memory integrity

master
bqv 2 years ago
parent 065ebac3c3
commit 30a7f9eeff
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -587,6 +587,7 @@ void account__free(struct t_account *account)
account__free_data(account);
delete account;
account = nullptr;
accounts = new_accounts;
}
@ -692,12 +693,12 @@ struct t_gui_buffer *account__create_buffer(struct t_account *account)
&buffer__close_cb, NULL, NULL);
if (!account->buffer)
return NULL;
weechat_printf(account->buffer, "xmpp: %s", account->name);
if (!weechat_buffer_get_integer(account->buffer, "short_name_is_set"))
weechat_buffer_set(account->buffer, "short_name", account->name);
weechat_buffer_set(account->buffer, "localvar_set_type", "server");
weechat_buffer_set(account->buffer, "localvar_set_server", account->name);
weechat_buffer_set(account->buffer, "localvar_set_channel", account->name);
weechat_buffer_set(account->buffer, "localvar_set_account", account->name);
snprintf(charset_modifier, sizeof (charset_modifier),
"account.%s", account->name);
weechat_buffer_set(account->buffer, "localvar_set_charset_modifier",

@ -117,9 +117,11 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
xmpp_stanza_release(children[0]);
}
channel = channel__search(account, std::string(binding.from->bare).data());
channel = channel__search(account, binding.from->bare.data());
if (!(binding.type && *binding.type == "unavailable") && !binding.muc_user() && !channel)
channel = channel__new(account, CHANNEL_TYPE_PM, std::string(binding.from->bare).data(), std::string(binding.from->bare).data());
{
channel = channel__new(account, CHANNEL_TYPE_PM, binding.from->bare.data(), binding.from->bare.data());
}
if (auto x = binding.muc_user())
{
@ -185,12 +187,12 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
std::string affiliation(item.affiliation ? xep0045::format_affiliation(*item.affiliation) : "");
std::string jid = item.target ? item.target->full : clientid;
user = user__search(account, std::string(binding.from->full).data());
user = user__search(account, binding.from->full.data());
if (!user)
user = user__new(account, std::string(binding.from->full).data(),
channel && std::string(binding.from->bare).data() == channel->id
? (binding.from->resource.size() ? std::string(binding.from->resource).data() : "")
: std::string(binding.from->full).data());
user = user__new(account, binding.from->full.data(),
channel && binding.from->bare.data() == channel->id
? (binding.from->resource.size() ? binding.from->resource.data() : "")
: binding.from->full.data());
auto status = binding.status();
auto show = binding.show();
auto idle = binding.idle_since();
@ -211,20 +213,20 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
}
if (weechat_strcasecmp(role.data(), "none") == 0)
channel__remove_member(account, channel, std::string(binding.from->full).data(), status ? status->data() : nullptr);
channel__remove_member(account, channel, binding.from->full.data(), status ? status->data() : nullptr);
else
channel__add_member(account, channel, std::string(binding.from->full).data(), jid.data());
channel__add_member(account, channel, binding.from->full.data(), jid.data());
}
}
}
else
{
user = user__search(account, std::string(binding.from->full).data());
user = user__search(account, binding.from->full.data());
if (!user)
user = user__new(account, std::string(binding.from->full).data(),
channel && std::string(binding.from->bare).data() == channel->id
? (binding.from->resource.size() ? std::string(binding.from->resource).data() : "")
: std::string(binding.from->full).data());
user = user__new(account, binding.from->full.data(),
channel && binding.from->bare.data() == channel->id
? (binding.from->resource.size() ? binding.from->resource.data() : "")
: binding.from->full.data());
auto status = binding.status();
auto show = binding.show();
auto idle = binding.idle_since();
@ -244,9 +246,9 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
}
if (user->profile.role)
channel__remove_member(account, channel, std::string(binding.from->full).data(), status ? status->data() : nullptr);
channel__remove_member(account, channel, binding.from->full.data(), status ? status->data() : nullptr);
else
channel__add_member(account, channel, std::string(binding.from->full).data(), clientid.data());
channel__add_member(account, channel, binding.from->full.data(), clientid.data());
}
}

@ -94,6 +94,8 @@ weechat-xmpp: $(DEPS) xmpp.so
xmpp.so: $(OBJS) $(DEPS) $(HDRS)
$(CXX) $(LDFLAGS) -o $@ $(OBJS) $(DEPS) $(LDLIBS)
git ls-files | xargs tar c | objcopy --add-section .source=/dev/stdin xmpp.so
#objcopy --dump-section .source=/dev/stdout xmpp.so | tar t
.%.o: %.c
$(eval GIT_REF=$(shell git describe --abbrev=6 --always --dirty 2>/dev/null || true))
@ -138,7 +140,7 @@ coverage: tests/run
debug: xmpp.so
env LD_PRELOAD=$(DEBUG) gdb -ex "handle SIGPIPE nostop noprint pass" --args \
weechat -a -P 'alias,buflist,exec,irc' -r '/plugin load ./xmpp.so'
weechat -a -P 'alias,buflist,exec,irc,relay' -r '/plugin load ./xmpp.so'
depend: $(SRCS) $(HDRS)
$(RM) -f ./.depend

@ -1,4 +1,4 @@
// This Source Code Form is subject to the terms of the Mozilla PublicAA
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

@ -49,15 +49,16 @@ const std::regex jid::pattern(
"^((?:([^@/<>'\"]+)@)?([^@/<>'\"]+))(?:/([^<>'\"]*))?$");
jid::jid(xmpp_ctx_t *, std::string s) : full(s) {
auto as_sv = [](std::ssub_match m) {
if(!m.matched) return std::string_view();
return std::string_view { &*m.first, static_cast<size_t>(m.length()) };
};
std::smatch match;
if (std::regex_search(full, match, pattern))
{
auto as_sv = [&](std::ssub_match m) {
if(!m.matched) return std::string_view();
size_t offset = &*m.first - &*match[0].first;
return std::string_view{full.data() + offset, static_cast<size_t>(m.length())};
};
bare = as_sv(match[1]);
local = as_sv(match[2]);
domain = as_sv(match[3]);

@ -34,10 +34,11 @@ public:
operator std::string&() { return full; }
std::string full;
std::string_view bare;
std::string_view local;
std::string_view domain;
std::string_view resource;
std::string bare;
std::string local;
std::string domain;
std::string resource;
bool is_bare() const;
};

Loading…
Cancel
Save