Skip to content

Commit

Permalink
Use snprintf and add extra check on invalid hex values. (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio authored Nov 12, 2023
1 parent 3eb0ef8 commit 8b8f7f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/gnu_v2/cplus-dem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ type_kind_t tk;
string_append(s, work->tmpl_argvec[idx]);
else {
char buf[10];
sprintf(buf, "T%d", idx);
snprintf(buf, sizeof(buf), "T%d", idx);
string_append(s, buf);
}
} else if (tk == tk_integral)
Expand Down Expand Up @@ -1328,7 +1328,7 @@ int remember;
string_append(trawname, work->tmpl_argvec[idx]);
} else {
char buf[10];
sprintf(buf, "T%d", idx);
snprintf(buf, sizeof(buf), "T%d", idx);
string_append(tname, buf);
if (trawname)
string_append(trawname, buf);
Expand Down Expand Up @@ -2056,7 +2056,7 @@ string *declp;

if (method) {
char buf[50];
sprintf(buf, "virtual function thunk (delta:%d) for ", -delta);
snprintf(buf, sizeof(buf), "virtual function thunk (delta:%d) for ", -delta);
string_append(declp, buf);
string_append(declp, method);
free(method);
Expand Down Expand Up @@ -2689,7 +2689,7 @@ string *result;
string_append(result, work->tmpl_argvec[idx]);
else {
char buf[10];
sprintf(buf, "T%d", idx);
snprintf(buf, sizeof(buf), "T%d", idx);
string_append(result, buf);
}

Expand Down Expand Up @@ -2863,8 +2863,9 @@ string *result;
(*mangled)++;
for (i = 0;
i < sizeof(buf) - 1 && **mangled && **mangled != '_';
(*mangled)++, i++)
(*mangled)++, i++) {
buf[i] = **mangled;
}
if (**mangled != '_') {
success = 0;
break;
Expand All @@ -2877,7 +2878,11 @@ string *result;
*mangled += min(strlen(*mangled), 2);
}
sscanf(buf, "%x", &dec);
sprintf(buf, "int%i_t", dec);
if (dec > 64 || dec < 8) {
success = 0;
break;
}
snprintf(buf, sizeof(buf), "int%i_t", dec);
APPEND_BLANK(result);
string_append(result, buf);
break;
Expand Down
1 change: 1 addition & 0 deletions test/test_cxx_gnu_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mu_demangle_tests(gnu_v2,
mu_demangle_test("foo__1Ai", "A::foo(int)"),
mu_demangle_test("foo__1Afe", "A::foo(float,...)"),
mu_demangle_test("_AddColor__10ZafDisplayUcUcUcUcUc", "ZafDisplay::_AddColor(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)"),
mu_demangle_test("I_EEEEET_PNS0_7IsolateENS0_7Runtime10FunctionIdEPKNS2_16TSCallDescriptorENS2_7OpIndexESU_RKT0_", NULL),
// end
);

Expand Down

0 comments on commit 8b8f7f3

Please sign in to comment.