]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Don't limit refclock driver name to 4 chars
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 13 Jun 2011 11:49:46 +0000 (13:49 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 13 Jun 2011 11:49:46 +0000 (13:49 +0200)
conf.c
refclock.c
refclock.h

diff --git a/conf.c b/conf.c
index 87050eba576e36e9d1d2e5dcad78520980f5600d..f898cbade2c1f178ff4ef3785e9cc0d89546a3f2 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -471,7 +471,7 @@ parse_refclock(const char *line)
   unsigned long ref_id, lock_ref_id;
   double offset, delay, precision;
   const char *tmp;
-  char name[5], cmd[10 + 1], *param;
+  char cmd[10 + 1], *name, *param;
   unsigned char ref[5];
   SRC_SelectOption sel_option;
 
@@ -490,11 +490,20 @@ parse_refclock(const char *line)
   lock_ref_id = 0;
   sel_option = SRC_SelectNormal;
 
-  if (sscanf(line, "%4s%n", name, &n) != 1) {
+  while (isspace(line[0]))
+    line++;
+  tmp = line;
+  while (line[0] != '\0' && !isspace(line[0]))
+    line++;
+
+  if (line == tmp) {
     LOG(LOGS_WARN, LOGF_Configure, "Could not read refclock driver name at line %d", line_number);
     return;
   }
-  line += n;
+
+  name = MallocArray(char, 1 + line - tmp);
+  strncpy(name, tmp, line - tmp);
+  name[line - tmp] = '\0';
 
   while (isspace(line[0]))
     line++;
@@ -504,6 +513,7 @@ parse_refclock(const char *line)
 
   if (line == tmp) {
     LOG(LOGS_WARN, LOGF_Configure, "Could not read refclock parameter at line %d", line_number);
+    Free(name);
     return;
   }
 
@@ -558,7 +568,7 @@ parse_refclock(const char *line)
     line += n;
   }
 
-  strncpy(refclock_sources[i].driver_name, name, 4);
+  refclock_sources[i].driver_name = name;
   refclock_sources[i].driver_parameter = param;
   refclock_sources[i].driver_poll = dpoll;
   refclock_sources[i].poll = poll;
index edb743d30a85ee5f617f105ed8faad69f8ba56f4..4f8226be8c45fdd4e05d42875c2206770d535f34 100644 (file)
@@ -150,14 +150,14 @@ RCL_AddRefclock(RefclockParameters *params)
   if (n_sources == MAX_RCL_SOURCES)
     return 0;
 
-  if (strncmp(params->driver_name, "SHM", 4) == 0) {
+  if (strcmp(params->driver_name, "SHM") == 0) {
     inst->driver = &RCL_SHM_driver;
     inst->precision = 1e-6;
-  } else if (strncmp(params->driver_name, "SOCK", 4) == 0) {
+  } else if (strcmp(params->driver_name, "SOCK") == 0) {
     inst->driver = &RCL_SOCK_driver;
     inst->precision = 1e-9;
     pps_source = 1;
-  } else if (strncmp(params->driver_name, "PPS", 4) == 0) {
+  } else if (strcmp(params->driver_name, "PPS") == 0) {
     inst->driver = &RCL_PPS_driver;
     inst->precision = 1e-9;
     pps_source = 1;
@@ -244,6 +244,8 @@ RCL_AddRefclock(RefclockParameters *params)
 #endif
   n_sources++;
 
+  Free(params->driver_name);
+
   return 1;
 }
 
index 438f1dd7d30685af2e66999f21f1d1eb1e52c9be..a653006e97e529bdce49dfd45fae47b22f587661 100644 (file)
@@ -32,7 +32,7 @@
 #include "sources.h"
 
 typedef struct {
-  char driver_name[4];
+  char *driver_name;
   char *driver_parameter;
   int driver_poll;
   int poll;