From 74f0fd12cc69b32ad022b5714ffa40a52cfa2405 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 1 Apr 2017 15:27:08 +0430 Subject: th elocation fo the config file has been changed when you run make install --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index c938515..d73a6b5 100644 --- a/makefile +++ b/makefile @@ -62,7 +62,7 @@ install: chmod +x ./extra-tools/ReportPrintPretty.sh chmod +x ./extra-tools/precommitTests.sh if [[ ! -d "./temp" ]]; then mkdir temp; fi - $(shell echo MUTATOR_HOME=$$(pwd) > mutator.config) + $(shell echo MUTATOR_HOME=$$(pwd) > ./daemon/mutator.config) help: @echo '- There is help.' -- cgit v1.2.3 From d32b0c14a217547dfdf9818f8d96fa0be41d1c01 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sat, 1 Apr 2017 15:28:49 +0430 Subject: now the server will only run the driver commands. not anything. --- daemon/daemon_aux.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- daemon/mutatorclient.c | 6 ++--- daemon/mutatord.c | 2 ++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index ce47f37..3a78eb6 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -59,6 +59,7 @@ bool cleanser(char cleansee[]) return (cleansee_health && nullterminated); } + /**********************************************************************************************************************/ int mutator_server(FILE* log_file) { @@ -67,9 +68,11 @@ int mutator_server(FILE* log_file) char client_message[2000]; FILE* clientistream; + FILE* mutator_config; char runresponse[4000]; - char NOOUT[]="command did not return any output. could be an error or not.\n"; - char BADOUT[]="what are you exactly trying to do?"; + const char NOOUT[]="command did not return any output. could be an error or not.\n"; + const char BADOUT[]="what are you exactly trying to do?"; + const char STD_OUT[]="stdout returned:\n"; /*create socket*/ socket_desc = socket(AF_INET, SOCK_STREAM, 0); @@ -120,10 +123,59 @@ int mutator_server(FILE* log_file) fprintf(log_file, "%s", "got command from client.\n"); + mutator_config = fopen("/home/bloodstalker/devi/hell2/daemon/mutator.config", "r"); + + char configline[100]; + const char delimiter[2]="="; + char* token_var; + const char mutator_home_var[]="MUTATOR_HOME"; + const char driver_name[] = "/mutator.sh "; + char* full_command; + char* temp; + +#if 1 +#if 1 + while (fgets(configline,sizeof(configline), mutator_config) != NULL) + { + temp = strstr(configline, mutator_home_var); + + if (temp != NULL) + { + memmove(temp, configline + strlen(mutator_home_var) + 1, strlen(configline) - strlen(mutator_home_var) + 1); + + break; + } + } +#endif + +#if 1 + for (int i = 0; i < strlen(temp); ++i) + { + if (i == strlen(temp) - 1) + { + temp[i] = '\0'; + } + } + full_command = malloc(strlen(temp) + strlen(client_message) + strlen(driver_name) + 1); + + strcpy(full_command,temp); + strcat(full_command, driver_name); + strcat(full_command, client_message); + fprintf(log_file, "%s", full_command); +#endif +#endif + if (cleanser(client_message) == true) { +#ifndef __DBG + clientistream = popen(full_command, "r"); +#endif + +#if defined(__DBG) /*open pipe, run command*/ clientistream = popen(client_message, "r"); + //clientistream = popen(full_command, "r"); +#endif } else { @@ -132,6 +184,9 @@ int mutator_server(FILE* log_file) continue; } + fprintf(log_file, "%s", "freeing memory reserved for command.\n"); + free(full_command); + if (clientistream == NULL) { perror("client command did not run successfully."); @@ -146,16 +201,21 @@ int mutator_server(FILE* log_file) if (fgets(runresponse, sizeof(runresponse), clientistream) == NULL) { /*say there was nothing on stdout to send.*/ + fprintf(log_file, "%s", "command returned no stdout.\n"); write(client_sock, NOOUT, strlen(NOOUT)); } + else + { + fprintf(log_file, "%s", "command returned stdout.\n"); + write(client_sock, STD_OUT, strlen(STD_OUT)); + } rewind(clientistream); while (fgets(runresponse, sizeof(runresponse), clientistream) != NULL) { #if defined(__DBG) - fscanf(log_file, "%s", "command stdout:"); - fscanf(log_file, "%s", runresponse); + fprintf(log_file, "%s", "command stdout:\n"); #endif write(client_sock, runresponse, strlen(runresponse)); fprintf(log_file, "%s", runresponse); diff --git a/daemon/mutatorclient.c b/daemon/mutatorclient.c index 2b61d96..0addc76 100644 --- a/daemon/mutatorclient.c +++ b/daemon/mutatorclient.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* /**********************************************************************************************************************/ /*macros*/ #define __DBG -#if 1 +#if 0 #undef __DBG #endif /**********************************************************************************************************************/ @@ -97,14 +97,14 @@ int main(int argc, char *argv[]) fflush(stdin); #if defined(__DBG) - puts("checkpoint 1"); + puts("checkpoint 11"); #endif /*recieve a reply from the server*/ recvlength = recv(sock, server_reply, 2000, 0); #if defined(__DBG) - puts("checkpoint 2"); + puts("checkpoint 12"); #endif if (recvlength < 0) diff --git a/daemon/mutatord.c b/daemon/mutatord.c index a0496d3..a9d29cd 100644 --- a/daemon/mutatord.c +++ b/daemon/mutatord.c @@ -140,6 +140,8 @@ int main(void) fclose(mut_log); }while(0); + //return server_exit_code; + /*@DEVI-these obviously will never run. theyre just a reminder that i need to handle the gracefull shutdown*/ #if 0 fclose(mut_log); -- cgit v1.2.3 From a9ffad836eafa989b2d4e489fe2d591169b1de8e Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 09:11:05 +0430 Subject: fixed some issues --- daemon/daemon_aux.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index 3a78eb6..3572972 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -149,11 +149,14 @@ int mutator_server(FILE* log_file) #endif #if 1 - for (int i = 0; i < strlen(temp); ++i) + if (temp != NULL) { - if (i == strlen(temp) - 1) + for (int i = 0; i < strlen(temp); ++i) { - temp[i] = '\0'; + if (i == strlen(temp) - 1) + { + temp[i] = '\0'; + } } } full_command = malloc(strlen(temp) + strlen(client_message) + strlen(driver_name) + 1); @@ -181,11 +184,14 @@ int mutator_server(FILE* log_file) { fprintf(log_file, "%s", "what are you trying to do exactly?"); write(client_sock, BADOUT, strlen(BADOUT)); + free(full_command); + fclose(mutator_config); continue; } fprintf(log_file, "%s", "freeing memory reserved for command.\n"); free(full_command); + fclose(mutator_config); if (clientistream == NULL) { -- cgit v1.2.3 From aaebb9c2d6bb9aff225f88884737bbc978df0ae0 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 09:41:59 +0430 Subject: added a check for empty or config file not found. --- daemon/daemon_aux.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index 3572972..278d207 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -73,6 +73,7 @@ int mutator_server(FILE* log_file) const char NOOUT[]="command did not return any output. could be an error or not.\n"; const char BADOUT[]="what are you exactly trying to do?"; const char STD_OUT[]="stdout returned:\n"; + const char EMPTY_CONFIG[]="empty config file or file not found.\n"; /*create socket*/ socket_desc = socket(AF_INET, SOCK_STREAM, 0); @@ -133,6 +134,17 @@ int mutator_server(FILE* log_file) char* full_command; char* temp; + /*checking for an empty config-file. could also mean the config file was not found.*/ + if(fgets(configline,sizeof(configline), mutator_config) == NULL) + { + fprintf(log_file, "%s", EMPTY_CONFIG); + fclose(log_file); + fclose(mutator_config); + return 1; + } + + rewind(mutator_config); + #if 1 #if 1 while (fgets(configline,sizeof(configline), mutator_config) != NULL) @@ -149,8 +161,6 @@ int mutator_server(FILE* log_file) #endif #if 1 - if (temp != NULL) - { for (int i = 0; i < strlen(temp); ++i) { if (i == strlen(temp) - 1) @@ -158,7 +168,6 @@ int mutator_server(FILE* log_file) temp[i] = '\0'; } } - } full_command = malloc(strlen(temp) + strlen(client_message) + strlen(driver_name) + 1); strcpy(full_command,temp); -- cgit v1.2.3 From b731fb9edf33fb2e1ec1fa1ab8e65f8680688351 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 09:54:52 +0430 Subject: more fixes --- daemon/daemon_aux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index 278d207..843c84b 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -140,6 +140,8 @@ int mutator_server(FILE* log_file) fprintf(log_file, "%s", EMPTY_CONFIG); fclose(log_file); fclose(mutator_config); + close(client_sock); + close(socket_desc); return 1; } -- cgit v1.2.3 From 0fa03ec7db294080d4df7f8eff50b0312c48162f Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:36:10 +0430 Subject: general overhaul to how the server handles the command execution. fixed the new-line char being sent along with the command. --- daemon/daemon_aux.c | 73 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 21 deletions(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index 843c84b..65fbc4b 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -23,10 +23,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* #if 1 #undef __DBG #endif + +#define __DBG_2 +#if 1 +#undef __DBG_2 +#endif + +#define CLEAN_UP() \ + do{\ + fclose(log_file);\ + fclose(mutator_config);\ + close(client_sock);\ + close(socket_desc);\ + }\ + while(0) /**********************************************************************************************************************/ /*inclusion directive*/ #include "daemon_aux.h" /*standard headers*/ +#include #include #include #include @@ -73,7 +88,9 @@ int mutator_server(FILE* log_file) const char NOOUT[]="command did not return any output. could be an error or not.\n"; const char BADOUT[]="what are you exactly trying to do?"; const char STD_OUT[]="stdout returned:\n"; - const char EMPTY_CONFIG[]="empty config file or file not found.\n"; + const char EMPTY_CONFIG[]="error: empty config file.\n"; + const char NFOUND_CONFIG[]="error: cant find config file in the default path.\n"; + const char SERVER_TERM[]="server terminated.\n"; /*create socket*/ socket_desc = socket(AF_INET, SOCK_STREAM, 0); @@ -126,6 +143,17 @@ int mutator_server(FILE* log_file) mutator_config = fopen("/home/bloodstalker/devi/hell2/daemon/mutator.config", "r"); + if (mutator_config == NULL) + { + write(client_sock, NFOUND_CONFIG, strlen(NFOUND_CONFIG)); + write(client_sock, SERVER_TERM, strlen(SERVER_TERM)); + fprintf(log_file, "%s", NFOUND_CONFIG); + fprintf(log_file, "%s%d%s", "fopen returned: ", errno, "\n"); + fprintf(log_file, "%s", SERVER_TERM); + CLEAN_UP(); + return errno; + } + char configline[100]; const char delimiter[2]="="; char* token_var; @@ -133,51 +161,54 @@ int mutator_server(FILE* log_file) const char driver_name[] = "/mutator.sh "; char* full_command; char* temp; + char* dummy; /*checking for an empty config-file. could also mean the config file was not found.*/ if(fgets(configline,sizeof(configline), mutator_config) == NULL) { + write(client_sock, EMPTY_CONFIG, strlen(EMPTY_CONFIG)); + write(client_sock, SERVER_TERM, strlen(SERVER_TERM)); fprintf(log_file, "%s", EMPTY_CONFIG); - fclose(log_file); - fclose(mutator_config); - close(client_sock); - close(socket_desc); - return 1; + fprintf(log_file, "%s", SERVER_TERM); + CLEAN_UP(); + /*@DEVI-return SIGPIPE*/ + return 141; } rewind(mutator_config); -#if 1 -#if 1 while (fgets(configline,sizeof(configline), mutator_config) != NULL) { temp = strstr(configline, mutator_home_var); if (temp != NULL) { - memmove(temp, configline + strlen(mutator_home_var) + 1, strlen(configline) - strlen(mutator_home_var) + 1); + memmove(temp, configline + strlen(mutator_home_var) + 1, strlen(configline) - strlen(mutator_home_var) - 1); break; } } -#endif -#if 1 - for (int i = 0; i < strlen(temp); ++i) - { - if (i == strlen(temp) - 1) - { - temp[i] = '\0'; - } - } - full_command = malloc(strlen(temp) + strlen(client_message) + strlen(driver_name) + 1); + /*@DEVI-null-terminating temp*/ + temp[strlen(temp) - strlen(mutator_home_var) - 2] = '\0'; + /*@DEVI-checks whether the line-break char was also sent.if yes, then removes it.*/ + if (client_message[read_size - 1] == '\n') + { + client_message[read_size - 1] = '\0'; + } + + full_command = malloc(strlen(temp) + read_size + strlen(driver_name) + 1); strcpy(full_command,temp); strcat(full_command, driver_name); + /*@DEVI-client_message is not null-terminated but strcat takes care of that.*/ strcat(full_command, client_message); - fprintf(log_file, "%s", full_command); -#endif + +#if defined(__DBG_2) + fprintf(log_file, "%s%s%s", "temp is: ", temp, "\n"); + fprintf(log_file, "%s%s%s", "driver_name is: ",driver_name, "\n"); #endif + fprintf(log_file, "%s%s%s", "full_command is: ", full_command, "\n"); if (cleanser(client_message) == true) { -- cgit v1.2.3 From 90f5834d0ffd9abc5a435ebc20aebc03d7ca2187 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:36:25 +0430 Subject: disbaled a macro --- daemon/mutatorclient.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/mutatorclient.c b/daemon/mutatorclient.c index 0addc76..1cbfd0a 100644 --- a/daemon/mutatorclient.c +++ b/daemon/mutatorclient.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* /**********************************************************************************************************************/ /*macros*/ #define __DBG -#if 0 +#if 1 #undef __DBG #endif /**********************************************************************************************************************/ -- cgit v1.2.3 From dae64986f26d1e49e65b1657ef74f4f791ef852d Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:36:49 +0430 Subject: the daemon returns the server exit code --- daemon/mutatord.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/mutatord.c b/daemon/mutatord.c index a9d29cd..a148686 100644 --- a/daemon/mutatord.c +++ b/daemon/mutatord.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.* /**********************************************************************************************************************/ /*macros*/ #define __DBG -#if 0 +#if 1 #undef __DBG #endif /**********************************************************************************************************************/ @@ -140,7 +140,7 @@ int main(void) fclose(mut_log); }while(0); - //return server_exit_code; + return server_exit_code; /*@DEVI-these obviously will never run. theyre just a reminder that i need to handle the gracefull shutdown*/ #if 0 -- cgit v1.2.3 From 14ea95e8bb55d0e0cbbce85b5cbed605cc05445e Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:37:02 +0430 Subject: marked as deprecated --- daemon/mutatorserver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/daemon/mutatorserver.c b/daemon/mutatorserver.c index 4450583..f233553 100644 --- a/daemon/mutatorserver.c +++ b/daemon/mutatorserver.c @@ -1,4 +1,10 @@ +/** @file mutatorserver.c*/ +/** + * @brief The test file for the server. Runs the server as a stand-alone. + */ + +/** @warning Deprecated*/ /***************************************************Project Mutator****************************************************/ /*first line intentionally left blank.*/ /*Copyright (C) 2017 Farzad Sadeghi -- cgit v1.2.3 From cdd1daed95a47a604cb88ef81a11d460dd02ecfe Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:37:13 +0430 Subject: marked as deprecated --- daemon/mutatorserver.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/daemon/mutatorserver.h b/daemon/mutatorserver.h index ce885e7..8585192 100644 --- a/daemon/mutatorserver.h +++ b/daemon/mutatorserver.h @@ -1,4 +1,11 @@ +/** @file mutatorserver.h*/ +/** + * @brief The header for the test file for the server. + */ + +/** @warning Deprecated*/ + /***************************************************Project Mutator****************************************************/ /*first line intentionally left blank.*/ /*Copyright (C) 2017 Farzad Sadeghi -- cgit v1.2.3 From 39a3c2ae3239b13582f811b052c21afbacb12ead Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 16:37:33 +0430 Subject: updated as per the changes --- daemon/README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/daemon/README.md b/daemon/README.md index ba2a8f7..e9e2943 100644 --- a/daemon/README.md +++ b/daemon/README.md @@ -10,6 +10,7 @@ It's simple. The client sends a command to the server run by the daemon(`mutator The mutator client is a thin client which is also the whole point of all of this: Plugin.
The daemon generates a log file in the `daemon` directory under root named `mutatordlog`.
+The daemon will need to read some VARS from a config file that is generated by `make install` inside the daemon directory named `mutator.config`.
### How to use it? @@ -21,15 +22,25 @@ make all ``` -After that, run `mutatord` to start up the server and then run `mutatorclient` and send your commands.
-The server passes the commands to `mutator.sh` to execute. For a list of available options you can run `mutator.sh -h` or just read the `README.md` in project root.
A -I have yet to decide how to set a home path variable for mutator so you need to pass all adresses to the server as absolute paths since the daemon changes the directory to `/`.
+Or just run that from the main makefile. After that, run `mutatord` to start up the server and then run `mutatorclient` and send your commands.
+The server passes the commands to `mutator.sh` to execute. For a list of available options you can run `mutator.sh -h` or just read the `README.md` in project root.
+ +To run commands on the server, use normal mutator driver commands excluding the driver name:
+ +```bash + +-f /home/user1/mutator/samples/action_file.mutator + +``` + To kill the client and server(and also the daemon) just send `end_comm` as the command through the client.
## WARNING -Currently there are no checks on the commands sent to the server. The server uses `popen()` to run the commands so it will run any valid `sh` command it gets from `/` and the buffers are not exactly small either.
+Currently there are some checks on the commands sent to the server. The server uses `popen()` to run the commands prefixed by the driver name, `mutator.sh`.
+The server checks to see whether the command string is null-terminated and whether it contains `|` or `;`. Thats's all the checks it runs before running a command from the root directory.
+The daemon will switch to the root directory as soon as it is run and the server will inherit the permissions that the daemon was ran by. There is no reason to run the daemon as sudo.
### Directory Content -- cgit v1.2.3 From ba407e763f31d647179d7a11305263b28ea4360d Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Sun, 2 Apr 2017 17:13:50 +0430 Subject: fixing some issues --- daemon/daemon_aux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/daemon/daemon_aux.c b/daemon/daemon_aux.c index 65fbc4b..00841de 100644 --- a/daemon/daemon_aux.c +++ b/daemon/daemon_aux.c @@ -110,6 +110,7 @@ int mutator_server(FILE* log_file) /*Bind*/ if (bind(socket_desc, (struct sockaddr*)&server, sizeof(server)) < 0) { + close(socket_desc); perror("bind failed.error.\n"); return 1; } @@ -150,7 +151,11 @@ int mutator_server(FILE* log_file) fprintf(log_file, "%s", NFOUND_CONFIG); fprintf(log_file, "%s%d%s", "fopen returned: ", errno, "\n"); fprintf(log_file, "%s", SERVER_TERM); - CLEAN_UP(); + + fclose(log_file); + close(client_sock); + close(socket_desc); + return errno; } -- cgit v1.2.3 From ed445dffb60110dc6dcf509c8ee7a99d1cd7e412 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 3 Apr 2017 00:47:34 +0430 Subject: fixed the temp workarounds for 12.11,10.1 and 10.2. they are proper now. --- mutator-lvl0.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp index 7e388d4..26b9673 100644 --- a/mutator-lvl0.cpp +++ b/mutator-lvl0.cpp @@ -4125,16 +4125,44 @@ public: uint64_t ICETypeSize = ASTC->getTypeSize(CanonTypeDaddy); uint64_t ChildTypeSize = ASTC->getTypeSize(CanonTypeChild); - /* - bool ICETypeIsSignedInt = CanonTypeDaddy->getAsPlaceholderType()->isSignedInteger(); - bool ChildTypeIsSignedInt = CanonTypeChild->getAsPlaceholderType()->isSignedInteger(); - - bool ICETypeIsUSignedInt = CanonTypeDaddy->getAsPlaceholderType()->isUnsignedInteger(); - bool ChildTypeIsUSignedInt = CanonTypeChild->getAsPlaceholderType()->isUnsignedInteger(); - - if (CanonTypeDaddy->getAsPlaceholderType()->isInteger() && CanonTypeChild->getAsPlaceholderType()->isInteger()) - */ + bool ICETypeIsSignedInt = CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Long) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Int) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Short) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::SChar) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Char_S) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::LongLong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Int128) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::WChar_S); + bool ChildTypeIsSignedInt = CanonTypeChild->isSpecificBuiltinType(BuiltinType::Kind::Long) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Int) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Short) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::SChar) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Char_S) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::LongLong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Int128) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::WChar_S); + + bool ICETypeIsUSignedInt = CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::ULong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UInt) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UShort) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UChar) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Char_U) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::ULongLong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UInt128) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::WChar_U); + bool ChildTypeIsUSignedInt = CanonTypeChild->isSpecificBuiltinType(BuiltinType::Kind::ULong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UInt) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UShort) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UChar) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::Char_U) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::ULongLong) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::UInt128) || \ + CanonTypeDaddy->isSpecificBuiltinType(BuiltinType::Kind::WChar_U); + + bool ICETypeIsInteger = ICETypeIsSignedInt || ICETypeIsUSignedInt; + bool ChildTypeIsInteger = ChildTypeIsSignedInt || ChildTypeIsUSignedInt; +#if 0 bool ICETypeIsSignedInt = false; bool ICETypeIsUSignedInt = false; bool ICETypeIsInteger = false; @@ -4158,6 +4186,7 @@ public: ChildTypeIsInteger = placeholderType->isInteger(); } } +#endif if (ICETypeIsInteger && ChildTypeIsInteger) { @@ -4919,7 +4948,16 @@ public: const clang::Type* CanonTP = ASTC->getCanonicalType(TP); - //bool TypeIsUSignedInt = CanonTP->getAsPlaceholderType()->isUnsignedInteger(); + bool TypeIsUSignedInt = CanonTP->isSpecificBuiltinType(BuiltinType::Kind::ULong) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::UInt) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::UShort) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::UChar) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::Char_U) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::ULongLong) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::UInt128) || \ + CanonTP->isSpecificBuiltinType(BuiltinType::Kind::WChar_U); + +#if 0 bool TypeIsUSignedInt = false; if (CanonTP) { auto placeholderType = CanonTP->getAsPlaceholderType(); @@ -4927,6 +4965,7 @@ public: TypeIsUSignedInt = placeholderType->isUnsignedInteger(); } } +#endif if (TypeIsUSignedInt) { -- cgit v1.2.3 From 694154c79d6517e2ddd4ffe60ece2c7fb445b80f Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 3 Apr 2017 04:16:39 +0430 Subject: added a blue-print for SaferCPP's tagging of all native pointers --- mutator-lvl0.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp index 26b9673..26b85a3 100644 --- a/mutator-lvl0.cpp +++ b/mutator-lvl0.cpp @@ -6024,6 +6024,44 @@ class SFCPPARR02 : public MatchFinder::MatchCallback SFCPPARR02SUB SubHandler; }; /**********************************************************************************************************************/ +/** + * @brief The callback for the Safercpp pointer matchers. + */ +class SFCPPPNTR01 : public MatchFinder::MatchCallback +{ + public: + SFCPPPNTR01 (Rewriter &Rewrite) : Rewrite(Rewrite) {} + + virtual void run(const MatchFinder::MatchResult &MR) + { + if (MR.Nodes.getNodeAs("sfcpppntr01") != nullptr) + { + const VarDecl* VD = MR.Nodes.getNodeAs("sfcpppntr01"); + + SourceLocation SL = VD->clang::Decl::getLocStart(); + CheckSLValidity(SL); + SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); + + if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) + { + return void(); + } + + if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL)) + { + return void(); + } + + std::cout << "SaferCPP02" << ":" << "Native pointer used:" << SL.printToString(*MR.SourceManager) << ":" << std::endl; + + XMLDocOut.XMLAddNode(MR.Context, SL, "SaferCPP02", "Native pointer used:"); + JSONDocOUT.JSONAddElement(MR.Context, SL, "SaferCPP02", "Native pointer used:"); + } + } + + private: + Rewriter &Rewrite; +}; /**********************************************************************************************************************/ /**********************************************************************************************************************/ /**********************************************************************************************************************/ @@ -7519,7 +7557,8 @@ public: HandlerForPointer1723(R), HandlerForPointer174(R), HandlerForPointer175(R), HandlerForTypes61(R), HandlerForSU181(R), \ HandlerForMCPTCCSTYLE(R), HandlerForATC101(R), HandlerForIdent51(R), HandlerForDCDF87(R), HandlerForDCDF88(R), HandlerForLangX23(R), \ HandlerForFunction167(R), HandlerForCF143(R), HandlerForExpr1212(R), HandlerForExpr1211(R), HandlerForAtc105(R), HandlerForCSE135(R), \ - HandlerForTypes612(R), HandlerForConst71(R), HandlerForIdent5X(R), HandlerForSFCPPARR01(R), HandlerForSFCPPARR02(R) { + HandlerForTypes612(R), HandlerForConst71(R), HandlerForIdent5X(R), HandlerForSFCPPARR01(R), HandlerForSFCPPARR02(R), \ + HandlerForSFCPPPNTR01(R) { /*@DEVI-disables all matchers*/ #if defined(_MUT0_DIS_MATCHERS) @@ -7787,6 +7826,8 @@ public: Matcher.addMatcher(declRefExpr(hasAncestor(binaryOperator(allOf(hasLHS(declRefExpr().bind("sfcpparrdeep")), hasRHS(hasDescendant(implicitCastExpr(hasCastKind(CK_ArrayToPointerDecay))))\ , hasOperatorName("="))))), &HandlerForSFCPPARR02); + + Matcher.addMatcher(varDecl(hasType(pointerType())).bind("sfcpppntr01"), &HandlerForSFCPPPNTR01); #endif } @@ -7866,6 +7907,7 @@ private: MCIdent5x HandlerForIdent5X; SFCPPARR01 HandlerForSFCPPARR01; SFCPPARR02 HandlerForSFCPPARR02; + SFCPPPNTR01 HandlerForSFCPPPNTR01; MatchFinder Matcher; }; /**********************************************************************************************************************/ -- cgit v1.2.3 From a0f838df37cd23c3188bcdac471053a4438d2170 Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Mon, 3 Apr 2017 05:58:15 +0430 Subject: added pointer declrefexpr tagging for safercpp --- mutator-lvl0.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/mutator-lvl0.cpp b/mutator-lvl0.cpp index 26b85a3..42f0946 100644 --- a/mutator-lvl0.cpp +++ b/mutator-lvl0.cpp @@ -6025,7 +6025,7 @@ class SFCPPARR02 : public MatchFinder::MatchCallback }; /**********************************************************************************************************************/ /** - * @brief The callback for the Safercpp pointer matchers. + * @brief The callback for the Safercpp pointer matchers. Matches the dedlarations. */ class SFCPPPNTR01 : public MatchFinder::MatchCallback { @@ -6052,6 +6052,45 @@ class SFCPPPNTR01 : public MatchFinder::MatchCallback return void(); } + std::cout << "SaferCPP02" << ":" << "Native pointer declared:" << SL.printToString(*MR.SourceManager) << ":" << std::endl; + + XMLDocOut.XMLAddNode(MR.Context, SL, "SaferCPP02", "Native pointer declared:"); + JSONDocOUT.JSONAddElement(MR.Context, SL, "SaferCPP02", "Native pointer declared:"); + } + } + + private: + Rewriter &Rewrite; +}; +/**********************************************************************************************************************/ +/** + * @brief The callback for the Safercpp pointer matchers. Matches the DeclRefExprs. + */ +class SFCPPPNTR02 : public MatchFinder::MatchCallback +{ + public: + SFCPPPNTR02 (Rewriter &Rewrite) : Rewrite(Rewrite) {} + + virtual void run(const MatchFinder::MatchResult &MR) + { + if (MR.Nodes.getNodeAs("sfcpppntr02") != nullptr) + { + const DeclRefExpr* DRE = MR.Nodes.getNodeAs("sfcpppntr02"); + + SourceLocation SL = DRE->getLocStart(); + CheckSLValidity(SL); + SL = Devi::SourceLocationHasMacro(SL, Rewrite, "start"); + + if (Devi::IsTheMatchInSysHeader(CheckSystemHeader, MR, SL)) + { + return void(); + } + + if (!Devi::IsTheMatchInMainFile(MainFileOnly, MR, SL)) + { + return void(); + } + std::cout << "SaferCPP02" << ":" << "Native pointer used:" << SL.printToString(*MR.SourceManager) << ":" << std::endl; XMLDocOut.XMLAddNode(MR.Context, SL, "SaferCPP02", "Native pointer used:"); @@ -6070,6 +6109,7 @@ class SFCPPPNTR01 : public MatchFinder::MatchCallback /**********************************************************************************************************************/ /**********************************************************************************************************************/ /**********************************************************************************************************************/ +/**********************************************************************************************************************/ /*the sourcelocation used in the overload of XMLAddNode that takes sourcemanager as input parameter uses the spelling location so the client does not need to check the sourcelocation for macros expansions.*/ class PPInclusion : public PPCallbacks @@ -7558,7 +7598,7 @@ public: HandlerForMCPTCCSTYLE(R), HandlerForATC101(R), HandlerForIdent51(R), HandlerForDCDF87(R), HandlerForDCDF88(R), HandlerForLangX23(R), \ HandlerForFunction167(R), HandlerForCF143(R), HandlerForExpr1212(R), HandlerForExpr1211(R), HandlerForAtc105(R), HandlerForCSE135(R), \ HandlerForTypes612(R), HandlerForConst71(R), HandlerForIdent5X(R), HandlerForSFCPPARR01(R), HandlerForSFCPPARR02(R), \ - HandlerForSFCPPPNTR01(R) { + HandlerForSFCPPPNTR01(R), HandlerForSFCPPPNTR02(R) { /*@DEVI-disables all matchers*/ #if defined(_MUT0_DIS_MATCHERS) @@ -7828,6 +7868,8 @@ public: , hasOperatorName("="))))), &HandlerForSFCPPARR02); Matcher.addMatcher(varDecl(hasType(pointerType())).bind("sfcpppntr01"), &HandlerForSFCPPPNTR01); + + Matcher.addMatcher(declRefExpr(hasType(pointerType())).bind("sfcpppntr02"), &HandlerForSFCPPPNTR02); #endif } @@ -7908,6 +7950,7 @@ private: SFCPPARR01 HandlerForSFCPPARR01; SFCPPARR02 HandlerForSFCPPARR02; SFCPPPNTR01 HandlerForSFCPPPNTR01; + SFCPPPNTR02 HandlerForSFCPPPNTR02; MatchFinder Matcher; }; /**********************************************************************************************************************/ -- cgit v1.2.3