Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb PR/54343: Prevent NULL pointers in callba...



details:   https://anonhg.NetBSD.org/src/rev/35bf4ea3c0d9
branches:  trunk
changeset: 458903:35bf4ea3c0d9
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Aug 15 10:29:07 2019 +0000

description:
PR/54343: Prevent NULL pointers in callback strings; use "*?*" for now to
identify them.

diffstat:

 usr.sbin/makemandb/apropos-utils.c |  27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diffs (63 lines):

diff -r 9c7e8d4060a2 -r 35bf4ea3c0d9 usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c        Thu Aug 15 10:24:26 2019 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c        Thu Aug 15 10:29:07 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apropos-utils.c,v 1.45 2019/06/07 16:43:58 leot Exp $  */
+/*     $NetBSD: apropos-utils.c,v 1.46 2019/08/15 10:29:07 christos Exp $      */
 /*-
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.45 2019/06/07 16:43:58 leot Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.46 2019/08/15 10:29:07 christos Exp $");
 
 #include <sys/queue.h>
 #include <sys/stat.h>
@@ -654,6 +654,13 @@
        return query;
 }
 
+static const char *
+get_stmt_col_text(sqlite3_stmt *stmt, int col)
+{
+       const char *t = (const char *) sqlite3_column_text(stmt, col);
+       return t == NULL ? "*?*" : t;
+}
+
 /*
  * Execute the full text search query and return the number of results
  * obtained.
@@ -695,13 +702,14 @@
        unsigned int nresults = 0;
        while (sqlite3_step(stmt) == SQLITE_ROW) {
                nresults++;
-               callback_args.section = (const char *) sqlite3_column_text(stmt, 0);
-               name_temp = (const char *) sqlite3_column_text(stmt, 1);
-               callback_args.name_desc = (const char *) sqlite3_column_text(stmt, 2);
-               callback_args.machine = (const char *) sqlite3_column_text(stmt, 3);
+               callback_args.section = get_stmt_col_text(stmt, 0);
+               name_temp = get_stmt_col_text(stmt, 1);
+               callback_args.name_desc = get_stmt_col_text(stmt, 2);
+               callback_args.machine = get_stmt_col_text(stmt, 3);
                if (!args->legacy) {
-                       callback_args.snippet = (const char *) sqlite3_column_text(stmt, 4);
-                       callback_args.snippet_length = strlen(callback_args.snippet);
+                       callback_args.snippet = get_stmt_col_text(stmt, 4);
+                       callback_args.snippet_length =
+                           strlen(callback_args.snippet);
                } else {
                        callback_args.snippet = "";
                        callback_args.snippet_length = 1;
@@ -713,8 +721,7 @@
                        easprintf(&name, "%s/%s", lower(m), name_temp);
                        free(m);
                } else {
-                       name = estrdup((const char *)
-                           sqlite3_column_text(stmt, 1));
+                       name = estrdup(get_stmt_col_text(stmt, 1));
                }
                callback_args.name = name;
                callback_args.other_data = args->callback_data;



Home | Main Index | Thread Index | Old Index