27.05.2009, 09:05 | #1 |
Участник
|
gatesasbait: Basic calculator using runbuf() in Dynamics AX
Источник: http://gatesasbait.spaces.live.com/B...B9F5!398.entry
============== Good evening, If you ever need to build a mathematical calculator in Dynamics AX, you might consider using runbuf() as basis for the code. The only critical considerations are to make sure that an attacker cannot use the calculator to execute code other than mathematical functions. Here’s a quick example of what the calc() code for the calculator might look like (in a job): X++: public static void calcExample(Args _args) { real ret; str formula = "(30+20)*(2)"; //user might type this into a textbox on a form ; ret = runbuf( strfmt( "real calc()\n" +"{\n" +" ;\n" +" return %1;\n" +"}\n", formula)); info(SysQuery::value(ret)); } An added advantage of using runbuf() this way, is that it gives the user the ability to use mathematical functions defined in AX like abs() acos(), asin(), atan(), etc. Источник: http://gatesasbait.spaces.live.com/B...B9F5!398.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
27.05.2009, 11:24 | #2 |
Участник
|
маленький комментарий: помните о безопасном программировании!
сейчас в коде нет никаких проверок на валидность, никакой проверки на компилируемость, никакой обработки ошибок, никаких try/catch. а также никакой проверки на безопасность пользовательского кода. А ведь он может вызвать shell с командой format в боевых условиях такое грязное программирование может быть чревато страшными и необъяснимыми глюками. |
|
27.05.2009, 12:12 | #3 |
Боец
|
Согласен. Безопасность нужно учесть.
1. Добавить проверку на содержание только арифметических составляющих и чисел. 2. (Правильное оформление) Результат арифметического выражения: "2*2" в 4. Как? А то добавит работник себе бонуса к зарплате.., за что с кого-нибудь потом спросят... |
|
27.05.2009, 13:52 | #4 |
Участник
|
А еще можно просто пользоваться калькулятором в меню Сервис\Калькулятор
It's secure, great functionality, 0 effort - GREAT |
|
27.05.2009, 14:10 | #5 |
Боец
|
Цитата:
Но на самом деле пример полезен. Мне вот доводилось иметь дело с функциональностью, которая подразумевала ввод арифметических выражений пользователем в строки формы (набодобие excel). Затем при разноске эти выражения считались. Т.е. можно было строить сложные пользовательские выражения. |
|
|
За это сообщение автора поблагодарили: gatesasbait (1). |
29.05.2009, 00:13 | #6 |
Ax & C# programmer
|
Mazzy: I totally agree with you. If opening up calls to runbuf() for users, we need to be vary careful and remove any calls to functions that are not mathematical. Take for example the product builder, I do not believe it is secured, attack is possible, as well as when creating data import definitions, the conversion tabs are open for attack too.
KashperUK: True, the standard microsoft calc.exe is the ideal and safest calculator, however the idea of using runbuf() came from a brainstorm for a customer that needed a way to create custom formulas for forecasting in AX, I proposed using runbuf, I however will not be taking care of the actual project. The choice is up to them. Great forum btw, and a very useful bot for the AX community. |
|
|
За это сообщение автора поблагодарили: mazzy (2). |
|
|