From d36f8ac54252b9ba8dfc66e587d64c998f63ffb2 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sun, 14 Nov 2010 12:18:48 +0000 Subject: [PATCH] * fixed potential buffer overflow error when creating the fullprocname for display purposes if there was a parameter with a default value > 255 chars * replace #0, #10 and #13 in the fullprocname with '.' so they do not cause line breaks or early string termination when writing them to the assembler file (mantis #17928) git-svn-id: trunk@16344 - --- .gitattributes | 1 + compiler/symdef.pas | 13 +++++++++++-- tests/webtbs/tw17928.pp | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/webtbs/tw17928.pp diff --git a/.gitattributes b/.gitattributes index 152c1647a3..ec68fa8de1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -10748,6 +10748,7 @@ tests/webtbs/tw17907/test.bat svneol=native#text/plain tests/webtbs/tw17907/unit1/unit0001.pas svneol=native#text/plain tests/webtbs/tw17907/unit2/unit0002.pas svneol=native#text/plain tests/webtbs/tw1792.pp svneol=native#text/plain +tests/webtbs/tw17928.pp svneol=native#text/plain tests/webtbs/tw1792a.pp svneol=native#text/plain tests/webtbs/tw1798.pp svneol=native#text/plain tests/webtbs/tw1820.pp svneol=native#text/plain diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 63b2c58233..4053bab106 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -2974,8 +2974,17 @@ implementation begin If hpc.value.len>0 then begin - setLength(hs,hpc.value.len); - move(hpc.value.valueptr^,hs[1],hpc.value.len); + setLength(hs,hpc.value.len); + { don't write past the end of hs if the constant + is > 255 chars } + move(hpc.value.valueptr^,hs[1],length(hs)); + { make sure that constant strings with newline chars + don't create a linebreak in the assembler code, + since comments are line-based. Also remove nulls + because the comments are written as a pchar. } + ReplaceCase(hs,#0,'.'); + ReplaceCase(hs,#10,'.'); + ReplaceCase(hs,#13,'.'); end; end; constreal : diff --git a/tests/webtbs/tw17928.pp b/tests/webtbs/tw17928.pp new file mode 100644 index 0000000000..8471f9aeaf --- /dev/null +++ b/tests/webtbs/tw17928.pp @@ -0,0 +1,11 @@ +{ %norun } +{ %opt=-a } + +{$mode delphi} + +procedure AddItemsFromString(const aItems: String; const aSeparator: String = #13#10); +begin +end; + +begin +end.