Index: core/al/user/ual_av.c
===================================================================
--- core/al/user/ual_av.c	(revision 1521)
+++ core/al/user/ual_av.c	(working copy)
@@ -58,6 +58,16 @@
 	uint16_t			i;
 
 	ci_ca_lock_attr( p_ci_ca );
+
+	// sanity check
+	if (port_num == 0 || port_num > p_ci_ca->p_user_attr->num_ports)
+	{
+		AL_PRINT(TRACE_LEVEL_WARNING ,AL_DBG_AV,
+			("UAL_GET_GID_INDEX: invalid port number specified (%d)\n", port_num) );
+		status = IB_INVALID_PORT;
+		goto out;
+	}
+
 	p_port_attr = &p_ci_ca->p_user_attr->p_port_attr[port_num];
 	for( i = 0; i < p_port_attr->num_gids; i++ )
 	{
@@ -68,6 +78,8 @@
 			break;
 		}
 	}
+
+out:
 	ci_ca_unlock_attr( p_ci_ca );
 
 	return status;
