Subject: bug#30494: 25.2; (setting-constant nil) error in sql.el

From: [email-masked] (Pierre Téchoueyres)
Date: Sat, 01 Dec 2018 01:30:29 +0100

Noam Postavsky <[email-masked]> writes:

> tags 30494 + confirmed easy
> quit
>
> [email-masked] writes:
>
>> In 'emacs -Q' executing it step-by-step:
>>
>> (require 'sql)
>>
>> (sql-add-product 'xyz "XyzDB"
>>                  '(:free-software t))
>>
>> (defcustom my-sql-xyz-program "ixyz"
>>   "Command to start ixyz by XyzDB."
>>   :type 'file
>>   :group 'SQL)
>>
>> ;; NEXT STEP FAILS WITH:
>> ;; Debugger entered--Lisp error: (setting-constant nil)
>> ;;  sql-set-product-feature(xyz :sqli-program my-sql-xyz-program)
>> ;;  eval((sql-set-product-feature (quote xyz) :sqli-program (quote my-sql-xyz-program)) nil)
>> (sql-set-product-feature 'xyz
>>                          :sqli-program 'my-sql-xyz-program)
>
> Looks like it's probably just a missing nil check in
> sql-set-product-feature.
>

Does the attached patch do the trick ?

>From fc0ee63bb0cadb054260ea74d310720ac3068f15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pierre=20T=C3=A9choueyres?= <[email-masked]>
Date: Sat, 1 Dec 2018 01:20:45 +0100
Subject: [PATCH] Check that feature exist in `sql-set-product-feature'
 (Bug#30494).

* lisp/progmodes/sql.el: add check for feature existence.
---
 lisp/progmodes/sql.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index e7d7494d2c..9051a6ad07 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -2533,13 +2533,17 @@ sql-set-product-feature
 
   (let* ((p (assoc product sql-product-alist))
          (v (plist-get (cdr p) feature)))
-    (if p
+    (if (and p v)
         (if (and
              (member feature sql-indirect-features)
              (symbolp v))
             (set v newvalue)
           (setcdr p (plist-put (cdr p) feature newvalue)))
-      (error "`%s' is not a known product; use `sql-add-product' to add it first." product))))
+      (progn
+       (when (null p)
+         (error "`%s' is not a known product; use `sql-add-product' to add it first." product))
+       (when (null v)
+         (error "`%s' is not a known feature for `%s'; use `sql-add-product' to add it first." feature product))))))
 
 (defun sql-get-product-feature (product feature &optional fallback not-indirect)
   "Lookup FEATURE associated with a SQL PRODUCT.
-- 
2.19.2