summaryrefslogtreecommitdiff
path: root/lib/share.h
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-01-19 08:23:52 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-01-20 08:51:01 +0100
commit942cf12c2f73c4bb13858acc9101b1d644bf7c50 (patch)
tree0478f4aa93712d7b06b39da268aaae9ec102f312 /lib/share.h
parent13bc1ea9bcef34c4beb384549e4be64e341426db (diff)
downloadcurl-942cf12c2f73c4bb13858acc9101b1d644bf7c50.tar.gz
urldata: make magic be the first struct field
By making the `magic` identifier the same size and at the same place within the structs (easy, multi, share), libcurl will be able to more reliably detect and safely error out if an application passes in the wrong handle to APIs. Easier to detect and less likely to cause crashes if done. Such mixups can't be detected at compile-time due to them being typedefed void pointers - unless `CURL_STRICTER` is defined. Closes #6484
Diffstat (limited to 'lib/share.h')
-rw-r--r--lib/share.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/share.h b/lib/share.h
index 01aa9cda5..222e34ba6 100644
--- a/lib/share.h
+++ b/lib/share.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -37,8 +37,12 @@
#define CURL_VOLATILE volatile
#endif
+#define CURL_GOOD_SHARE 0x7e117a1e
+#define GOOD_SHARE_HANDLE(x) ((x) && (x)->magic == CURL_GOOD_SHARE)
+
/* this struct is libcurl-private, don't export details */
struct Curl_share {
+ unsigned int magic; /* CURL_GOOD_SHARE */
unsigned int specifier;
CURL_VOLATILE unsigned int dirty;