]> git.puffer.fish Git - matthieu/frr.git/commitdiff
*: manually remove some more sprintf
authorQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 20 Apr 2020 21:59:31 +0000 (17:59 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 20 Apr 2020 23:14:33 +0000 (19:14 -0400)
Take care of some more complicated cases by hand

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
bgpd/bgp_clist.c
bgpd/bgp_dump.c
bgpd/bgp_fsm.c
lib/command.c
lib/log_vty.c
lib/vty.c
ospfd/ospf_vty.c

index 28b22997ed9974ff8953d3693b55cdcc86207301..5b3908442cad1b22bfdc9c02ef9126537338fa7a 100644 (file)
@@ -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;
 }
index 9af90dbf264baba8b9e606eb46b987de90227aaa..c87849ad7109fe9839296fa1b02c867f462f03be 100644 (file)
@@ -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) {
index fdffe374c04e92b73732c85e5a6904b22d06c811..ce5747dc2bae9d5cdaea11f9214add9db9453634 100644 (file)
@@ -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);
                }
        }
index 7abca5e70d907003df75e932d977d7c4e477c19b..6ee04e9c9bcb284a4e4768415f8db3a7d98aceb5 100644 (file)
@@ -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);
index 97026e5dbc771c8e385ace2687b6444bdb18f28b..d46fef15aee0ce4cbc33388b86ec03b3b02f5e41 100644 (file)
@@ -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);
index 34beb0a1a16e9af4f557acff5b0da9f3d24ec17b..784f9cf2ac460ed5865c786d67a03d32a65649f9 100644 (file)
--- 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);
index 43eeadbda5eb5fce0f4ba42f93d75b21e75081bc..71275e49d27610644f1580a0ad4fe0c4af22b4ae 100644 (file)
@@ -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) {