Skip to content

Commit

Permalink
Merge branch 'SLE-15-SP4' into merge_SLE-15-SP4
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Dec 30, 2022
2 parents 1c37acd + f58e151 commit 2281370
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package/yast2-network.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Dec 29 06:44:50 UTC 2022 - Knut Anderssen <kanderssen@suse.com>

- Do not crash when the NETMASK or PREFIXLEN are invalid
(bsc#1206551).
- 4.5.11

-------------------------------------------------------------------
Tue Nov 22 14:53:13 UTC 2022 - Martin Vidner <mvidner@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-network.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-network
Version: 4.5.10
Version: 4.5.11
Release: 0
Summary: YaST2 - Network Configuration
License: GPL-2.0-only
Expand Down
51 changes: 45 additions & 6 deletions src/lib/y2network/wicked/connection_config_readers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def all_ips
@all_ips ||= file.ipaddrs.each_with_object([]) do |(id, ip), all|
next unless ip.is_a?(Y2Network::IPAddress)

ip_address = build_ip(ip, file.prefixlens[id], file.netmasks[id])
ip_address = build_ip(ip, id)

all << Y2Network::ConnectionConfig::IPConfig.new(
ip_address,
id: id,
Expand All @@ -158,17 +159,55 @@ def all_ips
# It takes an IP address and, optionally, a prefix or a netmask.
#
# @param ip [Y2Network::IPAddress] IP address
# @param prefix [Integer,nil] Address prefix
# @param netmask [String,nil] Netmask
def build_ip(ip, prefix, netmask)
# @param id [String] Hash key for the IP Address
def build_ip(ip, id)
ipaddr = ip.clone
return ipaddr if ip.prefix?

ipaddr.netmask = netmask if netmask
ipaddr.prefix = prefix if prefix
assign_ip_netmask(ipaddr, id)
assign_ip_prefix(ipaddr, id)

ipaddr
end

# @param ip [Y2Network::IPAddress] IP address
# @param id [String] Hash key for the IP Address
def assign_ip_netmask(ip, id)
netmask = file.netmasks[id]
return ip unless netmask

begin
ip.netmask = netmask
rescue StandardError
issue_location = "file:#{file.path}:NETMASK#{id}"
issue = Y2Issues::InvalidValue.new(
netmask, fallback: nil, location: issue_location
)
issues_list << issue
end
end

# @param ip [Y2Network::IPAddress] IP address
# @param id [String] Hash key for the IP Address
def assign_ip_prefix(ip, id)
prefix = file.prefixlens[id]
return ip unless prefix

address = ip.address.clone
begin
# Take advantage of the IPAddress address validations when the prefix is assigned not
# allowing an invalid one (bsc#1206551)
address.prefix = prefix
ip.prefix = prefix
rescue StandardError
issue_location = "file:#{file.path}:PREFIXLEN#{id}"
issue = Y2Issues::InvalidValue.new(
prefix, fallback: nil, location: issue_location
)
issues_list << issue
end
end

# Returns the hostnames for the given connection
#
# @return [Array<String>]
Expand Down
2 changes: 1 addition & 1 deletion test/data/scr_read/etc/sysconfig/network/ifcfg-eth0
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BOOTPROTO='static'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR='192.168.123.1/24'
IPADDR='192.168.123.1/24'
MTU='1500'
NAME='Ethernet Card 0'
NETWORK=''
Expand Down
35 changes: 35 additions & 0 deletions test/y2network/wicked/connection_config_readers/ethernet_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,40 @@
expect(issue.message).to include("Invalid value 'automatic'")
end
end

context "when the NETMASK is not valid" do
let(:interface_name) { "eth1" }

before do
allow(file).to receive(:netmasks).and_return("_1" => "255.255.252.298")
end

it "registers an issue" do
handler.connection_config
issue = issues_list.first
expect(issue.location.to_s).to eq(
"file:/etc/sysconfig/network/ifcfg-eth1:NETMASK_1"
)
expect(issue.message).to include("Invalid value '255.255.252.298'")
end
end

context "when the PREFIXLEN is not valid" do
let(:interface_name) { "eth2" }

before do
allow(file).to receive(:prefixlens).and_return("" => 244)
end

it "registers an issue" do
handler.connection_config
issue = issues_list.first
expect(issue.location.to_s).to eq(
"file:/etc/sysconfig/network/ifcfg-eth2:PREFIXLEN"
)
expect(issue.message).to include("Invalid value '244'")
end
end

end
end

0 comments on commit 2281370

Please sign in to comment.