Avoid undefined results when the parameter is out of range.
[openssl.git] / crypto / stack / stack.c
index 1d2b47ee678d3caa25d9275fb5d5247c337ec50a..821b6caca5227ff249b8dc4859e9d4baaa0a3af8 100644 (file)
@@ -307,7 +307,7 @@ int sk_num(const STACK *st)
 
 char *sk_value(const STACK *st, int i)
 {
-       if(st == NULL) return NULL;
+       if(!st || (i < 0) || (i >= st->num)) return NULL;
        return st->data[i];
 }