Package: nut-cgi Version: 2.0.1-2 Severity: normal Tags: patch I forgot to copy in a good version of hosts.conf when setting up a new nut-cgi installation, and when I invoked upsstats.cgi, I got an "Internal Server Error" from apache.
It turns out that upsstats.cgi was dereferencing a NULL pointer and crashing if no valid MONITOR lines were encountered. The attached patch prints an error message telling the user that the problem lies in hosts.conf. -- System Information: Debian Release: 3.1 APT prefers unstable APT policy: (500, 'unstable'), (500, 'testing') Architecture: powerpc (ppc) Kernel: Linux 2.6.10-powerpc Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1) Versions of packages nut-cgi depends on: ii libc6 2.3.2.ds1-20 GNU C Library: Shared libraries an ii libfontconfig1 2.3.1-2 generic font configuration library ii libfreetype6 2.1.7-2.3 FreeType 2 font engine, shared lib ii libgd2-xpm 2.0.33-1.1 GD Graphics Library version 2 ii libjpeg62 6b-10 The Independent JPEG Group's JPEG ii libpng12-0 1.2.8rel-1 PNG library - runtime ii libx11-6 4.3.0.dfsg.1-12 X Window System protocol client li ii libxpm4 4.3.0.dfsg.1-12 X pixmap library ii xlibs 4.3.0.dfsg.1-12 X Keyboard Extension (XKB) configu ii zlib1g 1:1.2.2-4 compression library - runtime -- no debconf information
--- nut-2.0.1/clients/upsstats.c.orig 2003-09-30 00:50:10.000000000 -0400 +++ nut-2.0.1/clients/upsstats.c 2005-04-03 12:49:39.583284972 -0400 @@ -752,6 +752,20 @@ static void load_hosts_conf(void) } pconf_finish(&ctx); + + if (!ulhead) { + printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n"); + printf(" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); + printf("<HTML><HEAD>\n"); + printf("<TITLE>Error: no hosts to monitor</TITLE>\n"); + printf("</HEAD><BODY>\n"); + printf("Error: no hosts to monitor (check <CODE>hosts.conf</CODE>)\n"); + printf("</BODY></HTML>\n"); + + /* leave something for the admin */ + fprintf(stderr, "upsstats: no hosts to monitor\n"); + exit(EXIT_FAILURE); + } } static void display_single(void)