$OpenBSD: patch-src_input_libreal_asmrp_c,v 1.2 2007/01/02 19:42:59 robert Exp $
--- src/input/libreal/asmrp.c.orig	Fri Aug 27 14:34:16 2004
+++ src/input/libreal/asmrp.c	Mon Jan  1 15:27:04 2007
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include "asmrp.h"
 
 #define LOG_MODULE "asmrp"
 #define LOG_VERBOSE
@@ -604,7 +605,7 @@ static int asmrp_rule (asmrp_t *p) {
   return ret;
 }
 
-static int asmrp_eval (asmrp_t *p, int *matches) {
+static int asmrp_eval (asmrp_t *p, int *matches, int matchsize) {
 
   int rule_num, num_matches;
 
@@ -613,13 +614,15 @@ static int asmrp_eval (asmrp_t *p, int *
   asmrp_get_sym (p);
 
   rule_num = 0; num_matches = 0;
-  while (p->sym != ASMRP_SYM_EOF) {
+  while (p->sym != ASMRP_SYM_EOF && num_matches < matchsize -1) {
 
     if (asmrp_rule (p)) {
       lprintf ("rule #%d is true\n", rule_num);
 
-      matches[num_matches] = rule_num;
-      num_matches++;
+      if(num_matches < MAX_RULEMATCHES - 1)
+        matches[num_matches++] = rule_num;
+      else
+        printf("Ignoring matched asm rule %d, too many matched rules.\n", rule_num);
     }
 
     rule_num++;
@@ -629,7 +632,7 @@ static int asmrp_eval (asmrp_t *p, int *
   return num_matches;
 }
 
-int asmrp_match (const char *rules, int bandwidth, int *matches) {
+int asmrp_match (const char *rules, int bandwidth, int *matches, int matchsize) {
 
   asmrp_t *p;
   int      num_matches;
@@ -641,7 +644,7 @@ int asmrp_match (const char *rules, int 
   asmrp_set_id (p, "Bandwidth", bandwidth);
   asmrp_set_id (p, "OldPNMPlayer", 0);
 
-  num_matches = asmrp_eval (p, matches);
+  num_matches = asmrp_eval (p, matches, matchsize);
 
   asmrp_dispose (p);
 
