/ GetXdef: get the external TABDEF from OEM module. */ /
| 610 | /* GetXdef: get the external TABDEF from OEM module. */ |
| 611 | /***********************************************************************/ |
| 612 | PTABDEF OEMDEF::GetXdef(PGLOBAL g) |
| 613 | { |
| 614 | typedef PTABDEF (__stdcall *XGETDEF) (PGLOBAL, void *); |
| 615 | char c, soname[_MAX_PATH], getname[40] = "Get"; |
| 616 | PTABDEF xdefp; |
| 617 | XGETDEF getdef = NULL; |
| 618 | PCATLG cat = Cat; |
| 619 | |
| 620 | /*********************************************************************/ |
| 621 | /* Ensure that the module name doesn't have a path. */ |
| 622 | /* This is done to ensure that only approved libs from the system */ |
| 623 | /* directories are used (to make this even remotely secure). */ |
| 624 | /*********************************************************************/ |
| 625 | if (check_valid_path(Module, strlen(Module))) { |
| 626 | safe_strcpy(g->Message, sizeof(g->Message), "Module cannot contain a path"); |
| 627 | return NULL; |
| 628 | } |
| 629 | else if (strlen(Subtype)+1+3 >= sizeof(getname)) { |
| 630 | safe_strcpy(g->Message, sizeof(g->Message), "Subtype string too long"); |
| 631 | return NULL; |
| 632 | } |
| 633 | else |
| 634 | // PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora |
| 635 | snprintf(soname, sizeof(soname), "%s%s", GetPluginDir(), Module); |
| 636 | |
| 637 | #if defined(_WIN32) |
| 638 | // Is the DLL already loaded? |
| 639 | if (!Hdll && !(Hdll = GetModuleHandle(soname))) |
| 640 | // No, load the Dll implementing the function |
| 641 | if (!(Hdll = LoadLibrary(soname))) { |
| 642 | char buf[256]; |
| 643 | DWORD rc = GetLastError(); |
| 644 | |
| 645 | snprintf(g->Message, sizeof(g->Message), MSG(DLL_LOAD_ERROR), rc, soname); |
| 646 | FormatMessage(FORMAT_MESSAGE_FLAGS, NULL, rc, 0, |
| 647 | (LPTSTR)buf, sizeof(buf), NULL); |
| 648 | safe_strcat(g->Message, sizeof(g->Message), ": "); |
| 649 | safe_strcat(g->Message, sizeof(g->Message), buf); |
| 650 | return NULL; |
| 651 | } // endif hDll |
| 652 | |
| 653 | // The exported name is always in uppercase |
| 654 | for (int i = 0; ; i++) { |
| 655 | c = Subtype[i]; |
| 656 | getname[i + 3] = toupper(c); |
| 657 | if (!c) break; |
| 658 | } // endfor i |
| 659 | |
| 660 | // Get the function returning an instance of the external DEF class |
| 661 | if (!(getdef = (XGETDEF)GetProcAddress((HINSTANCE)Hdll, getname))) { |
| 662 | char buf[256]; |
| 663 | DWORD rc = GetLastError(); |
| 664 | |
| 665 | snprintf(g->Message, sizeof(g->Message), MSG(PROCADD_ERROR), rc, getname); |
| 666 | FormatMessage(FORMAT_MESSAGE_FLAGS, NULL, rc, 0, |
| 667 | (LPTSTR)buf, sizeof(buf), NULL); |
| 668 | safe_strcat(g->Message, sizeof(g->Message), ": "); |
| 669 | safe_strcat(g->Message, sizeof(g->Message), buf); |
nothing calls this directly
no test coverage detected