diff options
| author | 2026-03-17 20:01:15 +0100 | |
|---|---|---|
| committer | 2026-03-17 20:01:15 +0100 | |
| commit | 275685d2eaded279d70212a960f732bf4cd9a1a6 (patch) | |
| tree | 42ff09af85866df81b96eb385d677db5778b8052 | |
| parent | Merge pull request 'Fixed buffer overflow read in `xs_evp_genkey()` when crea... (diff) | |
| parent | fix: more memory leaks (diff) | |
| download | snac2-275685d2eaded279d70212a960f732bf4cd9a1a6.tar.gz snac2-275685d2eaded279d70212a960f732bf4cd9a1a6.tar.xz snac2-275685d2eaded279d70212a960f732bf4cd9a1a6.zip | |
Merge pull request 'Fixed more memory leaks in new features' (#584) from dandelions/snac2:pr-leaks-1 into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/584
| -rw-r--r-- | activitypub.c | 18 | ||||
| -rw-r--r-- | html.c | 12 |
2 files changed, 21 insertions, 9 deletions
diff --git a/activitypub.c b/activitypub.c index 0535269..ed9acf9 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -645,12 +645,13 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) | |||
| 645 | 645 | ||
| 646 | while (xs_list_iter(&l, &v)) { | 646 | while (xs_list_iter(&l, &v)) { |
| 647 | if (expand_public) { | 647 | if (expand_public) { |
| 648 | xs *followers_url = xs_fmt("%s/followers", snac->actor); | ||
| 648 | if (strcmp(v, public_address) == 0 || | 649 | if (strcmp(v, public_address) == 0 || |
| 649 | /* check if it's a followers collection URL */ | 650 | /* check if it's a followers collection URL */ |
| 650 | (xs_type(v) == XSTYPE_STRING && | 651 | (xs_type(v) == XSTYPE_STRING && |
| 651 | strcmp(v, xs_fmt("%s/followers", snac->actor)) == 0) || | 652 | strcmp(v, followers_url) == 0) || |
| 652 | (xs_type(v) == XSTYPE_LIST && | 653 | (xs_type(v) == XSTYPE_LIST && |
| 653 | xs_list_in(v, xs_fmt("%s/followers", snac->actor)) != -1)) { | 654 | xs_list_in(v, followers_url) != -1)) { |
| 654 | /* iterate the followers and add them */ | 655 | /* iterate the followers and add them */ |
| 655 | xs *fwers = follower_list(snac); | 656 | xs *fwers = follower_list(snac); |
| 656 | const char *actor; | 657 | const char *actor; |
| @@ -1624,6 +1625,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o) | |||
| 1624 | else if (*eid == '%') { | 1625 | else if (*eid == '%') { |
| 1625 | content = xs_url_dec_emoji(xs_dup(eid)); | 1626 | content = xs_url_dec_emoji(xs_dup(eid)); |
| 1626 | if (content == NULL) { | 1627 | if (content == NULL) { |
| 1628 | xs_free(n_msg); | ||
| 1627 | return NULL; | 1629 | return NULL; |
| 1628 | } | 1630 | } |
| 1629 | } | 1631 | } |
| @@ -1631,8 +1633,10 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o) | |||
| 1631 | content = xs_fmt(":%s:", eid); | 1633 | content = xs_fmt(":%s:", eid); |
| 1632 | const char *emo = xs_dict_get(emjs, content); | 1634 | const char *emo = xs_dict_get(emjs, content); |
| 1633 | 1635 | ||
| 1634 | if (emo == NULL) | 1636 | if (emo == NULL) { |
| 1637 | xs_free(n_msg); | ||
| 1635 | return NULL; | 1638 | return NULL; |
| 1639 | } | ||
| 1636 | 1640 | ||
| 1637 | if (xs_match(emo, "https://*|http://*")) { /* emoji is an URL to an image */ | 1641 | if (xs_match(emo, "https://*|http://*")) { /* emoji is an URL to an image */ |
| 1638 | icon = xs_dict_set(icon, "type", "Image"); | 1642 | icon = xs_dict_set(icon, "type", "Image"); |
| @@ -1667,9 +1671,10 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o) | |||
| 1667 | 1671 | ||
| 1668 | accounts = xs_list_append(accounts, snac->actor); | 1672 | accounts = xs_list_append(accounts, snac->actor); |
| 1669 | 1673 | ||
| 1674 | xs *to_duplicate = xs_dup(xs_list_get(xs_dict_get(n_msg, "to"), 1)); | ||
| 1670 | n_msg = xs_dict_set(n_msg, "content", content); | 1675 | n_msg = xs_dict_set(n_msg, "content", content); |
| 1671 | n_msg = xs_dict_set(n_msg, "accounts", accounts); | 1676 | n_msg = xs_dict_set(n_msg, "accounts", accounts); |
| 1672 | n_msg = xs_dict_set(n_msg, "attributedTo", xs_list_get(xs_dict_get(n_msg, "to"), 1)); | 1677 | n_msg = xs_dict_set(n_msg, "attributedTo", to_duplicate); |
| 1673 | n_msg = xs_dict_set(n_msg, "accountId", snac->uid); | 1678 | n_msg = xs_dict_set(n_msg, "accountId", snac->uid); |
| 1674 | n_msg = xs_dict_set(n_msg, "tag", tag); | 1679 | n_msg = xs_dict_set(n_msg, "tag", tag); |
| 1675 | 1680 | ||
| @@ -1679,6 +1684,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o) | |||
| 1679 | return n_msg; | 1684 | return n_msg; |
| 1680 | } | 1685 | } |
| 1681 | 1686 | ||
| 1687 | xs_free(n_msg); | ||
| 1682 | return NULL; | 1688 | return NULL; |
| 1683 | } | 1689 | } |
| 1684 | 1690 | ||
| @@ -1710,13 +1716,14 @@ xs_dict *msg_emoji_unreact(snac *user, const char *mid, const char *eid) | |||
| 1710 | if (strlen(eid) == 12 && *eid == '%') { | 1716 | if (strlen(eid) == 12 && *eid == '%') { |
| 1711 | eid = xs_url_dec(eid); | 1717 | eid = xs_url_dec(eid); |
| 1712 | if (eid == NULL) { | 1718 | if (eid == NULL) { |
| 1719 | xs_free(msg); | ||
| 1713 | return NULL; | 1720 | return NULL; |
| 1714 | } | 1721 | } |
| 1715 | } | 1722 | } |
| 1716 | 1723 | ||
| 1717 | /* lets get all emotes for this msg, and compare it to our content */ | 1724 | /* lets get all emotes for this msg, and compare it to our content */ |
| 1718 | while (xs_list_next(emotes, &v, &c)) { | 1725 | while (xs_list_next(emotes, &v, &c)) { |
| 1719 | xs_dict *e = NULL; | 1726 | xs *e = NULL; |
| 1720 | if (valid_status(object_get_by_md5(v, &e))) { | 1727 | if (valid_status(object_get_by_md5(v, &e))) { |
| 1721 | const char *content = xs_dict_get(e, "content"); | 1728 | const char *content = xs_dict_get(e, "content"); |
| 1722 | const char *id = xs_dict_get(e, "id"); | 1729 | const char *id = xs_dict_get(e, "id"); |
| @@ -1730,6 +1737,7 @@ xs_dict *msg_emoji_unreact(snac *user, const char *mid, const char *eid) | |||
| 1730 | } | 1737 | } |
| 1731 | } | 1738 | } |
| 1732 | 1739 | ||
| 1740 | xs_free(msg); | ||
| 1733 | return NULL; | 1741 | return NULL; |
| 1734 | } | 1742 | } |
| 1735 | 1743 | ||
| @@ -4112,7 +4112,7 @@ void notify_filter(snac *user, const xs_dict *p_vars) | |||
| 4112 | int folreq_on = (v = xs_dict_get(p_vars, "folreqs_on")) ? strcmp(v, "on") == 0 : 0; | 4112 | int folreq_on = (v = xs_dict_get(p_vars, "folreqs_on")) ? strcmp(v, "on") == 0 : 0; |
| 4113 | int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0; | 4113 | int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0; |
| 4114 | int polls_on = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0; | 4114 | int polls_on = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0; |
| 4115 | xs_dict *filter = xs_dict_new(); | 4115 | xs *filter = xs_dict_new(); |
| 4116 | filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE)); | 4116 | filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| 4117 | filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE)); | 4117 | filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| 4118 | filter = xs_dict_set(filter, "mentions", xs_stock(ments_on ? XSTYPE_TRUE : XSTYPE_FALSE)); | 4118 | filter = xs_dict_set(filter, "mentions", xs_stock(ments_on ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| @@ -4123,6 +4123,7 @@ void notify_filter(snac *user, const xs_dict *p_vars) | |||
| 4123 | filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE)); | 4123 | filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| 4124 | filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE)); | 4124 | filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| 4125 | user->config = xs_dict_set(user->config, "notify_filter", filter); | 4125 | user->config = xs_dict_set(user->config, "notify_filter", filter); |
| 4126 | user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz | ||
| 4126 | } | 4127 | } |
| 4127 | 4128 | ||
| 4128 | xs_str *html_notifications(snac *user, int skip, int show) | 4129 | xs_str *html_notifications(snac *user, int skip, int show) |
| @@ -4138,7 +4139,9 @@ xs_str *html_notifications(snac *user, int skip, int show) | |||
| 4138 | xs_html *body = html_user_body(user, 0); | 4139 | xs_html *body = html_user_body(user, 0); |
| 4139 | const xs_dict *n_filter = xs_dict_get(user->config, "notify_filter"); | 4140 | const xs_dict *n_filter = xs_dict_get(user->config, "notify_filter"); |
| 4140 | if (!n_filter) { | 4141 | if (!n_filter) { |
| 4141 | user->config = xs_dict_set(user->config, "notify_filter", xs_dict_new()); | 4142 | xs *filter = xs_dict_new(); |
| 4143 | user->config = xs_dict_set(user->config, "notify_filter", filter); | ||
| 4144 | user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz | ||
| 4142 | n_filter = xs_dict_get(user->config, "notify_filter"); | 4145 | n_filter = xs_dict_get(user->config, "notify_filter"); |
| 4143 | } | 4146 | } |
| 4144 | xs *n_list = notify_filter_list(user, n_list_unfilt); | 4147 | xs *n_list = notify_filter_list(user, n_list_unfilt); |
| @@ -4159,6 +4162,7 @@ xs_str *html_notifications(snac *user, int skip, int show) | |||
| 4159 | body); | 4162 | body); |
| 4160 | 4163 | ||
| 4161 | xs *filter_notifs_action = xs_fmt("%s/admin/filter-notifications", user->actor); | 4164 | xs *filter_notifs_action = xs_fmt("%s/admin/filter-notifications", user->actor); |
| 4165 | xs *notifs_action = xs_fmt("%s/notifications", user->actor); | ||
| 4162 | xs_html *notifs_form = xs_html_tag("form", | 4166 | xs_html *notifs_form = xs_html_tag("form", |
| 4163 | xs_html_attr("autocomplete", "off"), | 4167 | xs_html_attr("autocomplete", "off"), |
| 4164 | xs_html_attr("method", "post"), | 4168 | xs_html_attr("method", "post"), |
| @@ -4168,7 +4172,7 @@ xs_str *html_notifications(snac *user, int skip, int show) | |||
| 4168 | xs_html_sctag("input", | 4172 | xs_html_sctag("input", |
| 4169 | xs_html_attr("type", "hidden"), | 4173 | xs_html_attr("type", "hidden"), |
| 4170 | xs_html_attr("name", "hard-redir"), | 4174 | xs_html_attr("name", "hard-redir"), |
| 4171 | xs_html_attr("value", xs_fmt("%s/notifications", user->actor))), | 4175 | xs_html_attr("value", notifs_action)), |
| 4172 | html_checkbox("likes_on", L("Likes"), n_likes_on), | 4176 | html_checkbox("likes_on", L("Likes"), n_likes_on), |
| 4173 | html_checkbox("reacts_on", L("Emoji reacts"), n_reacts_on), | 4177 | html_checkbox("reacts_on", L("Emoji reacts"), n_reacts_on), |
| 4174 | html_checkbox("mentions_on", L("Mentions"), n_ments_on), | 4178 | html_checkbox("mentions_on", L("Mentions"), n_ments_on), |
| @@ -5569,7 +5573,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 5569 | 5573 | ||
| 5570 | eid = xs_strip_chars_i(eid, ":"); | 5574 | eid = xs_strip_chars_i(eid, ":"); |
| 5571 | 5575 | ||
| 5572 | const xs_dict *ret = msg_emoji_init(&snac, id, eid); | 5576 | xs *ret = msg_emoji_init(&snac, id, eid); |
| 5573 | /* fails if either invalid or already reacted */ | 5577 | /* fails if either invalid or already reacted */ |
| 5574 | if (!ret) | 5578 | if (!ret) |
| 5575 | ret = msg_emoji_unreact(&snac, id, eid); | 5579 | ret = msg_emoji_unreact(&snac, id, eid); |