[openrtm-users 03050] Re: 報告: rtc.conf に空白行があると起きるエラー, coil::Properties::load()

原功 isao-hara @ aist.go.jp
2014年 6月 27日 (金) 08:54:27 JST


産技研 佐々木様:

産総研の原です。
ご報告ありがとうございます。
ご指摘の通りだと思います。現在の実装では、安全なコードとは言えませんね…。

ご提案のいずれかの方法で改修を検討したいと思います。

以上、よろしくお願いいたします。



2014年6月26日 22:09 <sasaki.akinori @ iri-tokyo.jp>:

> 東京都立産業技術研究センターの佐々木と申します。
>
>
> 既知の内容かもしれませんが,下記のような coil の実行時エラーに
> 遭遇しましたので報告いたします。
>
>
> テスト環境
> --------------
> - OpenRTM-aist-1.1.0-RELEASE (C++版), 32bit Windows版
>
> - Visual C++ 2010 Express Edition, 32bit
>
>   RTCBuilder + CMake で生成したソリューションファイルを利用し,
>   [Debug] 構成でRTコンポーネントをビルド
>
> - Windows 7 Professional (64bit)
>
>   (ただし,潜在的には環境に依存しないエラー)
>
>
> 実行時エラーの内容
> ----------------------
> RTコンポーネント(スタンドアローン)のロード時に
> 次のような assert 失敗 との メッセージウィンドウが表示される。
>
>       C:\***\xxxcomp.exe
>       File: c:\program files\microsoft visual studio
> 10.0\vc\include\xstring
>       Line: 1441
>
>       Expression: string subscript out of range
>
>       For information on how your program can cause an assertion
>       failure, see the Visual C++ documentation on asserts.
>
>       (Press Retry to debug the application)
>
>
>
> 実行時エラーが発生する条件
> --------------------------------
> - RTコンポーネントが読み込んだ rtc.conf に空白行があること
>   (行の位置には依存しない)
>
>
> 原因
> -------------
> coil::Properties::load() の実装
>
> In trunk/OpenRTM-aist/src/lib/coil/common/Properties.cpp, Line 344--349:
> (OpenRTM-aist-1.1.0-RELEASE においては,
>  */src/lib/coil/win32/coil/Properties.cpp)
>
>    342      while(!inStream.eof())
>    343        {
>    344          std::string tmp;
>    345          coil::getlinePortable(inStream, tmp);
>    346          coil::eraseHeadBlank(tmp);
>    347
>    348          // Skip comments or empty lines
>    349          if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
>    // 以下略
>
>    --> tmp.empty() == true のとき 第0要素も存在しないので
>        tmp[0] の評価時点で operator[] の実行中のどこかで assert に失敗する
>
>
> 改善案
> ---------
>
>   349c349
>   <       if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
>   ---
>   >       if (tmp.empty() || tmp[0] == '#' || tmp[0] == '!') continue;
>
>  --> ||演算子のオペランドは左から右に向かう順序で評価される
>      https://www.jpcert.or.jp/sc-rules/c-exp10-c.html
>
>
> もしくは,評価順序の知識なしで,実装の妥当性を判断できるように次のように変更
>
>   349c349,350
>   <       if (tmp[0] == '#' || tmp[0] == '!' || tmp == "") continue;
>   ---
>   >       if (tmp.empty()) continue;
>   >       if (tmp[0] == '#' || tmp[0] == '!') continue;
>
>
> --
> 地方独立行政法人 東京都立産業技術研究センター
> 事業化支援本部 技術開発支援部 ロボット開発セクター
> 佐々木 智典
>
>
> _______________________________________________
> openrtm-users mailing list
> openrtm-users @ openrtm.org
> http://www.openrtm.org/mailman/listinfo/openrtm-users
>



-- 
------------------------------------------------------------
産業技術総合研究所   知能システム研究部門
ディペンダブルシステム研究グループ 主任研究員
ソフトウェアプラットフォーム研究班 班長
原  功 <Isao-Hara @ aist.go.jp>
Isao HARA, Senior Researcher, ISRI, ,AIST,Japan
TEL: +81-29-861-5973
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
URL: <http://www.openrtm.org/pipermail/openrtm-users/attachments/20140627/388e2b21/attachment.html>


More information about the openrtm-users mailing list