On 2/11/2020 6:04 AM, Richard Cochran wrote:
> Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
Reviewed-by: Jacob Keller <jacob.e.kel...@intel.com>
> ---
> clock.c | 5 +++--
> config.c | 2 +-
> pmc_common.c | 2 +-
> 3 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/clock.c b/clock.c
> index 3895d09..159fcb2 100644
> --- a/clock.c
> +++ b/clock.c
> @@ -850,6 +850,7 @@ struct clock *clock_create(enum clock_type type, struct
> config *config,
> int fadj = 0, max_adj = 0, sw_ts;
> int phc_index, required_modes = 0;
> struct clock *c = &the_clock;
> + const char *uds_ifname;
> struct port *p;
> unsigned char oui[OUI_LEN];
> char phc[32], *tmp;
> @@ -999,8 +1000,8 @@ struct clock *clock_create(enum clock_type type, struct
> config *config,
> }
>
> /* Configure the UDS. */
> - snprintf(udsif->name, sizeof(udsif->name), "%s",
> - config_get_string(config, NULL, "uds_address"));
> + uds_ifname = config_get_string(config, NULL, "uds_address");
> + interface_set_name(udsif, uds_ifname);
This used to do an snprintf and now it does a strncpy. This is slightly
different because snprintf will null terminate while strncpy won't
guarantee this.. However we now copy by MAX_IFNAME_SIZE rather than
snprintf's "full" size. This means that the function will guarantee to
be null terminated if the original data starts as zero-allocated.
Perhaps the interface_set_name should guarantee the last byte is zero
just in case the interface structure is not per-initialized with zeros.
Thanks,
Jake
> if (config_set_section_int(config, interface_name(udsif),
> "announceReceiptTimeout", 0)) {
> return NULL;
> diff --git a/config.c b/config.c
> index c30f6bc..717ee65 100644
> --- a/config.c
> +++ b/config.c
> @@ -835,7 +835,7 @@ struct interface *config_create_interface(const char
> *name, struct config *cfg)
> return NULL;
> }
>
> - strncpy(iface->name, name, MAX_IFNAME_SIZE);
> + interface_set_name(iface, name);
> STAILQ_INSERT_TAIL(&cfg->interfaces, iface, list);
> cfg->n_interfaces++;
>
> diff --git a/pmc_common.c b/pmc_common.c
> index 6bdaa94..41181fb 100644
> --- a/pmc_common.c
> +++ b/pmc_common.c
> @@ -350,7 +350,7 @@ struct pmc *pmc_create(struct config *cfg, enum
> transport_type transport_type,
> goto failed;
> }
>
> - strncpy(iface.name, iface_name, MAX_IFNAME_SIZE);
> + interface_set_name(&iface, iface_name);
> interface_ensure_tslabel(&iface);
>
> if (transport_open(pmc->transport, &iface,
>
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel