chiark / gitweb /
adns_str* etc.: Return NULL rather than crashing, and docs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 25 May 2020 11:55:33 +0000 (12:55 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 11 Jun 2020 15:13:02 +0000 (16:13 +0100)
Previously, calling these functions with arbitrary values would cause
them to do a struct member lookup on a null pointer.  Now they return
the pointer instead.

Also, some users have been confused by the docs, and have passsed, for
example, adns_s_max_misconfig.  This is also not permitted.  Clarify
that only values actually returned by adns are allowed.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/adns.h
src/general.c

index 899a7319f0c13e19ac50bf883987c2f567f9fc2c..b8072eeb77b37c9b288eb4ba3615799c369c4507 100644 (file)
@@ -1085,8 +1085,11 @@ const char *adns_errtypeabbrev(adns_status st);
  * the abbreviation of the error - eg, for adns_s_timeout it returns
  * "timeout".  adns_errtypeabbrev returns the abbreviation of the
  * error class: ie, for values up to adns_s_max_XXX it will return the
- * string XXX.  You MUST NOT call these functions with status values
- * not returned by the same adns library.
+ * string XXX.
+ *
+ * If you call these functions with status values not actually
+ * returned from other functions in the same adns library, the
+ * returned information may be NULL.
  */
 
 #ifdef __cplusplus
index e2ab3bc1854a155f2c83d41967f1e8e8194e5ccf..cfe07bddbb5653b349d1f73c477e8ef72c174bd7 100644 (file)
@@ -288,14 +288,14 @@ const char *adns_strerror(adns_status st) {
   const struct sinfo *si;
 
   si= findsinfo(st);
-  return si->string;
+  return si ? si->string : 0;
 }
 
 const char *adns_errabbrev(adns_status st) {
   const struct sinfo *si;
 
   si= findsinfo(st);
-  return si->abbrev;
+  return si ? si->abbrev : 0;
 }
 
 
@@ -332,7 +332,7 @@ const char *adns_errtypeabbrev(adns_status st) {
 
   sti= bsearch(&st,stinfos, sizeof(stinfos)/sizeof(*stinfos),
               sizeof(*stinfos), sti_compar);
-  return sti->abbrev;
+  return sti ? sti->abbrev : 0;
 }