Fix uninformative hp2ps error when the cmdline contains double quotes
authorZejun Wu <watashi@fb.com>
Thu, 22 Nov 2018 16:51:15 +0000 (11:51 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 22 Nov 2018 18:14:01 +0000 (13:14 -0500)
commit390df8b51b917fb6409cbde8e73fe838d61d8832
tree68c81cf31c7ceed3f69f8d9cdb07fe79db2152b8
parent599eaada382d04722219bfc319bde94591be3fb1
Fix uninformative hp2ps error when the cmdline contains double quotes

The format of hp file didn't allow double quotes inside strings, and
under prof build, we include args in JOB, which may have double quotes.
When this happens, the error message is confusing to the user. This can
also happen under normal build if the executable name contains double
quite, which is unlikely though.

We fix this issue by introducing escaping for double quotes inside a
string by repeating it twice.

We also fix a buffer overflow bug when the length of the string happen
to be multiple of 5000.

Test Plan:
new tests, which used to fail with error message:

```
hp2ps: "T15904".hp, line 2: integer must follow identifier
```

use new ghc and hp2ps to profile a simple program.

Reviewers: simonmar, bgamari, erikd

Reviewed By: simonmar

Subscribers: rwbarton, carter

GHC Trac Issues: #15904

Differential Revision: https://phabricator.haskell.org/D5346
rts/ProfHeap.c
testsuite/tests/hp2ps/Makefile [new file with mode: 0644]
testsuite/tests/hp2ps/T15904.hs [new file with mode: 0644]
testsuite/tests/hp2ps/T15904.stdout [new file with mode: 0644]
testsuite/tests/hp2ps/all.T [new file with mode: 0644]
utils/hp2ps/HpFile.c