tests/hd-geo-test: Don't pass NULL to unlink()
PATCH 1/1 tests/hd-geo-test: Don't pass NULL to unlink()
The unlink() function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.
--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/hd-geo-test.c +3 -1
@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }return ret;
Signature · 1 line
2.7.4
Quoted 13 lines · Peter Maydell
The
unlink()function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.Signed-off-by Peter Maydell <[email protected]>--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/hd-geo-test.c +0
-0
tests/hd-geo-test.c int main(int argc, char **argv) · line 424
Quoted 10 lines
tests/hd-geo-test.c +3
-1@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }return ret;
And what terrible, terrible things unlink()'s going to do when passed a null pointer? Turns out the same scary terrible thing it has always
done: return -1 and set errno = EFAULT.
Quoted 24 lines · Markus Armbruster
Quoted 22 lines · Peter Maydell
The
unlink()function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.Signed-off-by Peter Maydell <[email protected]>--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/hd-geo-test.c +3
-1@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }
Quoted 5 lines
tests/hd-geo-test.c int main(int argc, char **argv) · line 424
Quoted 1 line
tests/hd-geo-test.c +0
-0return ret;And what terrible, terrible things unlink()'s going to do when passed a null pointer? Turns out the same scary terrible thing it has always
done: return -1 and set errno = EFAULT.
Feel free to send a bug report to the glibc folks saying they shouldn't have marked it as __nonnull((1)).
thanks
-- PMM
Ping?
thanks
-- PMM
Quoted 25 lines · Peter Maydell
The
unlink()function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.Signed-off-by Peter Maydell <[email protected]>--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/hd-geo-test.c +3
-2@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }return ret; --2.7.4
Quoted 5 lines · Peter Maydell
Ping?
thanks
-- PMM
Not sure who this belongs to; I can queue it up alongside some IDE and FDC stuff in the future if you like.
--js
Quoted 28 lines · Peter Maydell
Quoted 25 lines
The
unlink()function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.Signed-off-by Peter Maydell <[email protected]>--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/hd-geo-test.c +3
-2@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }return ret; --2.7.4
Signature · 1 line
—js
Quoted 6 lines · John Snow
Quoted 2 lines · Peter Maydell
Ping?
Not sure who this belongs to; I can queue it up alongside some IDE and FDC stuff in the future if you like.
I can apply it directly; I'd just like review :-)
thanks
-- PMM
John Snow
Reviewed-byQuoted 10 lines · Peter Maydell
Quoted 6 lines · John Snow
Quoted 2 lines · Peter Maydell
Ping?
Not sure who this belongs to; I can queue it up alongside some IDE and FDC stuff in the future if you like.
I can apply it directly; I'd just like review :-)
lol! yes, of course you can...
Quoted 3 lines
thanks
-- PMM
Well, I know some have religious arguments against making sanitizers happy, but that's not my religion.
If some systems appear to think that unlink must take a nonnull argument, I think that's a bug -- but making the sanitizer happy doesn't cost us much either IMO.
(And it's /just/ a test.)
So, personally:
Quoted 6 lines · John Snow
Well, I know some have religious arguments against making sanitizers happy, but that's not my religion.
If some systems appear to think that unlink must take a nonnull argument, I think that's a bug -- but making the sanitizer happy doesn't cost us much either IMO.
POSIX doesn't mandate that unlink() handles NULL, so it's just a quality-of-implementation issue in the library to handle it without barfing (or conversely a QoI issue to over-conservatively mark it as requires-nonnull in the system headers, if you like).
In any case my general view with all these sanitizing/lint tools is that it's usually worth taking a few unnecessary-looking detours in order to get to zero-warnings so you can easily flag up when new code triggers a warning (which could well be a bug).
Quoted 5 lines
(And it's /just/ a test.)
So, personally:
Reviewed-by John Snow <[email protected]>
Thanks!
-- PMM
Peter Maydell
AppliedQuoted 13 lines · Peter Maydell
The
unlink()function doesn't accept a NULL pointer, so don't pass it one. Spotted by the clang sanitizer.Signed-off-by Peter Maydell <[email protected]>--- tests/hd-geo-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/hd-geo-test.c +0
-0
tests/hd-geo-test.c int main(int argc, char **argv) · line 424
Quoted 10 lines
tests/hd-geo-test.c +3
-1@@ -416,7 +416,9 @@ int main(int argc, char **argv) ret =g_test_run ();for (i =0 ; i < backend_last; i++) { -unlink (img_file_name[i]); +if (img_file_name[i]) { +unlink (img_file_name[i]); + } }return ret;
Applied to master, thanks.
-- PMM