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

cplus_replace_std_multiset() UAF #59

Open
XVilka opened this issue Sep 11, 2023 · 0 comments
Open

cplus_replace_std_multiset() UAF #59

XVilka opened this issue Sep 11, 2023 · 0 comments
Assignees
Labels
C++ C++ demangling

Comments

@XVilka
Copy link
Member

XVilka commented Sep 11, 2023

static char *cplus_replace_std_multiset(char *input) {
225        char *p = strstr(input, "std::multiset<");
   	1. Condition !p, taking false branch.
226        if (!p) {
227                return input;
228        }
229        p += strlen("std::multiset<");
230        size_t length = cplus_find_type_length(p);
   	2. Condition length < 1, taking false branch.
231        if (length < 1) {
232                return input;
233        }
234        char *ktype = dem_str_ndup(p, length);
235        char *replace = dem_str_newf("std::multiset<%s>", ktype);
236        char *search = dem_str_newf("std::multiset<%s, std::less<%s>, std::allocator<%s> >", ktype, ktype, ktype);
   	3. freed_arg: dem_str_replace frees input. [[show details](https://scan3.scan.coverity.com/eventId=13166125-4&modelId=13166125-0&fileInstanceId=100856536&filePath=%2Fsubprojects%2Flibdemangle%2Fsrc%2Fdemangler_util.c&fileStart=33&fileEnd=77)]
237        char *output = dem_str_replace(input, search, replace, 1);
238        free(search);
239        // sometimes std::allocator has an extra space
240        search = dem_str_newf("std::multiset<%s, std::less<%s>, std::allocator<%s > >", ktype, ktype, ktype);
241        output = dem_str_replace(output, search, replace, 1);
242        free(search);
243        search = dem_str_newf("std::multiset<%s, std::greater<%s>, std::allocator<%s> >", ktype, ktype, ktype);
   	
CID 416049 (#1-6 of 6): Use after free (USE_AFTER_FREE)
4. pass_freed_arg: Passing freed pointer input as an argument to dem_str_replace.
244        output = dem_str_replace(input, search, replace, 1);
245        free(search);
246        // sometimes std::allocator has an extra space
247        search = dem_str_newf("std::multiset<%s, std::greater<%s>, std::allocator<%s > >", ktype, ktype, ktype);
248        output = dem_str_replace(output, search, replace, 1);
249        free(search);
250        free(replace);
251        free(ktype);
252        return output;
253}
@XVilka XVilka added the C++ C++ demangling label Sep 11, 2023
@wargio wargio self-assigned this Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ C++ demangling
Projects
None yet
Development

No branches or pull requests

2 participants