Add NULL guard in freerules function. Use strncat and strncpy to ensure the buffer lengths are adhered to.
While at it, mark most of functions static, as they are not used outside the module.