mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-04 00:51:49 +00:00 
			
		
		
		
	debug: bufferoverflow mitigation in DebugComponent::on_shutdown() (#9422)
This commit is contained in:
		
				
					committed by
					
						
						Jesse Hills
					
				
			
			
				
	
			
			
			
						parent
						
							a5055094d0
						
					
				
				
					commit
					5ba493acc3
				
			@@ -53,6 +53,7 @@ void DebugComponent::on_shutdown() {
 | 
			
		||||
  auto pref = global_preferences->make_preference(REBOOT_MAX_LEN, fnv1_hash(REBOOT_KEY + App.get_name()));
 | 
			
		||||
  if (component != nullptr) {
 | 
			
		||||
    strncpy(buffer, component->get_component_source(), REBOOT_MAX_LEN - 1);
 | 
			
		||||
    buffer[REBOOT_MAX_LEN - 1] = '\0';
 | 
			
		||||
  }
 | 
			
		||||
  ESP_LOGD(TAG, "Storing reboot source: %s", buffer);
 | 
			
		||||
  pref.save(&buffer);
 | 
			
		||||
@@ -68,6 +69,7 @@ std::string DebugComponent::get_reset_reason_() {
 | 
			
		||||
      auto pref = global_preferences->make_preference(REBOOT_MAX_LEN, fnv1_hash(REBOOT_KEY + App.get_name()));
 | 
			
		||||
      char buffer[REBOOT_MAX_LEN]{};
 | 
			
		||||
      if (pref.load(&buffer)) {
 | 
			
		||||
        buffer[REBOOT_MAX_LEN - 1] = '\0';
 | 
			
		||||
        reset_reason = "Reboot request from " + std::string(buffer);
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user