Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Server Code Submissions

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2013, 02:06 AM
Vexyl
Hill Giant
 
Join Date: Oct 2009
Location: U.S.A.
Posts: 197
Default unix_timestamp() fix for MariaDB

MariaDB returns NULL instead of 0 when an argument is passed that is out of range
(https://mariadb.com/kb/en/unix_timestamp/)


When the column 'suspendeduntil' of an entry in the 'account' table is out of range (e.g., the default value '0000-00-00 00:00:00'), undefined behavior results in Database::CheckStatus() from common/database.cpp since it essentially calls atoi(NULL), which generally causes a segfault.


I added a simple check for this, here is the diff:

Code:
--- database.cpp	2013-09-27 22:50:21.412193740 -0700
+++ eqemu/projecteqemu-read-only/common/database.cpp	2013-09-27 23:05:18.484523951 -0700
@@ -304,7 +304,11 @@
 
 			int16 status = atoi(row[0]);
 
-			int32 suspendeduntil = atoi(row[1]);
+			int32 suspendeduntil = 0;
+			// MariaDB initalizes with NULL if unix_timestamp() is out of range
+			if (row[1] != NULL) {
+				suspendeduntil = atoi(row[1]);
+			}
 
 			int32 current = atoi(row[2]);
On another note, isn't there a safer alternative to atoi() that can be used?


Edit: Forgot EQEmu is on GitHub, I'll make an account and create a pull request when I have time.
Edit 2: Okay, done.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:54 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3