Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize vector holding ip address to correct size #88

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/httporigdst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl Default for NgxHttpOrigDstCtx {

impl NgxHttpOrigDstCtx {
pub fn save(&mut self, addr: &str, port: in_port_t, pool: &mut core::Pool) -> core::Status {
let addr_data = pool.alloc(IPV4_STRLEN);
let addr_data = pool.alloc(addr.len());
if addr_data.is_null() {
return core::Status::NGX_ERROR;
}
unsafe { libc::memcpy(addr_data, addr.as_ptr() as *const c_void, IPV4_STRLEN) };
self.orig_dst_addr.len = IPV4_STRLEN;
unsafe { libc::memcpy(addr_data, addr.as_ptr() as *const c_void, addr.len()) };
self.orig_dst_addr.len = addr.len();
self.orig_dst_addr.data = addr_data as *mut u8;

let port_str = port.to_string();
Expand Down Expand Up @@ -204,6 +204,7 @@ unsafe fn ngx_get_origdst(request: &mut http::Request) -> Result<(String, in_por
ngx_log_debug_http!(request, "httporigdst: ngx_sock_ntop failed to convert sockaddr");
return Err(core::Status::NGX_ERROR);
}
ip.truncate(e);

let port = unsafe { ngx_inet_get_port(std::ptr::addr_of_mut!(addr) as *mut sockaddr) };

Expand Down