1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-28 13:00:45 +00:00

Check that there is no writing outside the string

This commit is contained in:
Nikolas Garofil 2011-02-13 00:10:20 +01:00
parent 5aaac61f4e
commit cb544bd1f7

View File

@ -235,41 +235,38 @@ void print_addrs(struct text_object *obj, char *p, int p_max_size)
void print_v6addrs(struct text_object *obj, char *p, int p_max_size) void print_v6addrs(struct text_object *obj, char *p, int p_max_size)
{ {
struct net_stat *ns = (struct net_stat *)obj->data.opaque; struct net_stat *ns = (struct net_stat *)obj->data.opaque;
char *current_char = p;
char tempaddress[INET6_ADDRSTRLEN]; char tempaddress[INET6_ADDRSTRLEN];
struct v6addr *current_v6 = ns->v6addrs; struct v6addr *current_v6 = ns->v6addrs;
if (!ns) if (!ns)
return; return;
if(p_max_size == 0) return;
if( ! ns->v6addrs) { if( ! ns->v6addrs) {
strncpy(p, "::", p_max_size); strncpy(p, "::", p_max_size);
if(ns->v6show_nm) strcat(p, "/128"); if(ns->v6show_nm) strncat(p, "/128", p_max_size);
if(ns->v6show_sc) strcat(p, "(/)"); if(ns->v6show_sc) strncat(p, "(/)", p_max_size);
return; return;
} }
*p=0;
while(current_v6) { while(current_v6) {
inet_ntop(AF_INET6, &(current_v6->addr), tempaddress, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &(current_v6->addr), tempaddress, INET6_ADDRSTRLEN);
strcpy(current_char, tempaddress); strncat(p, tempaddress, p_max_size);
current_char+=strlen(current_char);
//netmask //netmask
if(ns->v6show_nm) { if(ns->v6show_nm) {
char netmaskstr[5]; //max 5 chars (/128 + null-terminator) char netmaskstr[5]; //max 5 chars (/128 + null-terminator)
sprintf(netmaskstr, "/%u", current_v6->netmask); sprintf(netmaskstr, "/%u", current_v6->netmask);
strcpy(current_char, netmaskstr); strncat(p, netmaskstr, p_max_size);
current_char += strlen(netmaskstr);
} }
//scope //scope
if(ns->v6show_sc) { if(ns->v6show_sc) {
sprintf(current_char, "(%c)", current_v6->scope); char scopestr[3];
current_char += 3; sprintf(scopestr, "(%c)", current_v6->scope);
strncat(p, scopestr, p_max_size);
} }
//next (or last) address //next (or last) address
current_v6 = current_v6->next; current_v6 = current_v6->next;
if(current_v6) { if(current_v6) strncat(p, ", ", p_max_size);
strcpy(current_char, ", ");
current_char+=2;
} else *current_char=0;
} }
} }
#endif /* BUILD_IPV6 */ #endif /* BUILD_IPV6 */