Browse Source

Fix crash when Gemini response is missing CLRF

Not sure why this happens, it may be a server bug or issue with the content that I was testing with.
debug-epoch
Zane Ashby 10 months ago
parent
commit
fb2362d8ed
1 changed files with 5 additions and 0 deletions
  1. 5
    0
      src/gemini/client.rs

+ 5
- 0
src/gemini/client.rs View File

@@ -49,6 +49,11 @@ pub fn get_data<T: Protocol>(url: T) -> Result<(Option<Vec<u8>>, Vec<u8>), Strin
49 49
                                 stream.read_to_end(&mut res).unwrap();
50 50
 
51 51
                                 let clrf_idx = find_clrf(&res);
52
+
53
+                                if clrf_idx.is_none() {
54
+                                    return Err(format!("Failed to read response (missing clrf)"));
55
+                                }
56
+
52 57
                                 let content = res.split_off(clrf_idx.unwrap() + 2);
53 58
 
54 59
                                 Ok((Some(res), content))

Loading…
Cancel
Save