summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2020-04-20 23:59:31 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2020-04-21 01:14:33 +0200
commitfc746f1c01daf34600d83293647199e81fcb8316 (patch)
treef26168f502d6b5faaffff8c7945acbb88c885fa1
parent*: sprintf -> snprintf (diff)
downloadfrr-fc746f1c01daf34600d83293647199e81fcb8316.tar.xz
frr-fc746f1c01daf34600d83293647199e81fcb8316.zip
*: manually remove some more sprintf
Take care of some more complicated cases by hand Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_clist.c8
-rw-r--r--bgpd/bgp_dump.c26
-rw-r--r--bgpd/bgp_fsm.c3
-rw-r--r--lib/command.c3
-rw-r--r--lib/log_vty.c10
-rw-r--r--lib/vty.c2
-rw-r--r--ospfd/ospf_vty.c17
7 files changed, 20 insertions, 49 deletions
diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c
index 28b22997e..5b3908442 100644
--- a/bgpd/bgp_clist.c
+++ b/bgpd/bgp_clist.c
@@ -546,24 +546,20 @@ static char *lcommunity_str_get(struct lcommunity *lcom, int i)
uint32_t localdata2;
char *str;
const uint8_t *ptr;
- char *pnt;
ptr = lcom->val + (i * LCOMMUNITY_SIZE);
memcpy(&lcomval, ptr, LCOMMUNITY_SIZE);
/* Allocate memory. 48 bytes taken off bgp_lcommunity.c */
- str = pnt = XMALLOC(MTYPE_LCOMMUNITY_STR, 48);
-
ptr = (uint8_t *)lcomval.val;
ptr = ptr_get_be32(ptr, &globaladmin);
ptr = ptr_get_be32(ptr, &localdata1);
ptr = ptr_get_be32(ptr, &localdata2);
(void)ptr; /* consume value */
- sprintf(pnt, "%u:%u:%u", globaladmin, localdata1, localdata2);
- pnt += strlen(pnt);
- *pnt = '\0';
+ str = XMALLOC(MTYPE_LCOMMUNITY_STR, 48);
+ snprintf(str, 48, "%u:%u:%u", globaladmin, localdata1, localdata2);
return str;
}
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 9af90dbf2..c87849ad7 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -787,32 +787,6 @@ static struct cmd_node bgp_dump_node = {
.config_write = config_write_bgp_dump,
};
-#if 0
-char *
-config_time2str (unsigned int interval)
-{
- static char buf[BUFSIZ];
-
- buf[0] = '\0';
-
- if (interval / 3600)
- {
- sprintf (buf, "%dh", interval / 3600);
- interval %= 3600;
- }
- if (interval / 60)
- {
- sprintf (buf + strlen (buf), "%dm", interval /60);
- interval %= 60;
- }
- if (interval)
- {
- sprintf (buf + strlen (buf), "%d", interval);
- }
- return buf;
-}
-#endif
-
static int config_write_bgp_dump(struct vty *vty)
{
if (bgp_dump_all.filename) {
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index fdffe374c..ce5747dc2 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -1321,7 +1321,8 @@ int bgp_stop(struct peer *peer)
if ((peer->status == OpenConfirm)
|| (peer->status == Established)) {
/* ORF received prefix-filter pnt */
- sprintf(orf_name, "%s.%d.%d", peer->host, afi, safi);
+ snprintf(orf_name, sizeof(orf_name), "%s.%d.%d",
+ peer->host, afi, safi);
prefix_bgp_orf_remove_all(afi, orf_name);
}
}
diff --git a/lib/command.c b/lib/command.c
index 7abca5e70..6ee04e9c9 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1535,7 +1535,8 @@ static int file_write_config(struct vty *vty)
config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8);
- sprintf(config_file_tmp, "%s.XXXXXX", config_file);
+ snprintf(config_file_tmp, strlen(config_file) + 8, "%s.XXXXXX",
+ config_file);
/* Open file to configuration write. */
fd = mkstemp(config_file_tmp);
diff --git a/lib/log_vty.c b/lib/log_vty.c
index 97026e5db..d46fef15a 100644
--- a/lib/log_vty.c
+++ b/lib/log_vty.c
@@ -260,10 +260,11 @@ DEFUN_HIDDEN (no_config_log_monitor,
static int set_log_file(struct zlog_cfg_file *target, struct vty *vty,
const char *fname, int loglevel)
{
- char *p = NULL;
+ char path[MAXPATHLEN + 1];
const char *fullpath;
bool ok;
+
/* Path detection. */
if (!IS_DIRECTORY_SEP(*fname)) {
char cwd[MAXPATHLEN + 1];
@@ -276,17 +277,14 @@ static int set_log_file(struct zlog_cfg_file *target, struct vty *vty,
return CMD_WARNING_CONFIG_FAILED;
}
- p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2);
- sprintf(p, "%s/%s", cwd, fname);
- fullpath = p;
+ snprintf(path, sizeof(path), "%s/%s", cwd, fname);
+ fullpath = path;
} else
fullpath = fname;
target->prio_min = loglevel;
ok = zlog_file_set_filename(target, fullpath);
- XFREE(MTYPE_TMP, p);
-
if (!ok) {
if (vty)
vty_out(vty, "can't open logfile %s\n", fname);
diff --git a/lib/vty.c b/lib/vty.c
index 34beb0a1a..784f9cf2a 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2380,7 +2380,7 @@ static FILE *vty_use_backup_config(const char *fullpath)
}
fullpath_tmp = malloc(strlen(fullpath) + 8);
- sprintf(fullpath_tmp, "%s.XXXXXX", fullpath);
+ snprintf(fullpath_tmp, strlen(fullpath) + 8, "%s.XXXXXX", fullpath);
/* Open file to configuration write. */
tmp = mkstemp(fullpath_tmp);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 43eeadbda..71275e49d 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -83,7 +83,8 @@ static void area_id2str(char *buf, int length, struct in_addr *area_id,
if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
inet_ntop(AF_INET, area_id, buf, length);
else
- sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr));
+ snprintf(buf, length, "%lu",
+ (unsigned long)ntohl(area_id->s_addr));
}
static int str2metric(const char *str, int *metric)
@@ -9997,7 +9998,7 @@ static int config_write_interface(struct vty *vty)
static int config_write_network_area(struct vty *vty, struct ospf *ospf)
{
struct route_node *rn;
- uint8_t buf[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
/* `network area' print. */
for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
@@ -10006,12 +10007,12 @@ static int config_write_network_area(struct vty *vty, struct ospf *ospf)
/* Create Area ID string by specified Area ID format. */
if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
- inet_ntop(AF_INET, &n->area_id, (char *)buf,
+ inet_ntop(AF_INET, &n->area_id, buf,
sizeof(buf));
else
- sprintf((char *)buf, "%lu",
- (unsigned long int)ntohl(
- n->area_id.s_addr));
+ snprintf(buf, sizeof(buf), "%lu",
+ (unsigned long int)ntohl(
+ n->area_id.s_addr));
/* Network print. */
vty_out(vty, " network %s/%d area %s\n",
@@ -10026,13 +10027,13 @@ static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
{
struct listnode *node;
struct ospf_area *area;
- uint8_t buf[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
/* Area configuration print. */
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
struct route_node *rn1;
- area_id2str((char *)buf, sizeof(buf), &area->area_id,
+ area_id2str(buf, sizeof(buf), &area->area_id,
area->area_id_fmt);
if (area->auth_type != OSPF_AUTH_NULL) {