vcl: fix ldp_set_app_name overflow 39/21439/1
authorBenoît Ganne <bganne@cisco.com>
Wed, 21 Aug 2019 16:27:23 +0000 (18:27 +0200)
committerBenoît Ganne <bganne@cisco.com>
Wed, 21 Aug 2019 16:30:57 +0000 (18:30 +0200)
In case of overflow, we null-terminate the parameter ('app_name')
instead of ldp global name ('ldp->app_name').
Moreover, snprintf() always safely null-terminate the destination string
even in case of overflow.

Type: fix
Fixes: 048b1d6ab7

Change-Id: I4d8b0e020a228e982b6699d652b341c5afe92993
Signed-off-by: Benoît Ganne <bganne@cisco.com>
src/vcl/ldp.c

index 70a4299..7aa3830 100644 (file)
@@ -132,11 +132,8 @@ ldp_worker_get_current (void)
 static inline void
 ldp_set_app_name (char *app_name)
 {
-  int rv = snprintf (ldp->app_name, LDP_APP_NAME_MAX,
-                    "ldp-%d-%s", getpid (), app_name);
-
-  if (rv >= LDP_APP_NAME_MAX)
-    app_name[LDP_APP_NAME_MAX - 1] = 0;
+  snprintf (ldp->app_name, LDP_APP_NAME_MAX,
+           "ldp-%d-%s", getpid (), app_name);
 }
 
 static inline char *