diff options
| author | Namhyung Kim <namhyung.kim@lge.com> | 2012-04-08 22:54:33 -0400 |
|---|---|---|
| committer | Namhyung Kim <namhyung@kernel.org> | 2012-07-04 00:40:31 -0400 |
| commit | d286447f23cdb0337a5429e10b39761f6b1d5c18 (patch) | |
| tree | 8a7178790f2bc045796a51a50f60a15aeb3e5d70 /tools/lib/traceevent | |
| parent | ca63858e9eb0ce495031c4ab5291874835cb43cf (diff) | |
tools lib traceevent: Handle realloc() failure path
The realloc can fail so that we should handle it properly.
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1333940074-19052-7-git-send-email-namhyung.kim@lge.com
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/lib/traceevent')
| -rw-r--r-- | tools/lib/traceevent/event-parse.c | 76 |
1 files changed, 60 insertions, 16 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index cd334d52d333..05eb6b40b16a 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
| @@ -1264,9 +1264,15 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1264 | field->flags |= FIELD_IS_POINTER; | 1264 | field->flags |= FIELD_IS_POINTER; |
| 1265 | 1265 | ||
| 1266 | if (field->type) { | 1266 | if (field->type) { |
| 1267 | field->type = realloc(field->type, | 1267 | char *new_type; |
| 1268 | strlen(field->type) + | 1268 | new_type = realloc(field->type, |
| 1269 | strlen(last_token) + 2); | 1269 | strlen(field->type) + |
| 1270 | strlen(last_token) + 2); | ||
| 1271 | if (!new_type) { | ||
| 1272 | free(last_token); | ||
| 1273 | goto fail; | ||
| 1274 | } | ||
| 1275 | field->type = new_type; | ||
| 1270 | strcat(field->type, " "); | 1276 | strcat(field->type, " "); |
| 1271 | strcat(field->type, last_token); | 1277 | strcat(field->type, last_token); |
| 1272 | free(last_token); | 1278 | free(last_token); |
| @@ -1291,6 +1297,7 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1291 | if (strcmp(token, "[") == 0) { | 1297 | if (strcmp(token, "[") == 0) { |
| 1292 | enum event_type last_type = type; | 1298 | enum event_type last_type = type; |
| 1293 | char *brackets = token; | 1299 | char *brackets = token; |
| 1300 | char *new_brackets; | ||
| 1294 | int len; | 1301 | int len; |
| 1295 | 1302 | ||
| 1296 | field->flags |= FIELD_IS_ARRAY; | 1303 | field->flags |= FIELD_IS_ARRAY; |
| @@ -1310,9 +1317,14 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1310 | len = 1; | 1317 | len = 1; |
| 1311 | last_type = type; | 1318 | last_type = type; |
| 1312 | 1319 | ||
| 1313 | brackets = realloc(brackets, | 1320 | new_brackets = realloc(brackets, |
| 1314 | strlen(brackets) + | 1321 | strlen(brackets) + |
| 1315 | strlen(token) + len); | 1322 | strlen(token) + len); |
| 1323 | if (!new_brackets) { | ||
| 1324 | free(brackets); | ||
| 1325 | goto fail; | ||
| 1326 | } | ||
| 1327 | brackets = new_brackets; | ||
| 1316 | if (len == 2) | 1328 | if (len == 2) |
| 1317 | strcat(brackets, " "); | 1329 | strcat(brackets, " "); |
| 1318 | strcat(brackets, token); | 1330 | strcat(brackets, token); |
| @@ -1328,7 +1340,12 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1328 | 1340 | ||
| 1329 | free_token(token); | 1341 | free_token(token); |
| 1330 | 1342 | ||
| 1331 | brackets = realloc(brackets, strlen(brackets) + 2); | 1343 | new_brackets = realloc(brackets, strlen(brackets) + 2); |
| 1344 | if (!new_brackets) { | ||
| 1345 | free(brackets); | ||
| 1346 | goto fail; | ||
| 1347 | } | ||
| 1348 | brackets = new_brackets; | ||
| 1332 | strcat(brackets, "]"); | 1349 | strcat(brackets, "]"); |
| 1333 | 1350 | ||
| 1334 | /* add brackets to type */ | 1351 | /* add brackets to type */ |
| @@ -1339,10 +1356,16 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1339 | * the format: type [] item; | 1356 | * the format: type [] item; |
| 1340 | */ | 1357 | */ |
| 1341 | if (type == EVENT_ITEM) { | 1358 | if (type == EVENT_ITEM) { |
| 1342 | field->type = realloc(field->type, | 1359 | char *new_type; |
| 1343 | strlen(field->type) + | 1360 | new_type = realloc(field->type, |
| 1344 | strlen(field->name) + | 1361 | strlen(field->type) + |
| 1345 | strlen(brackets) + 2); | 1362 | strlen(field->name) + |
| 1363 | strlen(brackets) + 2); | ||
| 1364 | if (!new_type) { | ||
| 1365 | free(brackets); | ||
| 1366 | goto fail; | ||
| 1367 | } | ||
| 1368 | field->type = new_type; | ||
| 1346 | strcat(field->type, " "); | 1369 | strcat(field->type, " "); |
| 1347 | strcat(field->type, field->name); | 1370 | strcat(field->type, field->name); |
| 1348 | free_token(field->name); | 1371 | free_token(field->name); |
| @@ -1350,9 +1373,15 @@ static int event_read_fields(struct event_format *event, struct format_field **f | |||
| 1350 | field->name = token; | 1373 | field->name = token; |
| 1351 | type = read_token(&token); | 1374 | type = read_token(&token); |
| 1352 | } else { | 1375 | } else { |
| 1353 | field->type = realloc(field->type, | 1376 | char *new_type; |
| 1354 | strlen(field->type) + | 1377 | new_type = realloc(field->type, |
| 1355 | strlen(brackets) + 1); | 1378 | strlen(field->type) + |
| 1379 | strlen(brackets) + 1); | ||
| 1380 | if (!new_type) { | ||
| 1381 | free(brackets); | ||
| 1382 | goto fail; | ||
| 1383 | } | ||
| 1384 | field->type = new_type; | ||
| 1356 | strcat(field->type, brackets); | 1385 | strcat(field->type, brackets); |
| 1357 | } | 1386 | } |
| 1358 | free(brackets); | 1387 | free(brackets); |
| @@ -1735,10 +1764,16 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) | |||
| 1735 | /* could just be a type pointer */ | 1764 | /* could just be a type pointer */ |
| 1736 | if ((strcmp(arg->op.op, "*") == 0) && | 1765 | if ((strcmp(arg->op.op, "*") == 0) && |
| 1737 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { | 1766 | type == EVENT_DELIM && (strcmp(token, ")") == 0)) { |
| 1767 | char *new_atom; | ||
| 1768 | |||
| 1738 | if (left->type != PRINT_ATOM) | 1769 | if (left->type != PRINT_ATOM) |
| 1739 | die("bad pointer type"); | 1770 | die("bad pointer type"); |
| 1740 | left->atom.atom = realloc(left->atom.atom, | 1771 | new_atom = realloc(left->atom.atom, |
| 1741 | strlen(left->atom.atom) + 3); | 1772 | strlen(left->atom.atom) + 3); |
| 1773 | if (!new_atom) | ||
| 1774 | goto out_free; | ||
| 1775 | |||
| 1776 | left->atom.atom = new_atom; | ||
| 1742 | strcat(left->atom.atom, " *"); | 1777 | strcat(left->atom.atom, " *"); |
| 1743 | free(arg->op.op); | 1778 | free(arg->op.op); |
| 1744 | *arg = *left; | 1779 | *arg = *left; |
| @@ -2597,7 +2632,16 @@ process_arg_token(struct event_format *event, struct print_arg *arg, | |||
| 2597 | } | 2632 | } |
| 2598 | /* atoms can be more than one token long */ | 2633 | /* atoms can be more than one token long */ |
| 2599 | while (type == EVENT_ITEM) { | 2634 | while (type == EVENT_ITEM) { |
| 2600 | atom = realloc(atom, strlen(atom) + strlen(token) + 2); | 2635 | char *new_atom; |
| 2636 | new_atom = realloc(atom, | ||
| 2637 | strlen(atom) + strlen(token) + 2); | ||
| 2638 | if (!new_atom) { | ||
| 2639 | free(atom); | ||
| 2640 | *tok = NULL; | ||
| 2641 | free_token(token); | ||
| 2642 | return EVENT_ERROR; | ||
| 2643 | } | ||
| 2644 | atom = new_atom; | ||
| 2601 | strcat(atom, " "); | 2645 | strcat(atom, " "); |
| 2602 | strcat(atom, token); | 2646 | strcat(atom, token); |
| 2603 | free_token(token); | 2647 | free_token(token); |
