Jelajahi Sumber

-bug fixed in processing DB url without password

Bogdan-Andrei Iancu 20 tahun lalu
induk
melakukan
730bddb501
2 mengubah file dengan 12 tambahan dan 9 penghapusan
  1. 4 3
      modules/db_mysql/dbase.c
  2. 8 6
      modules/db_mysql/my_id.c

+ 4 - 3
modules/db_mysql/dbase.c

@@ -72,9 +72,9 @@ static int submit_query(db_con_t* _h, const char* _s)
 		CON_TIMESTAMP(_h) = t;
 	}
 
-	/* screws up the terminal when the query contains a BLOB :-( (by bogdan)
-	 * DBG("submit_query(): %s\n", _s);
-	 */
+	/* screws up the terminal when the query contains a BLOB :-( (by bogdan)*/
+	  DBG("submit_query(): %s\n", _s);
+	/**/
 
 	/* When a server connection is lost and a query is attempted, most of
 	 * the time the query will return a CR_SERVER_LOST, then at the second
@@ -475,6 +475,7 @@ int db_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	*(sql_buf + off++) = ')';
 	*(sql_buf + off) = '\0';
 
+	DBG("---> <%s>\n",sql_buf);
 	if (submit_query(_h, sql_buf) < 0) {
 	        LOG(L_ERR, "db_insert: Error while submitting query\n");
 		return -2;

+ 8 - 6
modules/db_mysql/my_id.c

@@ -77,13 +77,15 @@ struct my_id* new_my_id(const char* url)
 	}
 	memcpy(ptr->username.s, username, ptr->username.len + 1);
 
-	ptr->password.len = strlen(password);
-	ptr->password.s = (char*)pkg_malloc(ptr->password.len + 1);
-	if (!ptr->password.s) {
-		LOG(L_ERR, "new_connection(): No memory left\n");
-		goto err;
+	if (password) {
+		ptr->password.len = strlen(password);
+		ptr->password.s = (char*)pkg_malloc(ptr->password.len + 1);
+		if (!ptr->password.s) {
+			LOG(L_ERR, "new_connection(): No memory left\n");
+			goto err;
+		}
+		memcpy(ptr->password.s, password, ptr->password.len + 1);
 	}
-	memcpy(ptr->password.s, password, ptr->password.len + 1);
 
 	ptr->host.len = strlen(host);
 	ptr->host.s = (char*)pkg_malloc(ptr->host.len + 1);