Dear Quagga Developers,

We found a bug in bgpd which causes file descriptor leaks each time
when configuration is updated and then saved on disk. The reason is
that output file descriptor vty->wfd is not closed in vty_close
function.

This bug is very easy to reproduce. You need to
1) check a number of opened FDs (using lsof or /proc/<pid>/fd)
2) perform any update to the configuration
3) execute "write" command in "configure terminal"
4) check a number of opened FDs again

You can find a sample script (check.sh) in attachment that automates
the steps above. An example of its output:
 % sudo sh check.sh $(pgrep -f ./bgpd/.libs/bgpd) localhost 2605
<telnet password>
Open FDs: 10
altering config...
Open FDs: 11
altering config 10 times...
Open FDs: 21

A simple patch that fixes the problem above is also attached.

--
| Evgeny Uskov  | HLL l QRATOR
| mob.: +7 916 319 33 20
| skype: evgeny_uskov
| mailto: [email protected]
| visit: www.qrator.net
From f41b8d379ef7dcc131f531f33acabf03e665bbef Mon Sep 17 00:00:00 2001
From: Evgeny Uskov <[email protected]>
Date: Fri, 24 Nov 2017 16:03:32 +0300
Subject: [PATCH] bgpd: fix file descriptor leaks in vty_close

In vty_close output file descriptor was not properly closed. It caused
file descriptor leak each time an updated config file was saved on disk.
---
 lib/vty.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/vty.c b/lib/vty.c
index 7ca8354..4158fb1 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2365,6 +2365,10 @@ vty_close (struct vty *vty)
   else
     vty_stdio_reset ();
 
+  /* Close output fd (except stdout/stderr) */
+  if (vty->wfd > 2)
+    close (vty->wfd);
+
   if (vty->buf)
     XFREE (MTYPE_VTY, vty->buf);
 
-- 
2.9.3

Attachment: check.sh
Description: Bourne shell script

_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to