*: use appropriate buffer sizes, specifiers

- Fix 1 byte overflow when showing GR info in bgpd
- Use PATH_MAX for path buffers
- Use unsigned specifiers for uint16_t's in zebra pbr

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2020-04-20 14:28:39 -04:00
parent fc746f1c01
commit 2b7165e76f
6 changed files with 11 additions and 9 deletions

View File

@ -9860,7 +9860,8 @@ static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
{ {
char buf[SU_ADDRSTRLEN] = {0}; char buf[SU_ADDRSTRLEN] = {0};
char dn_flag[2] = {0}; char dn_flag[2] = {0};
char neighborAddr[INET6_ADDRSTRLEN] = {0}; /* '*' + v6 address of neighbor */
char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
if (!p->conf_if && peer_dynamic_neighbor(p)) if (!p->conf_if && peer_dynamic_neighbor(p))
dn_flag[0] = '*'; dn_flag[0] = '*';

View File

@ -637,7 +637,7 @@ void csv_dump(csv_t *csv)
static int get_memory_usage(pid_t pid) static int get_memory_usage(pid_t pid)
{ {
int fd, data, stack; int fd, data, stack;
char buf[4096], status_child[BUFSIZ]; char buf[4096], status_child[PATH_MAX];
char *vm; char *vm;
snprintf(status_child, sizeof(status_child), "/proc/%d/status", pid); snprintf(status_child, sizeof(status_child), "/proc/%d/status", pid);

View File

@ -25,6 +25,7 @@
#include <linux/ip.h> #include <linux/ip.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/if_tunnel.h> #include <linux/if_tunnel.h>
#include <linux/limits.h>
#include "nhrp_protocol.h" #include "nhrp_protocol.h"
#include "os.h" #include "os.h"
@ -127,7 +128,7 @@ static int linux_configure_arp(const char *iface, int on)
static int linux_icmp_redirect_off(const char *iface) static int linux_icmp_redirect_off(const char *iface)
{ {
char fname[256]; char fname[PATH_MAX];
int fd, ret = -1; int fd, ret = -1;
snprintf(fname, sizeof(fname), snprintf(fname, sizeof(fname),

View File

@ -605,7 +605,7 @@ static void parse_options(int argc, char *const *argv)
static int pid_is_exec(pid_t pid, const struct stat *esb) static int pid_is_exec(pid_t pid, const struct stat *esb)
{ {
struct stat sb; struct stat sb;
char buf[32]; char buf[PATH_MAX];
snprintf(buf, sizeof(buf), "/proc/%ld/exe", (long)pid); snprintf(buf, sizeof(buf), "/proc/%ld/exe", (long)pid);
if (stat(buf, &sb) != 0) if (stat(buf, &sb) != 0)
@ -617,7 +617,7 @@ static int pid_is_exec(pid_t pid, const struct stat *esb)
static int pid_is_user(pid_t pid, uid_t uid) static int pid_is_user(pid_t pid, uid_t uid)
{ {
struct stat sb; struct stat sb;
char buf[32]; char buf[PATH_MAX];
snprintf(buf, sizeof(buf), "/proc/%ld", (long)pid); snprintf(buf, sizeof(buf), "/proc/%ld", (long)pid);
if (stat(buf, &sb) != 0) if (stat(buf, &sb) != 0)
@ -628,7 +628,7 @@ static int pid_is_user(pid_t pid, uid_t uid)
static int pid_is_cmd(pid_t pid, const char *name) static int pid_is_cmd(pid_t pid, const char *name)
{ {
char buf[32]; char buf[PATH_MAX];
FILE *f; FILE *f;
int c; int c;

View File

@ -153,7 +153,7 @@ static int zebra_ns_delete(char *name)
static int zebra_ns_notify_self_identify(struct stat *netst) static int zebra_ns_notify_self_identify(struct stat *netst)
{ {
char net_path[64]; char net_path[PATH_MAX];
int netns; int netns;
snprintf(net_path, sizeof(net_path), "/proc/self/ns/net"); snprintf(net_path, sizeof(net_path), "/proc/self/ns/net");

View File

@ -877,14 +877,14 @@ static void zebra_pbr_display_icmp(struct vty *vty,
/* range icmp type */ /* range icmp type */
if (zpie->src_port_max || zpie->dst_port_max) { if (zpie->src_port_max || zpie->dst_port_max) {
vty_out(vty, ":icmp:[type <%d:%d>;code <%d:%d>", vty_out(vty, ":icmp:[type <%u:%u>;code <%u:%u>",
zpie->src_port_min, zpie->src_port_max, zpie->src_port_min, zpie->src_port_max,
zpie->dst_port_min, zpie->dst_port_max); zpie->dst_port_min, zpie->dst_port_max);
} else { } else {
port = ((zpie->src_port_min << 8) & 0xff00) + port = ((zpie->src_port_min << 8) & 0xff00) +
(zpie->dst_port_min & 0xff); (zpie->dst_port_min & 0xff);
memset(decoded_str, 0, sizeof(decoded_str)); memset(decoded_str, 0, sizeof(decoded_str));
snprintf(decoded_str, sizeof(decoded_str), "%d/%d", snprintf(decoded_str, sizeof(decoded_str), "%u/%u",
zpie->src_port_min, zpie->dst_port_min); zpie->src_port_min, zpie->dst_port_min);
vty_out(vty, ":icmp:%s", vty_out(vty, ":icmp:%s",
lookup_msg(icmp_typecode_str, lookup_msg(icmp_typecode_str,