File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,11 @@ use extism_pdk::*;
44pub fn http_get ( Json ( input) : Json < HttpRequest > ) -> FnResult < Memory > {
55 let res = http:: request :: < ( ) > ( & input, None ) ?;
66 let res = res. to_memory ( ) ?;
7+
8+ if res. offset ( ) == 0 {
9+ return Err ( WithReturnCode :: new ( Error :: msg ( "Failed to allocate memory" ) , 1 ) ) ;
10+ }
11+
712 Ok ( res)
813}
914
@@ -18,5 +23,10 @@ struct HttpRequestWithBody {
1823pub fn http_post ( Json ( input) : Json < HttpRequestWithBody > ) -> FnResult < Memory > {
1924 let res = http:: request :: < & str > ( & input. req , Some ( & input. data ) ) ?;
2025 let res = res. into_memory ( ) ;
26+
27+ if res. offset ( ) == 0 {
28+ return Err ( WithReturnCode :: new ( Error :: msg ( "Failed to allocate memory" ) , 1 ) ) ;
29+ }
30+
2131 Ok ( res)
2232}
Original file line number Diff line number Diff line change @@ -8,15 +8,21 @@ struct AllocRequest {
88
99#[ plugin_fn]
1010pub unsafe fn alloc_memory ( Json ( input) : Json < AllocRequest > ) -> FnResult < ( ) > {
11- _ = extism:: alloc ( input. bytes ) ;
11+ let offs = extism:: alloc ( input. bytes ) ;
12+ if offs == 0 {
13+ return Err ( WithReturnCode :: new ( Error :: msg ( "Failed to allocate memory" ) , 1 ) ) ;
14+ }
1215
1316 Ok ( ( ) )
1417}
1518
1619#[ plugin_fn]
1720pub unsafe fn alloc_var ( Json ( input) : Json < AllocRequest > ) -> FnResult < ( ) > {
1821 let buffer = vec ! [ 0u8 ; input. bytes as usize ] ;
19- _ = var:: set ( "buffer" , buffer) ;
22+
23+ if let Err ( e) = var:: set ( "buffer" , buffer) {
24+ return Err ( WithReturnCode :: from ( e) ) ;
25+ }
2026
2127 Ok ( ( ) )
2228}
You can’t perform that action at this time.
0 commit comments