nessus-libraries-2.0.0 compiler warnings patch
Stephen Friedl <[email protected]>
| Newsgroups | gmane.comp.security.nessus.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello all, This is a patch for nessus-libraries 2.0.0 to clean up numerous compiler warnings. I rebuilt everything with "-W -Wall --pedantic", and this pointed out plenty of unused variables and other things. Some of them are pedantic, but a few were real bugs. None of them should harm any production code or affect porting. - unused variables (but not parameters). I didn't touch any vars that were part of #ifdefs or commented out. - cleaned up the argument lists for signal handlers - fixed the code for dealing with __attribute__: before GCC 2.5 the only way to say that function didn't exit was to qualify it with "volatile", but >= 2.5 we should use __attribute__((noreturn)) I don't believe that __attribute__((volatile)) was ever correct for GCC. - "store_plugin" has "return" instead of "return <value>" in many places. This is surely a bug. I believe that NULL was the right error response. - added a few prototypes in dot-h files. There are more fixes to be made, but they're more aggressive and will be left for another day. I hope to dive into Nessus development, and I typically get my arms around a new project by cleaning up the code. If this is inappropriate or a distraction or otherwise not really wanted, that's ok too. Regards, Steve --- Stephen J Friedl | Software Consultant | Tustin, CA | +1 714 544-6561 www.unixwiz.net | I speak for me only | KA8CMY | [email protected] --- libnessus/arglists.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/arglists.c 2003-02-27 03:20:56.000000000 +0000 @@ -236,8 +236,6 @@ long length; void *value; { - int h; - if(name == NULL) return -1; @@ -281,8 +279,6 @@ struct arglist * args; const char * name; { - int flag=0; - if(args == NULL) return NULL; --- libnessus/harglists.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/harglists.c 2003-02-27 03:47:32.000000000 +0000 @@ -158,8 +158,6 @@ -static void *nullptr = 0 ; - #ifdef HARG_LIST_TRACKER static hlst *harg_tracker; #endif @@ -502,6 +500,12 @@ fputs ("\n", stderr); } +static void ** +harg_walk_next_ptr + (hargwalk *w) +{ + return next_hlst_search ((hsrch*)w) ; +} static void do_harg_dump @@ -510,7 +514,6 @@ { hargwalk *w ; harg **R, *r ; - static void **harg_walk_next_ptr (hargwalk*); if(a == 0 || (w = harg_walk_init (a)) == 0) { do_printf ("-error; no such list!\n",0,0,0,0,0); @@ -586,14 +589,6 @@ } -static void ** -harg_walk_next_ptr - (hargwalk *w) -{ - return next_hlst_search ((hsrch*)w) ; -} - - @@ -789,9 +784,7 @@ hargtype_t ntype) { harg **S, **R, *r ; - hargtype_t save ; int same_keys, klen = klen_by_type (type); - char *p, *q; /* sanity check */ if (a == 0) { --- libnessus/hlst.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/hlst.c 2003-02-27 03:21:23.000000000 +0000 @@ -837,7 +837,9 @@ qsort (h->access->inx, h->total_entries, sizeof (hashqueue*), sorter_cb); if (h->sorter_fn != 0) + { globally_unlock () ; + } } --- libnessus/ids_send.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/ids_send.c 2003-02-27 03:22:15.000000000 +0000 @@ -390,7 +390,6 @@ int sz = sizeof(sockaddr); int e; const char * packet; - int b; int bpf; bzero(&sockaddr, sizeof(sockaddr)); @@ -497,7 +496,6 @@ char * src_host, * dst_host; int ret = 0; int len; - int b; dst = plug_get_host_ip(args); if(!dst) --- libnessus/network.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/network.c 2003-02-27 03:43:49.000000000 +0000 @@ -932,6 +932,7 @@ if (total >= max_len) return total; if (__timeout) + { if (min_len <= 0) { /* Be smart */ @@ -953,6 +954,7 @@ if(ret == 0 || errcode != SSL_ERROR_WANT_READ) break; } + } } break; #endif --- libnessus/pcap.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/pcap.c 2003-02-27 03:21:08.000000000 +0000 @@ -72,7 +72,6 @@ { int soc = socket(AF_INET, SOCK_DGRAM, 0); struct sockaddr_in soca; - int b; int bpf; struct in_addr me; char * iface = routethrough(&addr, &me); --- libnessus/plugutils.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/plugutils.c 2003-02-27 03:27:11.000000000 +0000 @@ -30,6 +30,8 @@ /* want version stuff */ #include "libvers.h" +#include "scanners_utils.h" + #undef DEBUG_DIFF_SCAN @@ -448,7 +450,6 @@ const char * portname; { struct arglist * ports; - int iport = atoi(portname); if(portname != NULL) { @@ -837,7 +838,6 @@ char port_s[255]; unsigned short * range; char * prange = (char*)arg_get_value(prefs, "port_range"); - int flag; int num; if(!proto) @@ -1029,7 +1029,6 @@ char *t; char * buffer; int soc; - struct arglist * globs; char * naction; int len; ntp_caps* caps = arg_get_value(desc, "NTP_CAPS"); @@ -1357,10 +1356,7 @@ const char * defaul; { struct arglist * prefs = arg_get_value(desc, "PLUGIN_PREFS"); - char * p_name = _plug_get_name(desc); char pref[1024]; - char * cname; - int len; if(prefs == NULL) @@ -1581,33 +1577,29 @@ } static void -sig_n(n, f) - int n; - void * f; +sig_n(int signo, void (*fcn)(int) ) { #ifdef HAVE_SIGACTION struct sigaction sa; - sa.sa_handler = f; + sa.sa_handler = fcn; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); - sigaction(n,&sa,(struct sigaction *) 0); + sigaction(signo, &sa,(struct sigaction *) 0); #else - signal(n, f); + signal(signo, fcn); #endif } static void -sig_term(f) - void *f; +sig_term( void (*fcn)(int) ) { - sig_n(SIGTERM, f); + sig_n(SIGTERM, fcn); } static void -sig_alarm(f) - void * f; +sig_alarm( void (*fcn)(int) ) { - sig_n(SIGALRM, f); + sig_n(SIGALRM, fcn); } #endif --- libnessus/plugutils.h.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/plugutils.h 2003-02-27 03:39:39.000000000 +0000 @@ -17,6 +17,9 @@ char * _plug_get_description(struct arglist*); char * _plug_get_copyright(struct arglist*); char * _plug_get_fname(struct arglist *); - +int _plug_get_category(struct arglist * desc); +void _add_plugin_preference(struct arglist *prefs, const char *p_name, + const char *name, const char *type, + const char *defaul); #endif --- libnessus/proctitle.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/proctitle.c 2003-02-27 03:23:26.000000000 +0000 @@ -76,8 +76,7 @@ static char buf[SPT_BUFSIZE]; static char buf2[SPT_BUFSIZE+20]; va_list param; - char *t; - + /* print the argument string */ va_start(param, fmt); #if HAVE_VNSPRINTF --- libnessus/services.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/services.c 2003-02-27 03:13:49.000000000 +0000 @@ -36,9 +36,12 @@ /* IMPORTANT ! Some options are defined in services.h */ static int -cmp_ns_svc(struct nessus_service *p1, - struct nessus_service *p2) +cmp_ns_svc(const void *v1, + const void *v2) { + const struct nessus_service *p1 = v1; + const struct nessus_service *p2 = v2; + return p1->ns_port - p2->ns_port; } --- libnessus/services1.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/services1.c 2003-02-27 03:23:13.000000000 +0000 @@ -41,7 +41,7 @@ int port; /* 2 * port + proto_idx (0 = tcp, 1 = udp) */ char name[32]; /* Debug */ - char *filename;; + char *filename; int line; }; @@ -122,10 +122,10 @@ { static int flag = 0; char *p; - int l, last_port, error_flag = 0, rebuild = 0; + int l, error_flag = 0, rebuild = 0; char nmap_svc_path[MAXPATHLEN]; #define N_SVC_F 5 - struct my_svc svc[N_SVC_F], *psvc; + struct my_svc svc[N_SVC_F]; int nf = 0, i, j, prev_p; FILE *fpT = NULL, *fpU = NULL, *fpTXT = NULL; struct nessus_service ness_svc; @@ -329,7 +329,7 @@ if (fwrite(&ness_svc, sizeof(ness_svc), 1, fpT) < 1) { perror("fwrite"); - error_flag; + error_flag ++; } } } --- libnessus/store.c.orig 2003-02-27 02:53:55.000000000 +0000 +++ libnessus/store.c 2003-02-27 03:25:30.000000000 +0000 @@ -250,7 +250,6 @@ char desc_file[PATH_MAX+1]; char plug_file[PATH_MAX+1]; char * str; - struct stat a, b; char store_dir[PATH_MAX+1]; struct plugin p; struct pprefs pp[MAX_PREFS]; @@ -346,10 +345,10 @@ plug.magic = MAGIC; plug.id = _plug_get_id(plugin); e = safe_copy(path, plug.path, sizeof(plug.path), path, "path"); - if(e < 0)return; + if(e < 0)return 0; e = safe_copy(md5, plug.md5, sizeof(plug.md5), path, "md5"); - if(e < 0)return; + if(e < 0)return 0; plug.timeout = _plug_get_timeout(plugin); @@ -357,67 +356,67 @@ str = _plug_get_name(plugin); e = safe_copy(str, plug.name, sizeof(plug.name), path, "name"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_version(plugin); e = safe_copy(str, plug.version, sizeof(plug.version), path, "version"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_summary(plugin); e = safe_copy(str, plug.summary, sizeof(plug.summary), path, "summary"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_description(plugin); e = safe_copy(str, plug.description, sizeof(plug.description), path, "description"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_copyright(plugin); e = safe_copy(str, plug.copyright, sizeof(plug.copyright), path, "copyright"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_family(plugin); e = safe_copy(str, plug.family, sizeof(plug.family), path, "family"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_cve_id(plugin); e = safe_copy(str, plug.cve_id, sizeof(plug.cve_id), path, "cve_id"); - if(e < 0)return; + if(e < 0)return 0; str = _plug_get_bugtraq_id(plugin); e = safe_copy(str, plug.bid, sizeof(plug.bid), path, "bugtraq id"); - if(e < 0)return; + if(e < 0)return 0; arglist = _plug_get_deps(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.dependencies, sizeof(plug.dependencies), path, "dependencies"); efree(&str); - if(e < 0)return; + if(e < 0)return 0; arglist = _plug_get_required_keys(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_keys, sizeof(plug.required_keys), path, "required keys"); efree(&str); - if(e < 0)return; + if(e < 0)return 0; arglist = _plug_get_excluded_keys(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.excluded_keys, sizeof(plug.excluded_keys), path, "excluded_keys"); efree(&str); - if(e < 0)return; + if(e < 0)return 0; arglist = _plug_get_required_ports(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_ports, sizeof(plug.required_ports), path, "required ports"); efree(&str); - if(e < 0)return; + if(e < 0)return 0; arglist = _plug_get_required_udp_ports(plugin); str = arglist2str(arglist); e = safe_copy(str, plug.required_udp_ports, sizeof(plug.required_udp_ports), path, "required udp ports"); efree(&str); - if(e < 0)return; + if(e < 0)return 0; prefs = arg_get_value(plugin, "preferences"); @@ -439,18 +438,18 @@ str[0] = '\0'; name = str + 1; e = safe_copy(type, pp[num_plugin_prefs].type, sizeof(pp[num_plugin_prefs].type), path, "preference-type"); - if(e < 0)return; + if(e < 0)return 0; e = safe_copy(name, pp[num_plugin_prefs].name, sizeof(pp[num_plugin_prefs].name), path, "preference-name"); - if(e < 0)return; + if(e < 0)return 0; e = safe_copy(dfl, pp[num_plugin_prefs].dfl, sizeof(pp[num_plugin_prefs].dfl), path, "preference-default"); - if(e < 0)return; + if(e < 0)return 0; num_plugin_prefs ++; if(num_plugin_prefs >= MAX_PREFS) { fprintf(stderr, "%s: too many preferences\n", path); - return; + return 0; } _add_plugin_preference(prefs, p_name, name, type, dfl); str[0] = '/'; @@ -464,7 +463,7 @@ fd = open(desc_file, O_RDWR|O_CREAT|O_TRUNC, 0644); if(fd < 0) { - return; + return 0; } if(write(fd, &plug, sizeof(plug)) < 0) --- libpcap-nessus/lbl/gnuc.h.orig 2003-02-27 02:53:55.000000000 +0000 +++ libpcap-nessus/lbl/gnuc.h 2003-02-27 04:21:34.000000000 +0000 @@ -21,23 +21,30 @@ * * For example: * - * __dead void foo(void) __attribute__((volatile)); + * __dead void foo(void) __attribute__((noreturn)); + * + * NOTE: starting GCC 2.5, __attribute((noreturn)) took the place + * of the volatile qualifier on the return type. * */ #ifdef __GNUC__ -#ifndef __dead -#define __dead volatile -#endif -#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) -#ifndef __attribute__ -#define __attribute__(args) -#endif -#endif +# ifndef __dead +# define __dead volatile +# endif +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) +# ifndef __attribute__ +# define __attribute__(args) +# endif +# else +# undef __dead /* don't need it for >= 2.5 */ +# endif #else -#ifndef __dead -#define __dead -#endif -#ifndef __attribute__ -#define __attribute__(args) +# ifndef __attribute__ +# define __attribute__(args) +# endif #endif + +/* be sure this is always defined one way or the other */ +#ifndef __dead +# define __dead /*nothing*/ #endif --- libpcap-nessus/gencode.h.orig 2003-02-27 02:53:55.000000000 +0000 +++ libpcap-nessus/gencode.h 2003-02-27 03:10:08.000000000 +0000 @@ -161,10 +161,8 @@ struct block *gen_inbound(int); void bpf_optimize(struct block **); -#if __STDC__ __dead void bpf_error(const char *, ...) - __attribute__((volatile, format (printf, 1, 2))); -#endif + __attribute__((noreturn, format (printf, 1, 2))); void finish_parse(struct block *); char *sdup(const char *);