@@ -114,23 +114,30 @@ int bytesPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface)
114114 // ----------------------------------------------------------------------------------------
115115 // Standard methods: version, builddate, defaultmethod, maxinterfaceversion
116116
117+ int err {0 };
117118 if (STR_IEQUALS (request->function , " help" )) {
118- return plugin.help (plugin_interface);
119+ err = plugin.help (plugin_interface);
119120 } else if (STR_IEQUALS (request->function , " version" )) {
120- return plugin.version (plugin_interface);
121+ err = plugin.version (plugin_interface);
121122 } else if (STR_IEQUALS (request->function , " builddate" )) {
122- return plugin.build_date (plugin_interface);
123+ err = plugin.build_date (plugin_interface);
123124 } else if (STR_IEQUALS (request->function , " defaultmethod" )) {
124- return plugin.default_method (plugin_interface);
125+ err = plugin.default_method (plugin_interface);
125126 } else if (STR_IEQUALS (request->function , " maxinterfaceversion" )) {
126- return plugin.max_interface_version (plugin_interface);
127+ err = plugin.max_interface_version (plugin_interface);
127128 } else if (STR_IEQUALS (request->function , " read" )) {
128- return plugin.read (plugin_interface);
129+ err = plugin.read (plugin_interface);
129130 } else if (STR_IEQUALS (request->function , " size" )) {
130- return plugin.size (plugin_interface);
131+ err = plugin.size (plugin_interface);
131132 } else {
132133 RAISE_PLUGIN_ERROR_AND_EXIT (" Unknown function requested!" , plugin_interface);
133134 }
135+
136+ if (err != 0 ) {
137+ concatUdaError (&plugin_interface->error_stack );
138+ }
139+ return err;
140+
134141 } catch (const std::exception& e) {
135142 std::string err_msg = std::string (" Excption raised in bytes plugin:" ) + e.what ();
136143 RAISE_PLUGIN_ERROR_AND_EXIT (err_msg.c_str (), plugin_interface);
@@ -203,19 +210,16 @@ int check_path(const Environment* environment, const std::string& path)
203210 // Block Access to External Users
204211
205212 if (environment->external_user ) {
206- err = 999 ;
207- addIdamError (UDA_CODE_ERROR_TYPE, " readBytes" , err, " This Service is Disabled" );
208213 UDA_LOG (UDA_LOG_DEBUG, " Disabled Service - Requested File: %s \n " , path.c_str ());
209- return err ;
214+ RAISE_PLUGIN_ERROR ( " This Service is Disabled " ) ;
210215 }
211216
212217 // ----------------------------------------------------------------------
213218 // Test the filepath
214219
215220 if (!IsLegalFilePath (path.c_str ())) {
216- err = 999 ;
217- addIdamError (UDA_CODE_ERROR_TYPE, " readBytes" , err, " The directory path has incorrect syntax" );
218221 UDA_LOG (UDA_LOG_DEBUG, " The directory path has incorrect syntax [%s] \n " , path.c_str ());
222+ RAISE_PLUGIN_ERROR (" The directory path has incorrect syntax" );
219223 return err;
220224 }
221225
@@ -239,10 +243,6 @@ int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
239243
240244 unsigned long offset = 0 ;
241245 FIND_UNSIGNED_LONG_VALUE (plugin_interface->request_data ->nameValueList , offset);
242- auto file_size = filesystem::file_size (path);
243- if (offset >= file_size) {
244- RAISE_PLUGIN_ERROR_AND_EXIT (" Offset specified is out of bounds" , plugin_interface);
245- }
246246
247247 const char * checksum = nullptr ;
248248 FIND_STRING_VALUE (plugin_interface->request_data ->nameValueList , checksum);
@@ -251,9 +251,9 @@ int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
251251
252252 char tmp_path[MAXPATH];
253253 StringCopy (tmp_path, path, MAXPATH);
254- UDA_LOG (UDA_LOG_DEBUG, " expand_environment_variables! \n " );
255254 expand_environment_variables (tmp_path);
256-
255+ UDA_LOG (UDA_LOG_DEBUG, " expand_environment_variables: path=%s \n " , tmp_path);
256+
257257 int rc = check_allowed_path (tmp_path);
258258 if (rc != 0 ) {
259259 return rc;
@@ -268,6 +268,14 @@ int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface)
268268 return rc;
269269 }
270270
271+ if (!filesystem::exists (tmp_path)) {
272+ std::string msg = std::string (" Path does not exist: " ) + tmp_path;
273+ RAISE_PLUGIN_ERROR (msg.c_str ());
274+ }
275+ if (offset >= filesystem::file_size (tmp_path)) {
276+ RAISE_PLUGIN_ERROR (" Offset specified is out of bounds" );
277+ }
278+
271279 errno = 0 ;
272280
273281 FILE* file = nullptr ;
@@ -301,7 +309,27 @@ int BytesPlugin::size(IDAM_PLUGIN_INTERFACE* plugin_interface)
301309 const char * path = " " ;
302310 FIND_REQUIRED_STRING_VALUE (plugin_interface->request_data ->nameValueList , path);
303311
304- size_t file_size = filesystem::file_size (path);
312+ char tmp_path[MAXPATH];
313+ StringCopy (tmp_path, path, MAXPATH);
314+ expand_environment_variables (tmp_path);
315+ UDA_LOG (UDA_LOG_DEBUG, " expand_environment_variables: path=%s \n " , tmp_path);
316+
317+ int rc = check_allowed_path (tmp_path);
318+ if (rc != 0 ) {
319+ return rc;
320+ }
321+
322+ rc = check_path (plugin_interface->environment , tmp_path);
323+ if (rc != 0 ) {
324+ return rc;
325+ }
326+
327+ if (!filesystem::exists (tmp_path)) {
328+ std::string msg = std::string (" Path does not exist: " ) + tmp_path;
329+ RAISE_PLUGIN_ERROR (msg.c_str ());
330+ }
331+
332+ size_t file_size = filesystem::file_size (tmp_path);
305333
306334 return setReturnDataLongScalar (data_block, (long )file_size, nullptr );
307335}
0 commit comments