diff options
author | 2011-11-20 19:08:37 -0500 | |
---|---|---|
committer | 2011-11-20 19:11:56 -0500 | |
commit | 7ae4aa5619cc7e7067ea6ee24a4d49fa5b4a72fd (patch) | |
tree | 5b1299a80bdd484c849b953996c141010cd2c0d6 | |
parent | get_sname: unify numeric handling (diff) | |
download | net-tools-7ae4aa5619cc7e7067ea6ee24a4d49fa5b4a72fd.tar.gz net-tools-7ae4aa5619cc7e7067ea6ee24a4d49fa5b4a72fd.tar.bz2 net-tools-7ae4aa5619cc7e7067ea6ee24a4d49fa5b4a72fd.zip |
get_sname: avoid buffer overflows if proto name is too long
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r-- | lib/inet.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -431,16 +431,17 @@ const char *get_sname(int socknumber, const char *proto, int numeric) init = 1; } buffer[0] = '\0'; - if (!strcmp(proto, "tcp")) { - if ((item = searchlist(tcp_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); - } else if (!strcmp(proto, "udp")) { - if ((item = searchlist(udp_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); - } else if (!strcmp(proto, "raw")) { - if ((item = searchlist(raw_name, socknumber)) != NULL) - sprintf(buffer, "%s", item->name); - + if (!strcmp(proto, "tcp")) + item = searchlist(tcp_name, socknumber); + else if (!strcmp(proto, "udp")) + item = searchlist(udp_name, socknumber); + else if (!strcmp(proto, "raw")) + item = searchlist(raw_name, socknumber); + else + item = NULL; + if (item) { + strncpy(buffer, item->name, sizeof(buffer)); + buffer[sizeof(buffer) - 1] = '\0'; } if (!buffer[0]) { |