moduleloadtest.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*
  10. * Extremely simple dynamic loader, must never be linked with anything other
  11. * than the standard C library. Its purpose is to try to load a dynamic module
  12. * and verify the presence of one symbol, if that's given.
  13. */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <openssl/core.h>
  17. #include "simpledynamic.h"
  18. static int test_load(const char *path, const char *symbol)
  19. {
  20. #ifdef SD_INIT
  21. SD sd = SD_INIT;
  22. SD_SYM sym;
  23. int ret;
  24. if (!sd_load(path, &sd, SD_MODULE))
  25. return 0;
  26. ret = symbol == NULL || sd_sym(sd, symbol, &sym);
  27. if (!sd_close(sd))
  28. ret = 0;
  29. return ret;
  30. #else
  31. fprintf(stderr, "No dynamic loader\n");
  32. return 0;
  33. #endif
  34. }
  35. int main(int argc, char *argv[])
  36. {
  37. const char *m, *s;
  38. if (argc != 2 && argc != 3) {
  39. fprintf(stderr, "Usage: %s sharedobject [ entrypoint ]\n", argv[0]);
  40. return 1;
  41. }
  42. m = argv[1];
  43. s = argc == 3 ? argv[2] : NULL;
  44. return test_load(m, s) ? 0 : 1;
  45. }