Skip to content

Instantly share code, notes, and snippets.

@mkuron
Last active December 25, 2015 20:49
Show Gist options
  • Save mkuron/7038065 to your computer and use it in GitHub Desktop.
Save mkuron/7038065 to your computer and use it in GitHub Desktop.
Monkey-patching MathLM on Mac OS X so it does not crash when clients with 32-character (or longer) hostnames request a Mathematica license
strcpy.dylib: strcpy.c
gcc -Wall -o $@ -dynamiclib $<
#!/bin/bash
sudo -u lmgrduser DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=strcpy.dylib /usr/local/Wolfram/MathLM/mathlm -foreground -pwfile /usr/local/Wolfram/MathLM/mathpass -timeout 3 -loglevel 4 -logfile /var/log/lmgrd/mathlm.log
#include <stdio.h>
#include <string.h>
void *
__strcpy_chk (char* dest, char* src, size_t dstlen)
{
size_t len = strlen (src);
if (__builtin_expect (dstlen < len, 0))
printf("THIS WOULD HAVE CRASHED: ");
printf("Copying %s. Source: %lu bytes, Destination: %lu bytes\n", src, len, dstlen);
if (18446744073709551615U == dstlen)
return memcpy (dest, src, len + 1);
return strncpy (dest, src, dstlen);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment