aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-inlines.h
diff options
context:
space:
mode:
authorTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>2023-09-13 11:02:36 +0200
committerTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>2023-10-17 17:31:20 +0200
commit998a4f589d68503f79695f180fdf1742eeb0a39d (patch)
tree618e2906f5b949c620ddba79664f7f32a14d25bc /libctf/ctf-inlines.h
parent22bfda88f898e8ce11a622a888bd3f1daf86114a (diff)
downloadfsf-binutils-gdb-998a4f589d68503f79695f180fdf1742eeb0a39d.zip
fsf-binutils-gdb-998a4f589d68503f79695f180fdf1742eeb0a39d.tar.gz
fsf-binutils-gdb-998a4f589d68503f79695f180fdf1742eeb0a39d.tar.bz2
libctf: Sanitize error types for PR 30836
Made sure there is no implicit conversion between signed and unsigned return value for functions setting the ctf_errno value. An example of the problem is that in ctf_member_next, the "offset" value is either 0L or (ctf_id_t)-1L, but it should have been 0L or -1L. The issue was discovered while building a 64 bit ld binary to be executed on the Windows platform. Example object file that demonstrates the issue is attached in the PR. libctf/ Affected functions adjusted. Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com> Co-Authored-By: Yvan ROUX <yvan.roux@foss.st.com>
Diffstat (limited to 'libctf/ctf-inlines.h')
-rw-r--r--libctf/ctf-inlines.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/libctf/ctf-inlines.h b/libctf/ctf-inlines.h
index 6bda68d..84044a1 100644
--- a/libctf/ctf-inlines.h
+++ b/libctf/ctf-inlines.h
@@ -90,6 +90,23 @@ ctf_assert_internal (ctf_dict_t *fp, const char *file, size_t line,
return expr;
}
+static inline int
+ctf_set_errno (ctf_dict_t *fp, int err)
+{
+ fp->ctf_errno = err;
+ /* Don't rely on CTF_ERR here as it will not properly sign extend on 64-bit
+ Windows ABI. */
+ return -1;
+}
+
+static inline ctf_id_t
+ctf_set_typed_errno (ctf_dict_t *fp, int err)
+{
+ fp->ctf_errno = err;
+ return CTF_ERR;
+}
+
+
#ifdef __cplusplus
}
#endif