Skip to content

Commit 82969f8

Browse files
author
Andrej Mihajlov
committed
Merge branch 'fix-service-config-segfault'
2 parents 309f842 + a5bf17e commit 82969f8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8-
8+
### Fixed
9+
- Fix segmentation fault in `Service` functions, that query service config, by moving buffer
10+
allocation on heap.
911

1012
## [0.3.0] - 2020-06-18
1113
### Added

src/service.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ impl Service {
14241424
/// Get the service config from the system.
14251425
pub fn query_config(&self) -> crate::Result<ServiceConfig> {
14261426
// As per docs, the maximum size of data buffer used by QueryServiceConfigW is 8K
1427-
let mut data = [0u8; MAX_QUERY_BUFFER_SIZE];
1427+
let mut data = vec![0u8; MAX_QUERY_BUFFER_SIZE];
14281428
let mut bytes_written: u32 = 0;
14291429

14301430
let success = unsafe {
@@ -1512,7 +1512,7 @@ impl Service {
15121512
/// Query the system for the boolean indication that the service is configured to run failure
15131513
/// actions on non-crash failures.
15141514
pub fn get_failure_actions_on_non_crash_failures(&self) -> crate::Result<bool> {
1515-
let mut data = [0u8; MAX_QUERY_BUFFER_SIZE];
1515+
let mut data = vec![0u8; MAX_QUERY_BUFFER_SIZE];
15161516

15171517
let raw_failure_actions_flag: winsvc::SERVICE_FAILURE_ACTIONS_FLAG = unsafe {
15181518
self.query_config2(winsvc::SERVICE_CONFIG_FAILURE_ACTIONS_FLAG, &mut data)
@@ -1547,7 +1547,7 @@ impl Service {
15471547
/// Query the configured failure actions for the service.
15481548
pub fn get_failure_actions(&self) -> crate::Result<ServiceFailureActions> {
15491549
unsafe {
1550-
let mut data = [0u8; MAX_QUERY_BUFFER_SIZE];
1550+
let mut data = vec![0u8; MAX_QUERY_BUFFER_SIZE];
15511551

15521552
let raw_failure_actions: winsvc::SERVICE_FAILURE_ACTIONSW = self
15531553
.query_config2(winsvc::SERVICE_CONFIG_FAILURE_ACTIONS, &mut data)
@@ -1657,11 +1657,7 @@ impl Service {
16571657
}
16581658

16591659
/// Private helper to query the optional configuration parameters of windows services.
1660-
unsafe fn query_config2<T: Copy>(
1661-
&self,
1662-
kind: DWORD,
1663-
data: &mut [u8; MAX_QUERY_BUFFER_SIZE],
1664-
) -> io::Result<T> {
1660+
unsafe fn query_config2<T: Copy>(&self, kind: DWORD, data: &mut [u8]) -> io::Result<T> {
16651661
let mut bytes_written: u32 = 0;
16661662

16671663
let success = winsvc::QueryServiceConfig2W(

0 commit comments

Comments
 (0)