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

Uninitialized memory leading to crash #2217

Closed
marcstern opened this issue Dec 12, 2019 · 3 comments
Closed

Uninitialized memory leading to crash #2217

marcstern opened this issue Dec 12, 2019 · 3 comments
Labels
2.x Related to ModSecurity version 2.x

Comments

@marcstern
Copy link
Contributor

In apache2/persist_dbm.c, in collection_store(), we have the following declaration:
char *username;

The variable is supposed to be initialized on line 392:
apr_uid_name_get(&username, uid, msr->mp);

In case there's a problem in apr_uid_name_get(), the variable is not initialized. This leads to a crash on line 412:
dbm_filename = apr_pstrcat(msr->, "/", username, ...

If username is initialized to a static empty string, no more crash.
char *username = "";
We could also check apr_uid_name_get() return code and initialize username only in case of error but this would be less efficient and add useless code.

No idea why the function apr_uid_name_get() fails in my environment, but this can be reproduced easily in a debugger.

The fix is anyway safe and aligned with good practices.

@zimmerle zimmerle added the 2.x Related to ModSecurity version 2.x label Dec 13, 2019
@marcstern
Copy link
Contributor Author

Here is the a centralized function we're using for years:

char* get_username(apr_pool_t* mp) {
 char* username;
 apr_uid_t uid;
 apr_gid_t gid;
 int rc = apr_uid_current(&uid, &gid, mp);
 if (rc != APR_SUCCESS) return "apache";
 rc = apr_uid_name_get(&username, uid, mp);
 if (rc != APR_SUCCESS) return "apache";
 return username;
}

@marcstern
Copy link
Contributor Author

This is a duplicate of #2046

@martinhsv
Copy link
Contributor

Right. This was a duplicate.

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

No branches or pull requests

3 participants