From: Dan Carpenter Date: Thu, 19 Dec 2013 11:06:33 +0000 (+0300) Subject: kernel, db: consider x = htonl(10) and x = 10 equivalent. X-Git-Tag: 1.60~461 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/7606a115769d169d3a8975a5387c267f3f174435 kernel, db: consider x = htonl(10) and x = 10 equivalent. Smatch considers network endian data as untrusted. But there are some cases where we do: foo.size = htonl(sizeof(msg)); frob(ntohl(foo.size)); In this case we actually know the value of ntohl(foo.size). Pretending endian data is always CPU endian is ok because Sparse will warn if we using endian data for math. Signed-off-by: Dan Carpenter --- diff --git a/smatch_data/db/fixup_kernel.sh b/smatch_data/db/fixup_kernel.sh index d96d96e6..f2e4966b 100755 --- a/smatch_data/db/fixup_kernel.sh +++ b/smatch_data/db/fixup_kernel.sh @@ -57,6 +57,14 @@ update return_states set return = '0-u32max[<=p2]' where function = '__copy_from /* 64 CPUs aught to be enough for anyone */ update return_states set return = '1-64' where function = 'cpumask_weight'; +/* + * Preserve the value across byte swapping. By the time we use it for math it + * will be byte swapped back to CPU endian. + */ +update return_states set return = '[==p0]' where function = '__fswab64'; +update return_states set return = '[==p0]' where function = '__fswab32'; +update return_states set return = '[==p0]' where function = '__fswab16'; + EOF call_id=$(echo "select distinct call_id from caller_info where function = '__kernel_write';" | sqlite3 smatch_db.sqlite) diff --git a/smatch_data/kernel.no_inline_functions b/smatch_data/kernel.no_inline_functions new file mode 100644 index 00000000..7b2e5e82 --- /dev/null +++ b/smatch_data/kernel.no_inline_functions @@ -0,0 +1,3 @@ +__fswab16 +__fswab32 +__fswab64