From 1d99026dbcf73d9bcf193ed15f87e0b3451ec7e2 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 20 Nov 2015 03:12:07 +0000 Subject: [PATCH] enhanced awk to detected divide-by-zero error when folding constans --- qse/lib/awk/parse.c | 17 ++++++++++++++++- qse/lib/http/httpd-std.c | 7 +++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/qse/lib/awk/parse.c b/qse/lib/awk/parse.c index 758aa4c7..61a0cf30 100644 --- a/qse/lib/awk/parse.c +++ b/qse/lib/awk/parse.c @@ -3364,6 +3364,12 @@ static int fold_constants_for_binop ( break; case QSE_AWK_BINOP_DIV: + if (((qse_awk_nde_int_t*)right)->val == 0) + { + qse_awk_seterrnum (awk, QSE_AWK_EDIVBY0, QSE_NULL); + return QSE_NULL; + } + if (INT_BINOP_INT(left,%,right)) { folded->r = (qse_awk_flt_t)((qse_awk_nde_int_t*)left)->val / @@ -3371,8 +3377,17 @@ static int fold_constants_for_binop ( fold = QSE_AWK_NDE_FLT; break; } - /* fall through here */ + + folded->l = INT_BINOP_INT(left,/,right); + break; + case QSE_AWK_BINOP_IDIV: + if (((qse_awk_nde_int_t*)right)->val == 0) + { + qse_awk_seterrnum (awk, QSE_AWK_EDIVBY0, QSE_NULL); + return QSE_NULL; + } + folded->l = INT_BINOP_INT(left,/,right); break; diff --git a/qse/lib/http/httpd-std.c b/qse/lib/http/httpd-std.c index 01d8908c..6c5d47e0 100644 --- a/qse/lib/http/httpd-std.c +++ b/qse/lib/http/httpd-std.c @@ -1174,11 +1174,14 @@ static int server_accept ( * the same addresses. however, the port number may be different * as a typical TPROXY rule is set to change the port number. * However, this check is fragile if the server port number is - * set to 0. */ + * set to 0. + * + * Take note that if the TPROXY rule doesn't change the port + * number the above assumption gets wrong. so it won't be able + * to handle such a TPROXYed packet without port transformation. */ client->status |= QSE_HTTPD_CLIENT_INTERCEPTED; } #if 0 -/* TODO: how to set intercepted when TPROXY is used? */ else if ((client->initial_ifindex = resolve_ifindex (fd, client->local_addr)) <= -1) { /* the local_address is not one of a local address.