[quagga-dev 5265] mes_lookup / LOOKUP robustness

Paul Jakma Paul.Jakma at Sun.COM
Tue Feb 26 09:28:02 GMT 2008


Hi,

mes_lookup tries to print the string in the '{0, NULL}' entry that many 
struct messages have. Most callers are similarly unprepared and pass 
LOOKUP directly as a printf argument. Making mes_lookup more robust, and 
kinder to less-sophisticated users seems trivial and obvious.

(Diagnosed by Sowmini Varadhan).

Any objections to the below fix for this?

Index: lib/log.c
===================================================================
RCS file: /var/cvsroot/quagga/lib/log.c,v
retrieving revision 1.33
diff -u -p -r1.33 log.c
--- lib/log.c	6 Aug 2007 15:21:45 -0000	1.33
+++ lib/log.c	26 Feb 2008 09:21:40 -0000
@@ -756,6 +756,8 @@ lookup (struct message *mes, int key)
  const char *
  mes_lookup (struct message *meslist, int max, int index)
  {
+  const char *str = "(nil)";
+
    /* first check for best case: index is in range and matches the key
       value in that slot */
    if ((index >= 0) && (index < max) && (meslist[index].key == index))
@@ -769,14 +771,16 @@ mes_lookup (struct message *meslist, int
        {
  	if (meslist->key == index)
  	  {
+	    str = (meslist->str ? meslist->str : "(nil)");
+
  	    zlog_debug ("message index %d [%s] found in position %d (max is %d)",
-		      index, meslist->str, i, max);
-	    return meslist->str;
+		      index, str, i, max);
+	    return str;
  	  }
        }
    }
    zlog_err("message index %d not found (max is %d)", index, max);
-  return NULL;
+  return str ;
  }

  /* Wrapper around strerror to handle case where it returns NULL. */

regards,
-- 
Paul Jakma,
Solaris Networking                       Sun Microsystems, Scotland
http://opensolaris.org/os/project/quagga tel: EMEA x73150 / +44 15066 73150



More information about the Quagga-dev mailing list