[Midnightbsd-cvs] src [7629] stable/0.8/lib/libmport/pkgmeta.c: add sanity checks to logging code and switch over to %s as %Q is causing crashes with newer sqlite versions

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 4 19:46:36 EDT 2016


Revision: 7629
          http://svnweb.midnightbsd.org/src/?rev=7629
Author:   laffer1
Date:     2016-06-04 19:46:35 -0400 (Sat, 04 Jun 2016)
Log Message:
-----------
add sanity checks to logging code and switch over to %s as %Q is causing crashes with newer sqlite versions

Modified Paths:
--------------
    stable/0.8/lib/libmport/pkgmeta.c

Modified: stable/0.8/lib/libmport/pkgmeta.c
===================================================================
--- stable/0.8/lib/libmport/pkgmeta.c	2016-06-04 23:12:43 UTC (rev 7628)
+++ stable/0.8/lib/libmport/pkgmeta.c	2016-06-04 23:46:35 UTC (rev 7629)
@@ -430,15 +430,27 @@
  *
  * Create an entry in the log table for this pkg (and version), using the given message.
  */
-int mport_pkgmeta_logevent(mportInstance *mport, mportPackageMeta *pkg, const char *msg) 
+int
+mport_pkgmeta_logevent(mportInstance *mport, mportPackageMeta *pkg, const char *msg) 
 {
-  struct timespec now;
+	struct timespec now;
   
-  if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
-    RETURN_ERROR(MPORT_ERR_FATAL, strerror(errno));
-  }
+	if (clock_gettime(CLOCK_REALTIME, &now) != 0) {
+		RETURN_ERROR(MPORT_ERR_FATAL, strerror(errno));
+	}
+
+	if (pkg == NULL)
+		RETURN_ERROR(MPORT_ERR_FATAL, "pkg is null");
+
+	if (pkg->name == NULL || pkg->version == NULL)
+		RETURN_ERROR(MPORT_ERR_FATAL, "pkg is not initialized");
+
+	if (msg == NULL)
+		RETURN_ERROR(MPORT_ERR_WARN, "null message to log");
           
-  return mport_db_do(mport->db, "INSERT INTO log (pkg, version, date, msg) VALUES (%Q,%Q,%i,%Q)", pkg->name, pkg->version, now.tv_sec, msg);
+	return mport_db_do(mport->db, 
+	  "INSERT INTO log (pkg, version, date, msg) VALUES (%s,%s,%i,%s)", 
+		pkg->name, pkg->version, now.tv_sec, msg);
 }
 
 



More information about the Midnightbsd-cvs mailing list