Skip to content
This repository
Browse code

m_ident Don't give a potentially non null terminated buffer to strrch…

…r(), allow the usage of an overriden IsIdent() instead of using a hardcoded version of it, fix casting User pointers to LocalUser pointers blindly
  • Loading branch information...
commit 36cabb64ce859d087d1fe4476c5c556ef93acb40 1 parent 6704b47
Attila Molnar authored

Showing 1 changed file with 22 additions and 26 deletions. Show diff stats Hide diff stats

  1. 48  src/modules/m_ident.cpp
48  src/modules/m_ident.cpp
@@ -216,15 +216,19 @@ class IdentRequestSocket : public EventHandler
216 216
 		char ibuf[MAXBUF];
217 217
 		int recvresult = ServerInstance->SE->Recv(this, ibuf, MAXBUF-1, 0);
218 218
 
  219
+		/* Close (but don't delete from memory) our socket
  220
+		 * and flag as done since the ident lookup has finished
  221
+		 */
  222
+		Close();
  223
+		done = true;
  224
+
219 225
 		/* Cant possibly be a valid response shorter than 3 chars,
220 226
 		 * because the shortest possible response would look like: '1,1'
221 227
 		 */
222 228
 		if (recvresult < 3)
223  
-		{
224  
-			Close();
225  
-			done = true;
226 229
 			return;
227  
-		}
  230
+
  231
+		ibuf[recvresult] = '\0';
228 232
 
229 233
 		ServerInstance->Logs->Log("m_ident",DEBUG,"ReadResponse()");
230 234
 
@@ -232,37 +236,25 @@ class IdentRequestSocket : public EventHandler
232 236
 		if(i)
233 237
 		{
234 238
 			std::string token(++i);
235  
-			std::string ident;
236 239
 
237 240
 			/* Truncate the ident at any characters we don't like, skip leading spaces */
238  
-			size_t k = 0;
239  
-			for (const char *j = token.c_str(); *j && (k++ < ServerInstance->Config->Limits.IdentMax); j++)
  241
+			for (std::string::const_iterator j = token.begin(); j != token.end() && (result.size() < ServerInstance->Config->Limits.IdentMax); ++j)
240 242
 			{
241 243
 				if (*j == ' ')
242 244
 					continue;
243 245
 
244  
-				/* Rules taken from InspIRCd::IsIdent */
245  
-				if (((*j >= 'A') && (*j <= '}')) || ((*j >= '0') && (*j <= '9')) || (*j == '-') || (*j == '.'))
  246
+				/* Add the next char to the result and see if it's still a valid ident,
  247
+				 * according to IsIdent(). If it isn't, then erase what we just added and
  248
+				 * we're done.
  249
+				 */
  250
+				result += *j;
  251
+				if (!ServerInstance->IsIdent(result.c_str()))
246 252
 				{
247  
-					ident += *j;
248  
-					continue;
  253
+					result.erase(result.end()-1);
  254
+					break;
249 255
 				}
250  
-
251  
-				break;
252  
-			}
253  
-
254  
-			if (!ident.empty() && ServerInstance->IsIdent(ident.c_str()))
255  
-			{
256  
-				result = ident;
257 256
 			}
258 257
 		}
259  
-
260  
-		/* Close (but dont delete from memory) our socket
261  
-		 * and flag as done
262  
-		 */
263  
-		Close();
264  
-		done = true;
265  
-		return;
266 258
 	}
267 259
 };
268 260
 
@@ -382,7 +374,11 @@ class ModuleIdent : public Module
382 374
 	{
383 375
 		/* Module unloading, tidy up users */
384 376
 		if (target_type == TYPE_USER)
385  
-			OnUserDisconnect((LocalUser*)item);
  377
+		{
  378
+			LocalUser* user = IS_LOCAL((User*) item);
  379
+			if (user)
  380
+				OnUserDisconnect(user);
  381
+		}
386 382
 	}
387 383
 
388 384
 	virtual void OnUserDisconnect(LocalUser *user)

0 notes on commit 36cabb6

Please sign in to comment.
Something went wrong with that request. Please try again.