[icinga-checkins] icinga.org: icinga-core/dev/cgis: classi-ui: fixed sort_icinga_logfiles_by_name() in readlogs. c fails to take NULL pointers into consideration #3398

git at icinga.org git at icinga.org
Fri Nov 9 16:18:16 CET 2012


Module: icinga-core
Branch: dev/cgis
Commit: d174b7413ef523442e746e4767999ca54ee09705
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=d174b7413ef523442e746e4767999ca54ee09705

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Fri Nov  9 16:16:15 2012 +0100

classi-ui: fixed sort_icinga_logfiles_by_name() in readlogs.c fails to take NULL pointers into consideration #3398

refs: #3398

this makes totally sense. kudos for fixing this to crfriend

---

 Changelog      |    1 +
 cgi/readlogs.c |   11 ++++++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Changelog b/Changelog
index e940332..340073b 100644
--- a/Changelog
+++ b/Changelog
@@ -28,6 +28,7 @@ FIXES
 
 * classic ui: fix cmd.cgi does not honor commandpipe location; overwrites from empty environment variable #3418 - MF
 * classic ui: fixed Double-listed host dependencies in host extinfo.cgi #3295 - RB
+* classic ui: fixed sort_icinga_logfiles_by_name() in readlogs.c fails to take NULL pointers into consideration #3398 - CF
 
 CHANGES
 
diff --git a/cgi/readlogs.c b/cgi/readlogs.c
index df7b046..85e0a03 100644
--- a/cgi/readlogs.c
+++ b/cgi/readlogs.c
@@ -58,8 +58,12 @@ int sort_icinga_logfiles_by_name(const void *a_in, const void *b_in) {
 	struct file_data *a = (struct file_data *)a_in;
 	struct file_data *b = (struct file_data *)b_in;
 
-	if (a->file_name == NULL || b->file_name == NULL)
+	if (a->file_name == NULL && b->file_name == NULL)
 		return 0;
+	if (a->file_name != NULL && b->file_name == NULL)
+		return 1;
+	if (a->file_name == NULL && b->file_name != NULL)
+		return -1;
 
 	// year
 	date_a[0]  = a->file_name[13];
@@ -265,14 +269,15 @@ int get_log_entries(logentry **entry_list, logfilter **filter_list, char **error
 		while ((dptr=readdir(dirp)) != NULL) {
 
 			/* filter dir for icinga / nagios log files */
-			if ((strncmp("icinga-",dptr->d_name,7) == 0 || strncmp("nagios-",dptr->d_name,7) == 0 ) && strstr(dptr->d_name, ".log"))
+			if ((strncmp("icinga-",dptr->d_name,7) == 0 || strncmp("nagios-",dptr->d_name,7) == 0 ) &&
+			    strstr(dptr->d_name, ".log") && strlen(dptr->d_name) == 24)
 				files[file_num++].file_name = strdup(dptr->d_name);
 		}
 		closedir(dirp);
 	}
 
 	/* sort log files, newest first */
-	qsort(files, sizeof(files) / sizeof(struct file_data) , sizeof(struct file_data), sort_icinga_logfiles_by_name);
+	qsort((void *)files, file_num, sizeof(struct file_data), sort_icinga_logfiles_by_name);
 
 	/* define which log files to use */
 	for (i=0; i< file_num; i++) {





More information about the icinga-checkins mailing list