Module Name:    src
Committed By:   abhinav
Date:           Sun Apr 30 14:49:26 UTC 2017

Modified Files:
        src/usr.sbin/makemandb: apropos-utils.c

Log Message:
Use sqlite3_mprintf() to generate SQL query instead of asprintf.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.sbin/makemandb/apropos-utils.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/makemandb/apropos-utils.c
diff -u src/usr.sbin/makemandb/apropos-utils.c:1.32 src/usr.sbin/makemandb/apropos-utils.c:1.33
--- src/usr.sbin/makemandb/apropos-utils.c:1.32	Thu Apr 27 08:02:24 2017
+++ src/usr.sbin/makemandb/apropos-utils.c	Sun Apr 30 14:49:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: apropos-utils.c,v 1.32 2017/04/27 08:02:24 abhinav Exp $	*/
+/*	$NetBSD: apropos-utils.c,v 1.33 2017/04/30 14:49:26 abhinav Exp $	*/
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <[email protected]>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.32 2017/04/27 08:02:24 abhinav Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.33 2017/04/30 14:49:26 abhinav Exp $");
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -503,12 +503,21 @@ generate_search_query(query_args *args, 
 	char *section_clause = NULL;
 	char *limit_clause = NULL;
 	char *machine_clause = NULL;
-	char *query;
+	char *query = NULL;
 
-	if (args->machine)
-		easprintf(&machine_clause, "AND mandb.machine = \'%s\' ",
-		    args->machine);
+	if (args->machine) {
+		machine_clause = sqlite3_mprintf("AND mandb.machine=%Q", args->machine);
+		if (machine_clause == NULL)
+			goto RETURN;
+	}
 
+	if (args->nrec >= 0) {
+		/* Use the provided number of records and offset */
+		limit_clause = sqlite3_mprintf(" LIMIT %d OFFSET %d",
+		    args->nrec, args->offset);
+		if (limit_clause == NULL)
+			goto RETURN;
+	}
 
 	/* We want to build a query of the form: "select x,y,z from mandb where
 	 * mandb match :query [AND (section LIKE '1' OR section LIKE '2' OR...)]
@@ -554,12 +563,6 @@ generate_search_query(query_args *args, 
 		}
 	}
 
-	if (args->nrec >= 0) {
-		/* Use the provided number of records and offset */
-		easprintf(&limit_clause, " LIMIT %d OFFSET %d",
-		    args->nrec, args->offset);
-	}
-
 	if (snippet_args == NULL) {
 		default_snippet_args[0] = "";
 		default_snippet_args[1] = "";
@@ -623,6 +626,7 @@ generate_search_query(query_args *args, 
 		limit_clause ? limit_clause : "");
 	}
 
+RETURN:
 	free(machine_clause);
 	free(section_clause);
 	free(limit_clause);

Reply via email to