diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-04-09 15:46:46 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-04-10 17:07:48 +0000 |
| commit | f2bf6886663c2c4bdc58d126ed3d17f1b85d5f12 (patch) | |
| tree | f64703e590c9d21822ffdfa59ba450744d4a4177 | |
| parent | 19eaed83ec269d117586013015f9eb856d04162d (diff) | |
tools/syz-declextract: handle ints more carefully
It seems that new clang is more picky about asserts for large ints.
It not assert-fails when converting large ints to int64.
Be more careful when converting these to ints.
| -rw-r--r-- | tools/syz-declextract/clangtool/declextract.cpp | 8 | ||||
| -rw-r--r-- | tools/syz-declextract/testdata/scopes.c | 6 | ||||
| -rw-r--r-- | tools/syz-declextract/testdata/scopes.c.info | 2 | ||||
| -rw-r--r-- | tools/syz-declextract/testdata/scopes.c.json | 18 | ||||
| -rw-r--r-- | tools/syz-declextract/testdata/scopes.c.txt | 5 |
5 files changed, 37 insertions, 2 deletions
diff --git a/tools/syz-declextract/clangtool/declextract.cpp b/tools/syz-declextract/clangtool/declextract.cpp index 786f66ca5..2df651e07 100644 --- a/tools/syz-declextract/clangtool/declextract.cpp +++ b/tools/syz-declextract/clangtool/declextract.cpp @@ -494,7 +494,13 @@ int Extractor::alignofType(const Type* T) { return static_cast<int>(Context->get template <typename T> T Extractor::evaluate(const Expr* E) { Expr::EvalResult Res; E->EvaluateAsConstantExpr(Res, *Context); - return static_cast<T>(Res.Val.getInt().getExtValue()); + // TODO: it's unclear what to do if it's not Int (in some cases we see None here). + if (Res.Val.getKind() != APValue::Int) + return 0; + auto val = Res.Val.getInt(); + if (val.isSigned()) + return val.sextOrTrunc(64).getSExtValue(); + return val.zextOrTrunc(64).getZExtValue(); } void Extractor::matchNetlinkPolicy() { diff --git a/tools/syz-declextract/testdata/scopes.c b/tools/syz-declextract/testdata/scopes.c index d53ca391d..57809ae3d 100644 --- a/tools/syz-declextract/testdata/scopes.c +++ b/tools/syz-declextract/testdata/scopes.c @@ -5,6 +5,9 @@ #include "include/syscall.h" #include "include/uapi/file_operations.h" +#define LARGE_UINT (1ull<<63) // this is supposed to overflow int64 +#define LARGE_SINT (20ll<<63) // this is supposed to overflow uint64 + static int scopes_helper(long cmd, long aux) { switch (cmd) { case FOO_IOCTL7: @@ -12,6 +15,9 @@ static int scopes_helper(long cmd, long aux) { case FOO_IOCTL8: __fget_light(aux); break; + case LARGE_UINT: + case LARGE_SINT: + break; } return 0; } diff --git a/tools/syz-declextract/testdata/scopes.c.info b/tools/syz-declextract/testdata/scopes.c.info index 8f18c7352..aeee09ace 100644 --- a/tools/syz-declextract/testdata/scopes.c.info +++ b/tools/syz-declextract/testdata/scopes.c.info @@ -1 +1 @@ -SYSCALL scopes0 func:__do_sys_scopes0 loc:32 access:unknown manual_desc:false auto_desc:true file:scopes.c subsystem:kernel +SYSCALL scopes0 func:__do_sys_scopes0 loc:35 access:unknown manual_desc:false auto_desc:true file:scopes.c subsystem:kernel diff --git a/tools/syz-declextract/testdata/scopes.c.json b/tools/syz-declextract/testdata/scopes.c.json index ab03673b0..b5921869c 100644 --- a/tools/syz-declextract/testdata/scopes.c.json +++ b/tools/syz-declextract/testdata/scopes.c.json @@ -284,6 +284,14 @@ } } ] + }, + { + "arg": 0, + "values": [ + "LARGE_UINT", + "LARGE_SINT" + ], + "loc": 3 } ] } @@ -318,6 +326,16 @@ "name": "FOO_IOCTL8", "filename": "include/uapi/file_operations.h", "value": 25352 + }, + { + "name": "LARGE_SINT", + "filename": "scopes.c", + "value": 0 + }, + { + "name": "LARGE_UINT", + "filename": "scopes.c", + "value": -9223372036854775808 } ], "structs": [ diff --git a/tools/syz-declextract/testdata/scopes.c.txt b/tools/syz-declextract/testdata/scopes.c.txt index fa923fc31..862b01cfd 100644 --- a/tools/syz-declextract/testdata/scopes.c.txt +++ b/tools/syz-declextract/testdata/scopes.c.txt @@ -18,3 +18,8 @@ scopes0$auto_FOO_IOCTL3(x int32, cmd const[FOO_IOCTL3], aux fd) fd scopes0$auto_FOO_IOCTL4(x int32, cmd const[FOO_IOCTL4], aux fd) scopes0$auto_FOO_IOCTL7(x int32, cmd const[FOO_IOCTL7], aux fd) fd scopes0$auto_FOO_IOCTL8(x fd, cmd const[FOO_IOCTL8], aux fd) +scopes0$auto_LARGE_SINT(x int32, cmd const[LARGE_SINT], aux fd) +scopes0$auto_LARGE_UINT(x int32, cmd const[LARGE_UINT], aux fd) + +define LARGE_SINT 0 +define LARGE_UINT -9223372036854775808 |
