[PATCH] Two trivial fixes for Control Flow Integrity support

Vlad Tsyrklevich via xml <[email protected]>
Newsgroups gmane.comp.gnome.lib.xml.general
Message-ID <CALz_-TaeYSWycWqQSBQmQGAs6HaDoy9iZd3-hAnBDqkLWmJz0g@mail.gmail.com>
Hello, I have two small patches to fix function pointer type signature
mismatches in libxml. I've submitted these upstream in chromium [1] as
part of the effort to enable Control Flow Integrity, but it would be
preferable to have them land in libxml itself.

Control Flow Integrity [2] is a security mechanism that checks that
indirect calls only occur to call sites with matching type
information. (As has been mentioned on this list before, some
transpilers like Emscripten also require that function pointers be
called with a type signature matching the called function.)

The patches fix type signature mismatches with xmlNop() and
xmlMemStrdup(). The first patch sets xmlNop() to have the same type
signature as xmlInputReadCallback, which is the only type it's ever
cast to. Under some compiler flags, xmlMemStrdup() is a function
pointer pointing to xmlStrdup() despite a mismatched type signature.
In that case I set it to strdup() instead since it has the correct
type signature and the other xmlMem(Malloc|Realloc|Free) function
pointers around it point directly to the libc implementations as well.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/745034
[2] https://clang.llvm.org/docs/ControlFlowIntegrity.html

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
https://mail.gnome.org/mailman/listinfo/xml
xmlmemstrdup.patch (application/octet-stream, 369 B)
--- a/globals.c
+++ b/globals.c
@@ -131,7 +131,7 @@ xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
  *
  * Returns the copy of the string or NULL in case of error
  */
-xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
+xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) strdup;
 #endif /* DEBUG_MEMORY_LOCATION || DEBUG_MEMORY */
 
 #include <libxml/threads.h>
xmlnop.patch (application/octet-stream, 451 B)
--- a/libxml.h
+++ b/libxml.h
@@ -96,7 +96,7 @@ int __xmlRandom(void);
 #endif
 
 XMLPUBFUN xmlChar * XMLCALL xmlEscapeFormatString(xmlChar **msg);
-int xmlNop(void);
+int xmlNop(void *context, char *buffer, int len);
 
 #ifdef IN_LIBXML
 #ifdef __GNUC__
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -808,7 +808,7 @@ xmlCheckFilename (const char *path)
  * Returns zero
  */
 int
-xmlNop(void) {
+xmlNop(void *context, char *buffer, int len) {
     return(0);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.