[4/4] pppoe-server: improve input validation

Submitted by Jonatan Schlag on June 3, 2017, 11:25 a.m.

Details

Message ID 1496489110-10134-4-git-send-email-jonatan.schlag@ipfire.org
State New
Headers show

Commit Message

Jonatan Schlag June 3, 2017, 11:25 a.m.
We now check if the subnet, the mtu and the max-sessions valud is valid.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
---
 src/hooks/configs/pppoe-server | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/hooks/configs/pppoe-server b/src/hooks/configs/pppoe-server
index 1ef3ba9..6f95212 100644
--- a/src/hooks/configs/pppoe-server
+++ b/src/hooks/configs/pppoe-server
@@ -69,15 +69,30 @@  hook_new() {
 				;;
 			--max-sessions=*)
 				MAX_SESSIONS=$(cli_get_val ${1})
+				if ! isinteger ${MAX_SESSIONS} || ! [ ${MAX_SESSIONS} -ge 0 ]; then
+					error "Invalid value for '--max-session'. This value must be an integer greate or eqal zero."
+					exit ${EXIT_ERROR}
+				fi
 				;;
 			--mtu=*)
 				MTU=$(cli_get_val ${1})
+				if ! mtu_is_valid "ipv4" ${MTU}; then
+					error "Invalid value for '--mtu'. Cannot be larger then 9000 or smaller than 576"
+					exit ${EXIT_ERROR}
+				fi
 				;;
 			--service-name=*)
 				SERVICE_NAME=$(cli_get_val ${1})
 				;;
 			--subnet=*)
 				SUBNET=$(cli_get_val ${1})
+				if ! ipv4_net_is_valid "${SUBNET}"; then
+					error "Invalid IPv4 Subnet ${SUBNET}."
+					exit ${EXIT_ERROR}
+				fi
+				;;
+			*)
+				warning "Ignoring unknown option '${1}'"
 				;;
 		esac
 		shift