| .. | .. |
|---|
| 525 | 525 | |
|---|
| 526 | 526 | pr_debug("llvm compiling command template: %s\n", template); |
|---|
| 527 | 527 | |
|---|
| 528 | + /* |
|---|
| 529 | + * Below, substitute control characters for values that can cause the |
|---|
| 530 | + * echo to misbehave, then substitute the values back. |
|---|
| 531 | + */ |
|---|
| 528 | 532 | err = -ENOMEM; |
|---|
| 529 | | - if (asprintf(&command_echo, "echo -n \"%s\"", template) < 0) |
|---|
| 533 | + if (asprintf(&command_echo, "echo -n \a%s\a", template) < 0) |
|---|
| 530 | 534 | goto errout; |
|---|
| 531 | 535 | |
|---|
| 536 | +#define SWAP_CHAR(a, b) do { if (*p == a) *p = b; } while (0) |
|---|
| 537 | + for (char *p = command_echo; *p; p++) { |
|---|
| 538 | + SWAP_CHAR('<', '\001'); |
|---|
| 539 | + SWAP_CHAR('>', '\002'); |
|---|
| 540 | + SWAP_CHAR('"', '\003'); |
|---|
| 541 | + SWAP_CHAR('\'', '\004'); |
|---|
| 542 | + SWAP_CHAR('|', '\005'); |
|---|
| 543 | + SWAP_CHAR('&', '\006'); |
|---|
| 544 | + SWAP_CHAR('\a', '"'); |
|---|
| 545 | + } |
|---|
| 532 | 546 | err = read_from_pipe(command_echo, (void **) &command_out, NULL); |
|---|
| 533 | 547 | if (err) |
|---|
| 534 | 548 | goto errout; |
|---|
| 535 | 549 | |
|---|
| 550 | + for (char *p = command_out; *p; p++) { |
|---|
| 551 | + SWAP_CHAR('\001', '<'); |
|---|
| 552 | + SWAP_CHAR('\002', '>'); |
|---|
| 553 | + SWAP_CHAR('\003', '"'); |
|---|
| 554 | + SWAP_CHAR('\004', '\''); |
|---|
| 555 | + SWAP_CHAR('\005', '|'); |
|---|
| 556 | + SWAP_CHAR('\006', '&'); |
|---|
| 557 | + } |
|---|
| 558 | +#undef SWAP_CHAR |
|---|
| 536 | 559 | pr_debug("llvm compiling command : %s\n", command_out); |
|---|
| 537 | 560 | |
|---|
| 538 | 561 | err = read_from_pipe(template, &obj_buf, &obj_buf_sz); |
|---|