Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional static def leads to wrong number of arguments #134

Open
pattersonz opened this issue Nov 15, 2020 · 0 comments
Open

conditional static def leads to wrong number of arguments #134

pattersonz opened this issue Nov 15, 2020 · 0 comments

Comments

@pattersonz
Copy link
Contributor

pattersonz commented Nov 15, 2020

the following code:

int wdb_stmt_cache(int wdb, int index);

#ifdef WAZUH_UNIT_TESTING
#define static
#endif

static void wdbi_update_completion(int wdb) {
    if (wdb_stmt_cache(wdb, 1) == -1) {
        return;
    }
}

produces this output:

#include <stdbool.h>

extern void __static_type_error(char *msg);
extern void __static_renaming(char *renaming, char *original);
extern void __static_condition_renaming(char *expression, char *renaming);

TODO: record original presence condition strings in file as well once raw strings are collected
void __static_initializer_default();

extern const bool __static_condition_default_7;
extern const bool __static_condition_default_8;
extern const bool __static_condition_default_9;
void __static_initializer_default() {
__static_renaming("__wdb_stmt_cache_2", "wdb_stmt_cache");
__static_renaming("__wdbi_update_completion_5", "wdbi_update_completion");
__static_renaming("__wdbi_update_completion_6", "wdbi_update_completion");

__static_condition_renaming("__static_condition_default_7", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert |(defined WAZUH_UNIT_TESTING)|)");
__static_condition_renaming("__static_condition_default_8", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert (not |(defined WAZUH_UNIT_TESTING)|))");
__static_condition_renaming("__static_condition_default_9", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert (not |(defined WAZUH_UNIT_TESTING)|))");

};
TODO: account for bitfield sizes in forward refs

int  __wdb_stmt_cache_2 (int  __wdb_0, int  __index_1);
void  __wdbi_update_completion_5 (int  __wdb_3) {

if (__static_condition_default_7) {
{

{
if (__static_condition_default_7) {
if (  __wdb_stmt_cache_2  (  __wdb_3 , 1 ) == - 1 ) {
return  ;

}



}

if (__static_condition_default_8) {
if (  __wdb_stmt_cache_2  ( 1 ) == - 1 ) {
return  ;

}



}

}}

}

}
static void  __wdbi_update_completion_6 (int  __wdb_4) {

if (__static_condition_default_9) {
{

{
if (__static_condition_default_7) {
if (  __wdb_stmt_cache_2  (  __wdb_3 , 1 ) == - 1 ) {
return  ;

}



}

if (__static_condition_default_8) {
if (  __wdb_stmt_cache_2  ( 1 ) == - 1 ) {
return  ;

}



}

}}

}

}

This results in two definitions of wdb_update_completion. The function calls exist in in static_condition_default_7/8. In 8, the wrong number of arguments are used.

Also, in wdb_update_completion_6, __wdb_3 is used in the call to wdb_stmt_cache_2, but __wdb_4 is what is defined in the arg list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant