diff options
author | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-07-12 15:42:30 +0000 |
---|---|---|
committer | om <om@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-07-12 15:42:30 +0000 |
commit | ea7694a8dbdaa7b77b787add711df1b6e5ace95d (patch) | |
tree | 5b56650d326b635fb5cb875d1a5714e613a87c54 /src | |
parent | ab348e6c8b94adfc0d815562c32d504bf1965ade (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/users.cpp | 9 |
1 files 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; |