We use default sndbuf (INT_MAX) if user assigns an invalid sndbuf.
This patch just added an error note.

Signed-off-by: Amos Kong <ak...@redhat.com>
---
 net/tap-linux.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/net/tap-linux.c b/net/tap-linux.c
index 812bf2d..fc0cc0d 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -130,9 +130,16 @@ int tap_set_sndbuf(int fd, const NetdevTapOptions *tap)
 {
     int sndbuf;
 
-    sndbuf = !tap->has_sndbuf       ? TAP_DEFAULT_SNDBUF :
-             tap->sndbuf > INT_MAX  ? INT_MAX :
-             tap->sndbuf;
+    if (!tap->has_sndbuf) {
+        sndbuf = TAP_DEFAULT_SNDBUF;
+    } else if (tap->sndbuf > INT_MAX) {
+        sndbuf = TAP_DEFAULT_SNDBUF;
+        error_report("given sndbuf isn't an integer, "
+                     "or it's larger than INT_MAX(%d). "
+                     "use default sndbuf(%d)", INT_MAX, INT_MAX);
+    } else {
+        sndbuf = tap->sndbuf;
+    }
 
     if (!sndbuf) {
         sndbuf = INT_MAX;
-- 
1.9.0


Reply via email to