Ivan Oleynikov
2016-07-01 10:43:43 UTC
This is simply icquired by using `realpath(3)` of value passed with -p
parameter instead of its original value.
Signed-off-by: Ivan Oleynikov <***@metrotek.spb.ru>
---
ptp4l.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/ptp4l.c b/ptp4l.c
index a87e7e6..090b75a 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
#include "clock.h"
#include "config.h"
@@ -72,7 +74,8 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
- char *config = NULL, *req_phc = NULL, *progname;
+ char req_phc[PATH_MAX];
+ char *config = NULL, *progname;
int c, err = -1, print_level;
struct clock *clock = NULL;
struct config *cfg;
@@ -137,7 +140,11 @@ int main(int argc, char *argv[])
goto out;
break;
case 'p':
- req_phc = optarg;
+ if (!realpath(optarg, req_phc)) {
+ pr_err("realpath(%s): %s", optarg, strerror(errno));
+ goto out;
+ }
+ pr_debug("using %s as realpath of %s", req_phc, optarg);
break;
case 's':
if (config_set_int(cfg, "slaveOnly", 1)) {
parameter instead of its original value.
Signed-off-by: Ivan Oleynikov <***@metrotek.spb.ru>
---
ptp4l.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/ptp4l.c b/ptp4l.c
index a87e7e6..090b75a 100644
--- a/ptp4l.c
+++ b/ptp4l.c
@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <limits.h>
+#include <errno.h>
#include "clock.h"
#include "config.h"
@@ -72,7 +74,8 @@ static void usage(char *progname)
int main(int argc, char *argv[])
{
- char *config = NULL, *req_phc = NULL, *progname;
+ char req_phc[PATH_MAX];
+ char *config = NULL, *progname;
int c, err = -1, print_level;
struct clock *clock = NULL;
struct config *cfg;
@@ -137,7 +140,11 @@ int main(int argc, char *argv[])
goto out;
break;
case 'p':
- req_phc = optarg;
+ if (!realpath(optarg, req_phc)) {
+ pr_err("realpath(%s): %s", optarg, strerror(errno));
+ goto out;
+ }
+ pr_debug("using %s as realpath of %s", req_phc, optarg);
break;
case 's':
if (config_set_int(cfg, "slaveOnly", 1)) {
--
2.1.4
--
Ivan Oleynikov
STC Metrotek
St.Petersburg
2.1.4
--
Ivan Oleynikov
STC Metrotek
St.Petersburg