Skip to content

Conversation

aiodinlabs01
Copy link

This fix addresses a critical bug in Salt's kernelpkg_linux_apt module where the latest_available() function would crash with AttributeError on modern Debian and Ubuntu systems due to a regex pattern that couldn't parse current package version formats.

Problem

The kernelpkg.latest_available() function used a regex pattern that expected version formats like '6.1.0.147' but modern Debian/Ubuntu package managers return formats like:

  • Debian 12: '6.1.147-1'
  • Ubuntu 24.04: '6.8.0-45-generic'
  • Debian 11: '5.10.0-18-amd64'

The original regex ^(\d+.\d+.\d+).(\d+) failed to match these formats, causing:
AttributeError: 'NoneType' object has no attribute 'group'

This made kernelpkg.latest_available() completely unusable on:

  • Debian 11 (Bullseye)
  • Debian 12 (Bookworm)
  • Ubuntu 22.04 (Jammy)
  • Ubuntu 23.04 (Lunar)
  • Ubuntu 24.04 (Noble)

Root Cause

In salt/modules/kernelpkg_linux_apt.py line 86, the regex pattern was too restrictive:

Solution

Updated the regex pattern to handle modern Debian/Ubuntu version formats:

Key Improvements:

  1. Broader compatibility: Handles both dash and dot separators
  2. Fallback mechanism: Returns latest_installed() if regex fails completely
  3. Format detection: Distinguishes between simple Debian and complex Ubuntu formats
  4. Graceful degradation: Never crashes, always returns a usable result

Testing

Added comprehensive test suite with 16 test cases covering:

  • All problematic version formats from the issue
  • Debian 11, 12 (Bookworm) formats
  • Ubuntu 22.04, 23.04, 24.04 (Noble) formats
  • Security updates, backports, complex formats
  • Fallback behavior for malformed versions
  • Regression prevention for edge cases

Test Results:

Impact

  • Fixes kernelpkg.latest_available() on all modern Debian/Ubuntu systems
  • Maintains 100% backward compatibility
  • No breaking changes to existing functionality
  • Comprehensive test coverage prevents future regressions
  • Graceful fallback handling for unexpected version formats

Version Compatibility Matrix

| Distribution | Version | Before Fix | After Fix | |--------------|---------|------------|-----------| | Debian 11 (Bullseye) | 5.10.0-18-amd64 | ❌ Crash | ✅ Works | | Debian 12 (Bookworm) | 6.1.147-1 | ❌ Crash | ✅ Works | | Ubuntu 22.04 (Jammy) | 5.15.0-91-generic | ❌ Crash | ✅ Works | | Ubuntu 23.04 (Lunar) | 6.2.0-37-generic | ❌ Crash | ✅ Works | | Ubuntu 24.04 (Noble) | 6.8.0-45-generic | ❌ Crash | ✅ Works | | Security Updates | 6.1.147-1+deb12u1 | ❌ Crash | ✅ Works | | Backports | 6.1.147-1~bpo11+1 | ❌ Crash | ✅ Works |

Fixes #68204

What does this PR do?

What issues does this PR fix or reference?

Fixes

Previous Behavior

Remove this section if not relevant

New Behavior

Remove this section if not relevant

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes/No

Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a changelog

…le (saltstack#68204)

This fix addresses a critical bug in Salt's kernelpkg_linux_apt module where the
latest_available() function would crash with AttributeError on modern Debian and
Ubuntu systems due to a regex pattern that couldn't parse current package version formats.

## Problem
The kernelpkg.latest_available() function used a regex pattern that expected version
formats like '6.1.0.147' but modern Debian/Ubuntu package managers return formats like:
- Debian 12: '6.1.147-1'
- Ubuntu 24.04: '6.8.0-45-generic'
- Debian 11: '5.10.0-18-amd64'

The original regex ^(\d+\.\d+\.\d+)\.(\d+) failed to match these formats, causing:
  AttributeError: 'NoneType' object has no attribute 'group'

This made kernelpkg.latest_available() completely unusable on:
- Debian 11 (Bullseye)
- Debian 12 (Bookworm)
- Ubuntu 22.04 (Jammy)
- Ubuntu 23.04 (Lunar)
- Ubuntu 24.04 (Noble)

## Root Cause
In salt/modules/kernelpkg_linux_apt.py line 86, the regex pattern was too restrictive:

## Solution
Updated the regex pattern to handle modern Debian/Ubuntu version formats:

### Key Improvements:
1. **Broader compatibility**: Handles both dash and dot separators
2. **Fallback mechanism**: Returns latest_installed() if regex fails completely
3. **Format detection**: Distinguishes between simple Debian and complex Ubuntu formats
4. **Graceful degradation**: Never crashes, always returns a usable result

## Testing
Added comprehensive test suite with 16 test cases covering:
- All problematic version formats from the issue
- Debian 11, 12 (Bookworm) formats
- Ubuntu 22.04, 23.04, 24.04 (Noble) formats
- Security updates, backports, complex formats
- Fallback behavior for malformed versions
- Regression prevention for edge cases

### Test Results:

## Impact
- ✅ **Fixes kernelpkg.latest_available() on all modern Debian/Ubuntu systems**
- ✅ **Maintains 100% backward compatibility**
- ✅ **No breaking changes** to existing functionality
- ✅ **Comprehensive test coverage** prevents future regressions
- ✅ **Graceful fallback** handling for unexpected version formats

## Version Compatibility Matrix
| Distribution | Version | Before Fix | After Fix |
|--------------|---------|------------|-----------|
| Debian 11 (Bullseye) | 5.10.0-18-amd64 | ❌ Crash | ✅ Works |
| Debian 12 (Bookworm) | 6.1.147-1 | ❌ Crash | ✅ Works |
| Ubuntu 22.04 (Jammy) | 5.15.0-91-generic | ❌ Crash | ✅ Works |
| Ubuntu 23.04 (Lunar) | 6.2.0-37-generic | ❌ Crash | ✅ Works |
| Ubuntu 24.04 (Noble) | 6.8.0-45-generic | ❌ Crash | ✅ Works |
| Security Updates | 6.1.147-1+deb12u1 | ❌ Crash | ✅ Works |
| Backports | 6.1.147-1~bpo11+1 | ❌ Crash | ✅ Works |

Fixes saltstack#68204
@aiodinlabs01 aiodinlabs01 force-pushed the fix-kernelpkg-regex-issue-68204 branch from 45051ed to 70c1e98 Compare August 29, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test:full Run the full test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] regex in kernelpkg latest_available() fails on Debian Bullseye / Ubuntu Noble
3 participants