File atftp-CVE-2019-11366.patch of Package atftp.11043

Index: atftp-0.7/tftpd_list.c
===================================================================
--- atftp-0.7.orig/tftpd_list.c
+++ atftp-0.7/tftpd_list.c
@@ -49,10 +49,11 @@ pthread_mutex_t thread_list_mutex = PTHR
  */
 int tftpd_list_add(struct thread_data *new)
 {
+     pthread_mutex_lock(&thread_list_mutex);
+
      struct thread_data *current;
      int ret;
 
-     pthread_mutex_lock(&thread_list_mutex);
      current = thread_data;
      number_of_thread++;
      
@@ -81,11 +82,11 @@ int tftpd_list_add(struct thread_data *n
  */
 int tftpd_list_remove(struct thread_data *old)
 {
+     pthread_mutex_lock(&thread_list_mutex);
+
      struct thread_data *current;
      int ret;
 
-     pthread_mutex_lock(&thread_list_mutex);
-
      current = thread_data;
 
      number_of_thread--;
@@ -139,6 +140,9 @@ int tftpd_list_find_multicast_server_and
                                              struct thread_data *data,
                                              struct client_info *client)
 {
+     /* lock the whole list before walking it */
+     pthread_mutex_lock(&thread_list_mutex);
+
      struct thread_data *current; /* head of the list */
      struct tftp_opt *tftp_options;
      struct client_info *tmp;
@@ -147,9 +151,6 @@ int tftpd_list_find_multicast_server_and
      char *index;
      size_t len;
 
-     /* lock the whole list before walking it */
-     pthread_mutex_lock(&thread_list_mutex);
-
      *thread = NULL;
 
      current = thread_data;
@@ -220,9 +221,9 @@ inline void tftpd_clientlist_ready(struc
 void tftpd_clientlist_remove(struct thread_data *thread,
                              struct client_info *client)
 {
+     pthread_mutex_lock(&thread->client_mutex);
      struct client_info *tmp;
 
-     pthread_mutex_lock(&thread->client_mutex);
      tmp = thread->client_info;
      while ((tmp->next != client) && (tmp->next != NULL))
           tmp = tmp->next;
@@ -237,10 +238,11 @@ void tftpd_clientlist_remove(struct thre
  */
 void tftpd_clientlist_free(struct thread_data *thread)
 {
+     pthread_mutex_lock(&thread->client_mutex);
+
      struct client_info *tmp;
      struct client_info *head;
 
-     pthread_mutex_lock(&thread->client_mutex);
      head = thread->client_info;
 
      while (head)
@@ -259,9 +261,10 @@ int tftpd_clientlist_done(struct thread_
                           struct client_info *client,
                           struct sockaddr_in *sock)
 {
+     pthread_mutex_lock(&thread->client_mutex);
+
      struct client_info *head;
 
-     pthread_mutex_lock(&thread->client_mutex);
      head = thread->client_info;
 
      if (client)
@@ -344,9 +347,10 @@ int tftpd_clientlist_next(struct thread_
 
 void tftpd_list_kill_threads(void)
 {
+     pthread_mutex_lock(&thread_list_mutex);
+
      struct thread_data *current; /* head of list */
 
-     pthread_mutex_lock(&thread_list_mutex);
      current = thread_data;
 
      while (current != NULL)
openSUSE Build Service is sponsored by