-
-
Save nununoisy/b61448b9724620cc4a9d6904ee7ce9db to your computer and use it in GitHub Desktop.
CodeQL C++ virtual tables test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CXX := g++ | |
CXX := ${CXX} | |
.PHONY: clean | |
all: vtables.cpp | |
$(CXX) -o vtables vtables.cpp | |
clean: | |
rm -f vtables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <cstdio> | |
#include <cstring> | |
/********************** | |
* CLASS - BaseClass * | |
**********************/ | |
class BaseClass { | |
public: | |
char cmd[1024]; | |
virtual void doSystemCall(); | |
virtual void initializeCommand(char *ncmd); | |
}; | |
void BaseClass::doSystemCall() { | |
std::cout << cmd << std::endl; | |
std::system(cmd); | |
} | |
void BaseClass::initializeCommand(char *ncmd) { | |
std::strcpy(cmd, ncmd); | |
} | |
/********************** | |
* CLASS - DerivClass * | |
**********************/ | |
class DerivClass : public BaseClass { | |
public: | |
void initializeCommand(char *ncmd) override; | |
}; | |
void DerivClass::initializeCommand(char *ncmd) { | |
std::strcat(cmd, "/bin/sh -c "); | |
std::strcat(cmd, ncmd); | |
} | |
/********************** | |
* CODE * | |
**********************/ | |
int main() { | |
char buf[512]; | |
std::fgets(buf, 512, stdin); | |
BaseClass* caller = new DerivClass(); | |
caller->initializeCommand(buf); | |
caller->doSystemCall(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment