grim/testing

Fix some issues scanbuild found in our dns handling code
release-2.x.y
2021-06-01, Gary Kramlich
5c79001c7e86
Parents f1ffe1b5a9d8
Children b6f7ee1f368a
Fix some issues scanbuild found in our dns handling code

Testing Done:
Verified scanbuild no longer detected the errors.

Reviewed at https://reviews.imfreedom.org/r/694/
--- a/libpurple/dnsquery.c Tue Jun 01 17:35:17 2021 -0500
+++ b/libpurple/dnsquery.c Tue Jun 01 17:36:18 2021 -0500
@@ -110,12 +110,17 @@
* Callback is a required parameter, but it can get set to
* NULL if we cancel a thread-based DNS lookup. So we need
* to free hosts.
+ *
+ * The host's list is pairs of file descriptors and sockaddr_in's.
*/
while (hosts != NULL)
{
+ gpointer data;
hosts = g_slist_remove(hosts, hosts->data);
- g_free(hosts->data);
+
+ data = hosts->data;
hosts = g_slist_remove(hosts, hosts->data);
+ g_free(data);
}
}
@@ -472,8 +477,7 @@
return NULL;
}
- resolver = g_new(PurpleDnsQueryResolverProcess, 1);
- resolver->inpa = 0;
+ resolver = g_new0(PurpleDnsQueryResolverProcess, 1);
cope_with_gdb_brokenness();
--- a/libpurple/dnssrv.c Tue Jun 01 17:35:17 2021 -0500
+++ b/libpurple/dnssrv.c Tue Jun 01 17:36:18 2021 -0500
@@ -160,11 +160,15 @@
r = runningtotal ? g_random_int_range(1, runningtotal + 1) : 0;
cur = list;
while (r > ((PurpleSrvResponseContainer *)cur->data)->sum) {
+ if(cur->next == NULL) {
+ break;
+ }
+
cur = cur->next;
}
/* Set the return parameter and remove cur from the list */
- *container_ptr = cur->data;
+ *container_ptr = cur->data;
return g_list_delete_link(list, cur);
}
@@ -198,9 +202,18 @@
cur = list;
while (container_list) {
container_list = select_random_response(container_list, &container);
+
+ if(container == NULL) {
+ break;
+ }
+
cur->data = container->response;
g_free(container);
cur = cur->next;
+
+ if(cur == NULL) {
+ break;
+ }
}
}
@@ -214,7 +227,7 @@
static GList *
purple_srv_sort(GList *list)
{
- int pref, count;
+ int count;
GList *cur, *start;
if (!list || !list->next) {
@@ -228,9 +241,14 @@
count = 1;
while (cur) {
PurpleSrvResponse *next_response;
- pref = ((PurpleSrvResponse *)cur->data)->pref;
+ PurpleSrvResponse *resp = (PurpleSrvResponse *)cur->data;
next_response = cur->next ? cur->next->data : NULL;
- if (!next_response || next_response->pref != pref) {
+
+ if(resp == NULL) {
+ continue;
+ }
+
+ if (!next_response || next_response->pref != resp->pref) {
/*
* The 'count' records starting at 'start' all have the same
* priority. Sort them by weight.
@@ -454,6 +472,8 @@
write_to_parent(in, out, &size, sizeof(size));
while (ret != NULL)
{
+ gpointer data;
+
if (query.type == T_SRV)
write_to_parent(in, out, ret->data, sizeof(PurpleSrvResponse));
if (query.type == T_TXT) {
@@ -463,8 +483,9 @@
write_to_parent(in, out, response->content, l);
}
- g_free(ret->data);
+ data = ret->data;
ret = g_list_remove(ret, ret->data);
+ g_free(data);
}
close(out);