Skip to content

Commit

Permalink
validate the number of log params match
Browse files Browse the repository at this point in the history
the number of %'s in the format string
  • Loading branch information
erankor committed Jan 29, 2017
1 parent d4a804f commit 5b3db6b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ngx_http_vod_request_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ ngx_http_vod_parse_uri_path(
if (rc != NGX_OK)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"ngx_http_vod_parse_uri_path: ngx_http_vod_parse_multi_uri failed", rc);
"ngx_http_vod_parse_uri_path: ngx_http_vod_parse_multi_uri failed %i", rc);
return rc;
}

Expand Down Expand Up @@ -994,15 +994,15 @@ ngx_http_vod_parse_uri_path(
if (rc != NGX_OK)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"ngx_http_vod_parse_uri_path: ngx_http_vod_merge_string_parts failed", rc);
"ngx_http_vod_parse_uri_path: ngx_http_vod_merge_string_parts failed %i", rc);
return rc;
}

rc = ngx_http_vod_extract_uri_params(r, params_hash, &cur_uri, cur_sequence, &clip_id, cur_source, &cur_clip);
if (rc != NGX_OK)
{
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"ngx_http_vod_parse_uri_path: ngx_http_vod_extract_uri_params failed", rc);
"ngx_http_vod_parse_uri_path: ngx_http_vod_extract_uri_params failed %i", rc);
return rc;
}

Expand Down
30 changes: 29 additions & 1 deletion test/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
import re
import os

def countArgs(argsSpec):
result = 0
parentCount = 0
for curCh in argsSpec:
if curCh == '(':
parentCount += 1
elif curCh == ')':
parentCount -= 1
elif curCh == ',' and parentCount == 0:
result += 1
return result

def validateLogParams(fileName, fileData):
logBlock = None
for curLine in fileData.split('\n'):
if re.match('^\s*(?:ngx|vod)_log_(?:debug|error)', curLine):
logBlock = ''
if logBlock == None:
continue
logBlock += curLine.strip()
if logBlock.count('(') > logBlock.count(')'):
continue
logMessage = logBlock[logBlock.find('"'):logBlock.rfind('"')]
args = logBlock[logBlock.rfind('"'):]
if countArgs(args) != logMessage.count('%') + logMessage.count('%*'):
print logBlock
logBlock = None

if len(sys.argv) < 2:
print 'Usage:\n\t%s <nginx-vod code root> [<error log file>]' % os.path.basename(__file__)
sys.exit(1)
Expand All @@ -18,9 +46,9 @@
if os.path.splitext(name)[1] != '.c':
continue
fileData = file(os.path.join(root, name), 'rb').read()
validateLogParams(name, fileData)
for curLog in re.findall('(?:ngx|vod)_log_(?:debug|error)[^\(]*\([^\)]+\)', fileData):
logMessage = curLog.split(',')[3].strip()

if logMessage.endswith('")'):
logMessage = logMessage[:-1]
if logMessage.endswith('"'):
Expand Down
2 changes: 1 addition & 1 deletion vod/mp4/mp4_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ mp4_parser_parse_elst_atom(atom_info_t* atom_info, metadata_parse_context_t* con
if (entries > 2)
{
vod_log_error(VOD_LOG_ERR, context->request_context->log, 0,
"mp4_parser_parse_elst_atom: unsupported edit - atom has %uD entries");
"mp4_parser_parse_elst_atom: unsupported edit - atom has %uD entries", entries);
}

if (atom->version[0] == 1)
Expand Down

0 comments on commit 5b3db6b

Please sign in to comment.