Просмотр исходного кода

Merge branch 'warnings' of https://github.com/tartina/nagios-plugins into tartina-warnings

Sebastian Wolf 2 лет назад
Родитель
Сommit
8baa8e4d9f
7 измененных файлов с 27 добавлено и 22 удалено
  1. 7 5
      lib/parse_ini.c
  2. 6 4
      lib/utils_base.c
  3. 4 4
      plugins-root/check_icmp.c
  4. 4 4
      plugins/check_disk.c
  5. 2 2
      plugins/check_load.c
  6. 2 1
      plugins/check_ntp_peer.c
  7. 2 2
      plugins/check_smtp.c

+ 7 - 5
lib/parse_ini.c

@@ -118,7 +118,7 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in
 np_arg_list* np_get_defaults(const char *locator, const char *default_section){
 	FILE *inifile=NULL;
 	np_arg_list *defaults=NULL;
-	np_ini_info i;
+	np_ini_info i = {NULL, NULL};
 	struct stat fstat;
 	bool is_suid_set = np_suid();
 
@@ -324,11 +324,13 @@ static int add_option(FILE *f, np_arg_list **optlst){
 	optnew->arg=malloc(cfg_len+1);
 	/* 1-character params needs only one dash */
 	if(opt_len==1) {
-		strncpy(&optnew->arg[read_pos], "-", 1);
-		read_pos+=1;
+		optnew->arg[read_pos]='-';
+		++read_pos;
 	} else {
-		strncpy(&optnew->arg[read_pos], "--", 2);
-		read_pos+=2;
+		optnew->arg[read_pos]='-';
+		++read_pos;
+		optnew->arg[read_pos]='-';
+		++read_pos;
 	}
 	strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len;
 	if(value) {

+ 6 - 4
lib/utils_base.c

@@ -332,6 +332,7 @@ int np_warn_if_not_root(void) {
 char *np_extract_value(const char *varlist, const char *name, char sep) {
 	char *tmp=NULL, *value=NULL;
 	int i;
+	size_t varlistlen;
 
 	while (1) {
 		/* Strip any leading space */
@@ -356,10 +357,11 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
 					value[tmp-varlist] = '\0';
 				} else {
 					/* Value is delimited by a \0 */
-					if (!strlen(varlist)) continue;
-					value = (char *)calloc(1, strlen(varlist) + 1);
-					strncpy(value, varlist, strlen(varlist));
-					value[strlen(varlist)] = '\0';
+					varlistlen = strlen(varlist);
+					if (!varlistlen) continue;
+					value = (char *)calloc(1, varlistlen + 1);
+					strncpy(value, varlist, varlistlen);
+					value[varlistlen] = '\0';
 				}
 				break;
 			}

+ 4 - 4
plugins-root/check_icmp.c

@@ -969,12 +969,12 @@ static void run_checks() {
 /*		icmp header                : 28 bytes */
 /*		icmp echo reply            : the rest */
 static int wait_for_reply(int sock, u_int t) {
-  int n, hlen;
+  int n, hlen = 0;
   static unsigned char buf[4096];
   struct sockaddr_storage resp_addr;
   union ip_hdr *ip;
   union icmp_packet packet;
-  struct rta_host *host;
+  struct rta_host *host = NULL;
   struct icmp_ping_data data;
   struct timeval wait_start, now;
   u_int tdiff, i, per_pkt_wait;
@@ -1700,8 +1700,8 @@ static u_int get_timevaldiff(struct timeval *early, struct timeval *later) {
 
 static int add_target_ip(char *arg, struct sockaddr_storage *in) {
   struct rta_host *host;
-  struct sockaddr_in *sin, *host_sin;
-  struct sockaddr_in6 *sin6, *host_sin6;
+  struct sockaddr_in *sin = NULL, *host_sin;
+  struct sockaddr_in6 *sin6 = NULL, *host_sin6;
 
   if (address_family == AF_INET) {
     sin = (struct sockaddr_in *)in;

+ 4 - 4
plugins/check_disk.c

@@ -233,7 +233,7 @@ main (int argc, char **argv)
   int temp_result2;
 
   struct mount_entry *me;
-  struct mount_entry *last_me;
+  struct mount_entry *last_me = NULL;
   struct fs_usage fsp, tmpfsp;
   struct parameter_list *temp_list, *path;
 
@@ -488,11 +488,11 @@ main (int argc, char **argv)
           const char *free_pct_str = &human_disk_entry->free_pct_str[0];
           const char *disk_result_str = state_text(human_disk_entry->disk_result);
           const char *avail_bytes_str = human_readable(human_disk_entry->avail_bytes, &human_buf[0], human_opts, 1, 1);
-          strncpy(&human_disk_entry->avail_bytes_str[0], avail_bytes_str, sizeof(human_disk_entry->avail_bytes_str));
+          strncpy(human_disk_entry->avail_bytes_str, avail_bytes_str, sizeof(human_disk_entry->avail_bytes_str - 1));
           const char *total_bytes_str = human_readable(human_disk_entry->total_bytes, &human_buf[0], human_opts, 1, 1);
-          strncpy(&human_disk_entry->total_bytes_str[0], total_bytes_str, sizeof(human_disk_entry->total_bytes_str));
+          strncpy(human_disk_entry->total_bytes_str, total_bytes_str, sizeof(human_disk_entry->total_bytes_str - 1));
 
-          strncpy(&human_disk_entry->disk_result_str[0], disk_result_str, sizeof(human_disk_entry->disk_result_str));
+          strncpy(human_disk_entry->disk_result_str, disk_result_str, sizeof(human_disk_entry->disk_result_str - 1));
           if (human_column_widths.free_pct < strlen(free_pct_str))       human_column_widths.free_pct = strlen(free_pct_str);
           if (human_column_widths.avail_bytes < strlen(avail_bytes_str)) human_column_widths.avail_bytes = strlen(avail_bytes_str);
           if (human_column_widths.total_bytes < strlen(total_bytes_str)) human_column_widths.total_bytes = strlen(total_bytes_str);

+ 2 - 2
plugins/check_load.c

@@ -101,7 +101,7 @@ get_threshold(char *arg, double *th)
 int
 main (int argc, char **argv)
 {
-	int result;
+	int result = 0;
 	int i, j;
 	long numcpus;
 
@@ -356,7 +356,7 @@ int cmpstringp(const void *p1, const void *p2) {
 #ifdef PS_USES_PROCETIME
 	char procetime[MAX_INPUT_BUFFER] = { '\0' };
 #endif /* PS_USES_PROCETIME */
-	char *procprog;
+	char *procprog = NULL;
 	char *proc_cgroup_hierarchy;
 	int pos;
 	sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST);

+ 2 - 1
plugins/check_ntp_peer.c

@@ -560,7 +560,8 @@ char *perfd_truechimers (int num_truechimers)
 }
 
 int main(int argc, char *argv[]){
-	int result, offset_result, stratum, num_truechimers, oresult, jresult, sresult, tresult;
+	int result, offset_result, stratum, num_truechimers, oresult;
+	int jresult = STATE_OK, sresult = STATE_OK, tresult = STATE_OK;
 	double offset=0, jitter=0;
 	char *result_line, *perfdata_line;
 

+ 2 - 2
plugins/check_smtp.c

@@ -584,7 +584,7 @@ process_arguments (int argc, char **argv)
 					     _("Could not realloc() units [%d]\n"), ncommands);
 			}
 			commands[ncommands] = (char *) malloc (sizeof(char) * 255);
-			strncpy (commands[ncommands], optarg, 255);
+			strncpy (commands[ncommands], optarg, 254);
 			ncommands++;
 			break;
 		case 'R':									/* server responses */
@@ -596,7 +596,7 @@ process_arguments (int argc, char **argv)
 					     _("Could not realloc() units [%d]\n"), nresponses);
 			}
 			responses[nresponses] = (char *) malloc (sizeof(char) * 255);
-			strncpy (responses[nresponses], optarg, 255);
+			strncpy (responses[nresponses], optarg, 254);
 			nresponses++;
 			break;
 		case 'c':									/* critical time threshold */