From ea7694a8dbdaa7b77b787add711df1b6e5ace95d Mon Sep 17 00:00:00 2001 From: om Date: Sat, 12 Jul 2008 15:42:30 +0000 Subject: Change sprintf to snprintf, just in case; Update comments. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9985 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/users.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/users.cpp b/src/users.cpp index a660fe6ac..268c61b3b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1162,7 +1162,7 @@ const char* User::GetCIDRMask(int range) /* And finally, zero the extra bits required. */ v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits; - sprintf(buf, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range); + snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range); return buf; } break; @@ -1181,7 +1181,10 @@ const char* User::GetCIDRMask(int range) sin = (sockaddr_in*)this->ip; v4.s_addr = sin->sin_addr.s_addr; - /* (32 - range) is the number of bits we are *ignoring*. We shift this left and then right to wipe off these bits. */ + /* To create the CIDR mask we want to set all the bits after 'range' bits of the address + * to zero. This means the last (32 - range) bits of the address must be set to zero. + * This is done by shifting the value right and then back left by (32 - range) bits. + */ if(range > 0) { temp = ntohl(v4.s_addr); @@ -1197,7 +1200,7 @@ const char* User::GetCIDRMask(int range) v4.s_addr = 0; } - sprintf(buf, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range); + snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range); return buf; } break; -- cgit v1.2.3