gitweb: Sanitize title attribute in format_subject_html

Replace control characters with question mark '?' (like in
chop_and_esc_str).

A little background: some web browsers turn on strict (and
unforgiving) XML validating mode for XHTML documents served using
application/xhtml+xml content type.  This means among others that
control characters are forbidden to appear in gitweb output.

CGI.pm does by default slight escaping (using simple_escape subroutine
from CGI::Util) of all _attribute_ values (depending on the value of
autoEscape, by default on).  This escaping, at least in CGI.pm version
3.10 (most current version at CPAN is 3.43), is minimal: only '"',
'&', '<' and '>' are escaped using named HTML entity references
(&quot;, &amp;, &lt; and &gt; respectively).  But simple_escape does
not do escaping of control characters such as ^X which are invalid in
XHTML (in strict mode).

If by some accident commit message do contain some control character
in first 50 characters (more or less) of first line of commit message,
and this line is longer than 50 characters (so gitweb shortens it for
display), then gitweb would put this control character in title
attribute (and CGI.pm would not remove them).  The tag _contents_ is
safe because it is escaped using esc_html() explicitly, and it
replaces control characters by their printable representation.

While at it: chop_and_escape_str doesn't need capturing group.

Noticed-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 36855d5d80d43c4cd413507e4fa18d2df6f0e736
  1. arm/
  2. compat/
  3. contrib/
  4. Documentation/
  5. git-gui/
  6. gitk-git/
  7. gitweb/
  8. mozilla-sha1/
  9. perl/
  10. ppc/
  11. t/
  12. templates/
  13. xdiff/
  14. .gitattributes
  15. .gitignore
  16. .mailmap
  17. abspath.c
  18. alias.c
  19. alloc.c
  20. archive-tar.c
  21. archive-zip.c
  22. archive.c
  23. archive.h
  24. attr.c
  25. attr.h
  26. base85.c
  27. bisect.c
  28. bisect.h
  29. blob.c
  30. blob.h
  31. branch.c
  32. branch.h
  33. builtin-add.c
  34. builtin-annotate.c
  35. builtin-apply.c
  36. builtin-archive.c
  37. builtin-bisect--helper.c
  38. builtin-blame.c
  39. builtin-branch.c
  40. builtin-bundle.c
  41. builtin-cat-file.c
  42. builtin-check-attr.c
  43. builtin-check-ref-format.c
  44. builtin-checkout-index.c
  45. builtin-checkout.c
  46. builtin-clean.c
  47. builtin-clone.c
  48. builtin-commit-tree.c
  49. builtin-commit.c
  50. builtin-config.c
  51. builtin-count-objects.c
  52. builtin-describe.c
  53. builtin-diff-files.c
  54. builtin-diff-index.c
  55. builtin-diff-tree.c
  56. builtin-diff.c
  57. builtin-fast-export.c
  58. builtin-fetch--tool.c
  59. builtin-fetch-pack.c
  60. builtin-fetch.c
  61. builtin-fmt-merge-msg.c
  62. builtin-for-each-ref.c
  63. builtin-fsck.c
  64. builtin-gc.c
  65. builtin-grep.c
  66. builtin-help.c
  67. builtin-http-fetch.c
  68. builtin-init-db.c
  69. builtin-log.c
  70. builtin-ls-files.c
  71. builtin-ls-remote.c
  72. builtin-ls-tree.c
  73. builtin-mailinfo.c
  74. builtin-mailsplit.c
  75. builtin-merge-base.c
  76. builtin-merge-file.c
  77. builtin-merge-ours.c
  78. builtin-merge-recursive.c
  79. builtin-merge.c
  80. builtin-mv.c
  81. builtin-name-rev.c
  82. builtin-pack-objects.c
  83. builtin-pack-refs.c
  84. builtin-prune-packed.c
  85. builtin-prune.c
  86. builtin-push.c
  87. builtin-read-tree.c
  88. builtin-receive-pack.c
  89. builtin-reflog.c
  90. builtin-remote.c
  91. builtin-rerere.c
  92. builtin-reset.c
  93. builtin-rev-list.c
  94. builtin-rev-parse.c
  95. builtin-revert.c
  96. builtin-rm.c
  97. builtin-send-pack.c
  98. builtin-shortlog.c
  99. builtin-show-branch.c
  100. builtin-show-ref.c
  101. builtin-stripspace.c
  102. builtin-symbolic-ref.c
  103. builtin-tag.c
  104. builtin-tar-tree.c
  105. builtin-unpack-objects.c
  106. builtin-update-index.c
  107. builtin-update-ref.c
  108. builtin-upload-archive.c
  109. builtin-verify-pack.c
  110. builtin-verify-tag.c
  111. builtin-write-tree.c
  112. builtin.h
  113. bundle.c
  114. bundle.h
  115. cache-tree.c
  116. cache-tree.h
  117. cache.h
  118. check-builtins.sh
  119. check-racy.c
  120. check_bindir
  121. color.c
  122. color.h
  123. combine-diff.c
  124. command-list.txt
  125. commit.c
  126. commit.h
  127. config.c
  128. config.mak.in
  129. configure.ac
  130. connect.c
  131. convert.c
  132. copy.c
  133. COPYING
  134. csum-file.c
  135. csum-file.h
  136. ctype.c
  137. daemon.c
  138. date.c
  139. decorate.c
  140. decorate.h
  141. delta.h
  142. diff-delta.c
  143. diff-lib.c
  144. diff-no-index.c
  145. diff.c
  146. diff.h
  147. diffcore-break.c
  148. diffcore-delta.c
  149. diffcore-order.c
  150. diffcore-pickaxe.c
  151. diffcore-rename.c
  152. diffcore.h
  153. dir.c
  154. dir.h
  155. editor.c
  156. entry.c
  157. environment.c
  158. exec_cmd.c
  159. exec_cmd.h
  160. fast-import.c
  161. fetch-pack.h
  162. fixup-builtins
  163. fsck.c
  164. fsck.h
  165. generate-cmdlist.sh
  166. git-add--interactive.perl
  167. git-am.sh
  168. git-archimport.perl
  169. git-bisect.sh
  170. git-compat-util.h
  171. git-cvsexportcommit.perl
  172. git-cvsimport.perl
  173. git-cvsserver.perl
  174. git-difftool--helper.sh
  175. git-difftool.perl
  176. git-filter-branch.sh
  177. git-instaweb.sh
  178. git-lost-found.sh
  179. git-merge-octopus.sh
  180. git-merge-one-file.sh
  181. git-merge-resolve.sh
  182. git-mergetool--lib.sh
  183. git-mergetool.sh
  184. git-parse-remote.sh
  185. git-pull.sh
  186. git-quiltimport.sh
  187. git-rebase--interactive.sh
  188. git-rebase.sh
  189. git-relink.perl
  190. git-repack.sh
  191. git-request-pull.sh
  192. git-send-email.perl
  193. git-sh-setup.sh
  194. git-stash.sh
  195. git-submodule.sh
  196. git-svn.perl
  197. GIT-VERSION-GEN
  198. git-web--browse.sh
  199. git.c
  200. git.spec.in
  201. graph.c
  202. graph.h
  203. grep.c
  204. grep.h
  205. hash-object.c
  206. hash.c
  207. hash.h
  208. help.c
  209. help.h
  210. http-push.c
  211. http-walker.c
  212. http.c
  213. http.h
  214. ident.c
  215. imap-send.c
  216. index-pack.c
  217. INSTALL
  218. levenshtein.c
  219. levenshtein.h
  220. list-objects.c
  221. list-objects.h
  222. ll-merge.c
  223. ll-merge.h
  224. lockfile.c
  225. log-tree.c
  226. log-tree.h
  227. mailmap.c
  228. mailmap.h
  229. Makefile
  230. match-trees.c
  231. merge-file.c
  232. merge-index.c
  233. merge-recursive.c
  234. merge-recursive.h
  235. merge-tree.c
  236. mktag.c
  237. mktree.c
  238. name-hash.c
  239. object.c
  240. object.h
  241. pack-check.c
  242. pack-redundant.c
  243. pack-refs.c
  244. pack-refs.h
  245. pack-revindex.c
  246. pack-revindex.h
  247. pack-write.c
  248. pack.h
  249. pager.c
  250. parse-options.c
  251. parse-options.h
  252. patch-delta.c
  253. patch-id.c
  254. patch-ids.c
  255. patch-ids.h
  256. path.c
  257. pkt-line.c
  258. pkt-line.h
  259. preload-index.c
  260. pretty.c
  261. progress.c
  262. progress.h
  263. quote.c
  264. quote.h
  265. reachable.c
  266. reachable.h
  267. read-cache.c
  268. README
  269. reflog-walk.c
  270. reflog-walk.h
  271. refs.c
  272. refs.h
  273. remote.c
  274. remote.h
  275. rerere.c
  276. rerere.h
  277. revision.c
  278. revision.h
  279. run-command.c
  280. run-command.h
  281. send-pack.h
  282. server-info.c
  283. setup.c
  284. sha1-lookup.c
  285. sha1-lookup.h
  286. sha1_file.c
  287. sha1_name.c
  288. shallow.c
  289. shell.c
  290. shortlog.h
  291. show-index.c
  292. sideband.c
  293. sideband.h
  294. sigchain.c
  295. sigchain.h
  296. strbuf.c
  297. strbuf.h
  298. string-list.c
  299. string-list.h
  300. symlinks.c
  301. tag.c
  302. tag.h
  303. tar.h
  304. test-chmtime.c
  305. test-ctype.c
  306. test-date.c
  307. test-delta.c
  308. test-dump-cache-tree.c
  309. test-genrandom.c
  310. test-match-trees.c
  311. test-parse-options.c
  312. test-path-utils.c
  313. test-sha1.c
  314. test-sha1.sh
  315. test-sigchain.c
  316. thread-utils.c
  317. thread-utils.h
  318. trace.c
  319. transport.c
  320. transport.h
  321. tree-diff.c
  322. tree-walk.c
  323. tree-walk.h
  324. tree.c
  325. tree.h
  326. unimplemented.sh
  327. unpack-file.c
  328. unpack-trees.c
  329. unpack-trees.h
  330. update-server-info.c
  331. upload-pack.c
  332. usage.c
  333. userdiff.c
  334. userdiff.h
  335. utf8.c
  336. utf8.h
  337. var.c
  338. walker.c
  339. walker.h
  340. wrapper.c
  341. write_or_die.c
  342. ws.c
  343. wt-status.c
  344. wt-status.h
  345. xdiff-interface.c
  346. xdiff-interface.h