pmem / pmemfile

Userspace implementation of file APIs using persistent memory.
Other
34 stars 21 forks source link

posix: don't rely on undefined behavior of signed integer overflow #321

Closed marcinslusarz closed 7 years ago

marcinslusarz commented 7 years ago

Fixes issue reported by ASAN: src/libpmemfile-posix/lseek.c:283:39: runtime error: signed integer overflow: 3 + 9223372036854775807 cannot be represented in type 'long' SUMMARY: AddressSanitizer: undefined-behavior /src/libpmemfile-posix/lseek.c:283:39 in src/libpmemfile-posix/lseek.c:294:39: runtime error: signed integer overflow: 9 + 9223372036854775806 cannot be represented in type 'long' SUMMARY: AddressSanitizer: undefined-behavior src/libpmemfile-posix/lseek.c:294:39 in


This change is Reviewable

krzycz commented 7 years ago
:lgtm:

Reviewed 1 of 1 files at r1. Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

codecov-io commented 7 years ago

Codecov Report

Merging #321 into master will increase coverage by 0.05%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #321      +/-   ##
==========================================
+ Coverage    77.5%   77.55%   +0.05%     
==========================================
  Files          90       90              
  Lines       13811    13816       +5     
  Branches     1994     1995       +1     
==========================================
+ Hits        10704    10715      +11     
+ Misses       2383     2381       -2     
+ Partials      724      720       -4
Impacted Files Coverage Δ
src/libpmemfile-posix/lseek.c 89.79% <100%> (+0.28%) :arrow_up:
tests/posix/mt/mt.cpp 85.41% <0%> (-1.05%) :arrow_down:
src/libpmemfile-posix/file.c 66.85% <0%> (+0.09%) :arrow_up:
src/libpmemfile-posix/dir.c 82.06% <0%> (+0.24%) :arrow_up:
src/libpmemfile-posix/utils.c 73.43% <0%> (+0.42%) :arrow_up:
src/libpmemfile-posix/rename.c 91.93% <0%> (+1.2%) :arrow_up:
src/libpmemfile-posix/read.c 91.83% <0%> (+1.49%) :arrow_up:
src/libpmemfile/syscall_early_filter.c 80% <0%> (+20%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3f1d2c4...763fb05. Read the comment docs.

sarahjelinek commented 7 years ago
:lgtm:

Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

GBuella commented 7 years ago

Well, that cast is implementation defined instead of undefined, but I guess UBSAN and ASAN only look for UB. Anyway, it would have been cleaner to not rely on implementation either.