$OpenBSD: patch-src_remap_c,v 1.1 2012/09/26 00:04:09 brad Exp $

- Initialize epos
- Pointer validation fixing

--- src/remap.c.orig	Wed Sep  5 14:20:01 2012
+++ src/remap.c	Wed Sep  5 14:20:08 2012
@@ -62,6 +62,9 @@ struct remap_s {
 
 static remap_t* remap_new( char *title) {
     remap_t *map = malloc( sizeof(remap_t));
+    if (map == NULL)
+	return NULL;
+
     map->title = strdup(title);
     map->maxblocks = 0;
     map->nblocks = 0;
@@ -139,8 +142,10 @@ static void remap_add_node( remap_t *map, block_t bloc
     } else {
         /* new block */
 	if (map->nblocks >= map->maxblocks) {
+	    if ((map->blocks = realloc( map->blocks, sizeof( block_t)*( map->maxblocks + 20))) == NULL)
+		return;
+
 	    map->maxblocks += 20;
-	    map->blocks = realloc( map->blocks, sizeof( block_t)*map->maxblocks);
 	}
 	n = map->nblocks++;
 	while (n > 0 && compare_block( &block, &map->blocks[ n-1]) < 0) {
@@ -155,10 +160,12 @@ static int parseblock(char *buf, int *dom, int *tt, in
 		      unsigned long *start, unsigned long *end) {
     long tmp;
     char *tok;
-    char *epos;
+    char *epos = NULL;
     char *marker[]={"domain", "title", "program", "start", "end"};
     int st = 0;
-    tok = strtok( buf, " ");
+    if ((tok = strtok( buf, " ")) == NULL)
+        return st;
+
     while (st < 5) {
         if (strcmp(tok, marker[st])) return -st-1000;
         tok = strtok( NULL, " ");
@@ -183,7 +190,7 @@ static int parseblock(char *buf, int *dom, int *tt, in
 		break;
 	}
 	st++;
-        tok = strtok( NULL, " ");
+        if (!(tok = strtok( NULL, " "))) return -st-2000;
     }
     return st;
 }
@@ -214,7 +221,12 @@ remap_t* remap_loadmap( char *title) {
     }
 
     /* Load the map file */
-    map = remap_new( title);
+    if ((map = remap_new( title)) == NULL) {
+	fprintf(MSG_OUT, "libdvdnav: Unable to load map '%s'\n", title);
+        fclose(fp);
+	return NULL;
+    }
+
     while (fgets( buf, sizeof(buf), fp) != NULL) {
         if (buf[0] == '\n' || buf[0] == '#' || buf[0] == 0) continue;
         if (strncasecmp( buf, "debug", 5) == 0) {
