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

corosync-fplay: Check incorrect idx and cycle

If idx is too large, segfault can happen. Also cycle is now detected
properly.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse 13 лет назад
Родитель
Сommit
d8761bae84
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      tools/corosync-fplay.c

+ 13 - 0
tools/corosync-fplay.c

@@ -350,6 +350,8 @@ static unsigned int printer_subsys_count =
 
 static uint32_t g_record[G_RECORD_SIZE];
 
+static int file_rewind = 0;
+
 /*
  * Copy record, dealing with wrapping
  */
@@ -357,6 +359,11 @@ static int logsys_rec_get (int rec_idx) {
 	uint32_t rec_size;
 	int firstcopy, secondcopy;
 
+	if (rec_idx >= flt_data_size) {
+		fprintf (stderr, "rec_idx too large. Input file is probably corrupted.\n");
+		exit (EXIT_FAILURE);
+	}
+
 	rec_size = flt_data[rec_idx];
 
 	firstcopy = rec_size;
@@ -373,6 +380,12 @@ static int logsys_rec_get (int rec_idx) {
 	}
 
 	if (firstcopy + rec_idx > flt_data_size) {
+		if (file_rewind) {
+			fprintf (stderr, "file rewind for second time (cycle). Input file is probably corrupted.\n");
+			exit (EXIT_FAILURE);
+		}
+
+		file_rewind = 1;
 		firstcopy = flt_data_size - rec_idx;
 		secondcopy -= firstcopy - rec_size;
 	}