2323// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2424// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
2627#include " sagemaker_server.h"
2728
2829namespace triton { namespace server {
@@ -291,6 +292,15 @@ SagemakerAPIServer::ParseSageMakerRequest(
291292 }
292293 }
293294
295+ if (url_string.find (" /dev/" ) == 0 || url_string.find (" /proc/" ) == 0 ||
296+ url_string.find (" /sys/" ) == 0 ) {
297+ LOG_ERROR << " Invalid URL: " << url_string
298+ << " . \" url\" property value cannot start with /dev/, /proc/, or "
299+ " /sys/." << std::endl;
300+ evhtp_send_reply (req, EVHTP_RES_BADREQ );
301+ return ;
302+ }
303+
294304 if (action == " load" ) {
295305 (*parse_map)[" url" ] = url_string.c_str ();
296306 }
@@ -895,6 +905,15 @@ SagemakerAPIServer::SageMakerMMELoadModel(
895905 std::string model_name_hash = parse_map.at (" model_name_hash" );
896906 std::string target_model = parse_map.at (" target_model" );
897907
908+ if (repo_path.find (" /dev/" ) == 0 || repo_path.find (" /proc/" ) == 0 ||
909+ repo_path.find (" /sys/" ) == 0 ) {
910+ LOG_ERROR << " Invalid repository path: " << repo_path
911+ << " . \" url\" property of `parse_map`cannot start with /dev/, "
912+ " /proc/, or /sys/." << std::endl;
913+ evhtp_send_reply (req, EVHTP_RES_BADREQ );
914+ return ;
915+ }
916+
898917 /* Check subdirs for models and find ensemble model within the repo_path
899918 * If only 1 model, that will be selected as model_subdir
900919 * Else ensemble model directory is set as model_subdir
@@ -905,6 +924,7 @@ SagemakerAPIServer::SageMakerMMELoadModel(
905924 std::string model_subdir, ensemble_model_subdir;
906925
907926 if ((dir = opendir (repo_path.c_str ())) != NULL ) {
927+ std::shared_ptr<DIR > dir_ptr{dir, closedir};
908928 while ((ent = readdir (dir)) != NULL ) {
909929 if ((ent->d_type == DT_DIR ) && (!strcmp (ent->d_name , " ." ) == 0 ) &&
910930 (!strcmp (ent->d_name , " .." ) == 0 )) {
@@ -923,7 +943,7 @@ SagemakerAPIServer::SageMakerMMELoadModel(
923943
924944 // Read the config.pbtxt file at each path, if available
925945 std::string ensemble_config_path =
926- repo_path + " /" + model_subdir + " /" + " config.pbtxt" ;
946+ repo_path + " /" + model_subdir + " /config.pbtxt" ;
927947 std::ifstream config_fstream (ensemble_config_path);
928948 std::stringstream ensemble_config_content;
929949
@@ -954,7 +974,6 @@ SagemakerAPIServer::SageMakerMMELoadModel(
954974 << std::endl;
955975 }
956976 }
957- closedir (dir);
958977 }
959978
960979 if (!strcmp (ensemble_model_subdir.c_str (), " " ) == 0 ) {
0 commit comments