]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
return error on fatal socket, not 0
authorAlan T. DeKok <aland@freeradius.org>
Fri, 31 Oct 2025 21:27:45 +0000 (17:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 1 Nov 2025 11:57:37 +0000 (07:57 -0400)
src/lib/io/network.c
src/listen/tacacs/proto_tacacs_tcp.c

index f7828609b9aac5a722c9ffb34561b1184d5986de..5372b26f226bd8eb85e66764b362403c4b54d224 100644 (file)
@@ -1183,10 +1183,9 @@ static void fr_network_write(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUS
                                          cd->m.data, cd->m.data_size, s->written);
 
                /*
-                *      As a special case, allow write() to return
-                *      "0", which means "close the socket".
+                *      Write of 0 bytes means an OS bug, and we just discard this packet.
                 */
-               if (rcode == 0) goto dead;
+               if (rcode == 0) goto discard;
 
                /*
                 *      Or we have a write error.
@@ -1232,7 +1231,7 @@ static void fr_network_write(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUS
                         *      signals to us that we have to close
                         *      the socket, but NOT complain about it.
                         */
-                       if (errno == ECONNREFUSED) goto dead;
+                       if ((errno == ECONNREFUSED) || (errno == ECONNRESET)) goto dead;
 
                        PERROR("Failed writing to socket %s", s->listen->name);
                        if (li->app_io->error) li->app_io->error(li);
@@ -1251,6 +1250,7 @@ static void fr_network_write(UNUSED fr_event_list_t *el, UNUSED int sockfd, UNUS
                        goto save_pending;
                }
 
+       discard:
                s->written = 0;
 
                /*
index 8009364e9d3ac35d6a9a1ea67f0dae96ca87b36c..4585c8f8847c6be49a28eb117730679b74bf78fa 100644 (file)
@@ -305,7 +305,8 @@ static ssize_t mod_write(fr_listen_t *li, UNUSED void *packet_ctx, UNUSED fr_tim
                        if (pkt->author_reply.status == FR_TAC_PLUS_AUTHOR_STATUS_ERROR) {
                        close_it:
                                DEBUG("Closing connection due to unrecoverable server error response");
-                               return 0;
+                               errno = ECONNRESET;
+                               return -1;
                        }
                        break;