nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: prometheus/snmp_exporter
Pull request #968 (2023-08-27 14:17:22)

Sanitize invalid UTF-8
Avoid sending raw invalid UTF-8 to metrics by replacing invalid chars with U+FFFD.

Fixes: https://github.com/prometheus/snmp_exporter/issues/279

SuperQ: :eyeglasses: @dswarbrick
SuperQ: Sigh:
```
ERROR: cannot verify file.wiener-d.com's certificate, issued by ‘CN=RapidSSL Global TLS RSA4096 SHA256 2022 CA1,O=DigiCert\\, Inc.,C=US’:
  Issued certificate has expired.
```

Patch:
diff --git a/collector/collector.go b/collector/collector.go
index 00616b2..d5b20af 100644
--- a/collector/collector.go
+++ b/collector/collector.go
@@ -817,7 +817,7 @@ func pduValueAsString(pdu *gosnmp.SnmpPDU, typ string, metrics internalMetrics)
 			return pdu.Value.(string)[1:]
 		}
 		// DisplayString.
-		return pdu.Value.(string)
+		return strings.ToValidUTF8(pdu.Value.(string), "�")
 	case []byte:
 		if typ == "" || typ == "Bits" {
 			typ = "OctetString"
@@ -832,7 +832,7 @@ func pduValueAsString(pdu *gosnmp.SnmpPDU, typ string, metrics internalMetrics)
 			parts = append([]int{len(pdu.Value.([]byte))}, parts...)
 		}
 		str, _, _ := indexOidsAsString(parts, typ, 0, false, nil)
-		return str
+		return strings.ToValidUTF8(str, "�")
 	case nil:
 		return ""
 	default:


Test patch:
diff --git a/collector/collector_test.go b/collector/collector_test.go
index 818a870..d1a7a80 100644
--- a/collector/collector_test.go
+++ b/collector/collector_test.go
@@ -718,6 +718,11 @@ func TestPduValueAsString(t *testing.T) {
 			pdu:    &gosnmp.SnmpPDU{Value: 10.1, Type: gosnmp.OpaqueDouble},
 			result: "10.1",
 		},
+		{
+			pdu:    &gosnmp.SnmpPDU{Value: []byte{115, 97, 110, 101, 253, 190, 214}},
+			typ:    "DisplayString",
+			result: "sane�",
+		},
 	}
 	for _, c := range cases {
 		got := pduValueAsString(c.pdu, c.typ, internalMetrics{})
Repository: Azure/WALinuxAgent
Pull request #814 (2017-07-25 23:20:25)

[#800] -- HostGAPlugin still use proxy while auto-updating
[#800] -- HostGAPlugin still use proxy while auto-updating
Signed-off-by: Brendan Dixon <brendandixon@me.com>


Patch:
diff --git a/azurelinuxagent/ga/update.py b/azurelinuxagent/ga/update.py
index d5b82879..c6e97cd8 100644
--- a/azurelinuxagent/ga/update.py
+++ b/azurelinuxagent/ga/update.py
@@ -800,7 +800,7 @@ class GuestAgent(object):
                     logger.verbose("Using host plugin as default channel")
 
                 uri, headers = self.host.get_artifact_request(uri.uri, self.host.manifest_uri)
-                if self._fetch(uri, headers=headers):
+                if self._fetch(uri, headers=headers, chk_proxy=False):
                     if not HostPluginProtocol.is_default_channel():
                         logger.verbose("Setting host plugin as default channel")
                         HostPluginProtocol.set_default_channel(True)
@@ -821,10 +821,10 @@ class GuestAgent(object):
             raise UpdateError(msg)
         return
 
-    def _fetch(self, uri, headers=None):
+    def _fetch(self, uri, headers=None, chk_proxy=True):
         package = None
         try:
-            resp = restutil.http_get(uri, chk_proxy=True, headers=headers)
+            resp = restutil.http_get(uri, chk_proxy=chk_proxy, headers=headers)
             if resp.status == restutil.httpclient.OK:
                 package = resp.read()
                 fileutil.write_file(self.get_agent_pkg_path(),


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 1b47983b..fb4b513d 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -683,8 +683,12 @@ class TestGuestAgent(UpdateTestCase):
                           return_value=True):
             self.assertRaises(UpdateError, agent._download)
             self.assertEqual(mock_http_get.call_count, 4)
+
             self.assertEqual(mock_http_get.call_args_list[2][0][0], ext_uri)
+
             self.assertEqual(mock_http_get.call_args_list[3][0][0], art_uri)
+            a, k = mock_http_get.call_args_list[3]
+            self.assertEqual(False, k['chk_proxy'])
 
             # ensure fallback works as expected
             with patch.object(HostPluginProtocol,
@@ -692,8 +696,16 @@ class TestGuestAgent(UpdateTestCase):
                               return_value=[art_uri, {}]):
                 self.assertRaises(UpdateError, agent._download)
                 self.assertEqual(mock_http_get.call_count, 6)
+
+                a, k = mock_http_get.call_args_list[3]
+                self.assertEqual(False, k['chk_proxy'])
+
                 self.assertEqual(mock_http_get.call_args_list[4][0][0], ext_uri)
+                a, k = mock_http_get.call_args_list[4]
+
                 self.assertEqual(mock_http_get.call_args_list[5][0][0], art_uri)
+                a, k = mock_http_get.call_args_list[5]
+                self.assertEqual(False, k['chk_proxy'])
 
     @patch("azurelinuxagent.ga.update.restutil.http_get")
     def test_ensure_downloaded(self, mock_http_get):
Repository: Azure/WALinuxAgent
Pull request #939 (2017-11-09 18:52:29)

v2.2.19
Signed-off-by: Brendan Dixon <brendandixon@me.com>


Patch:
diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py
index 3b817e20..f97e7f99 100644
--- a/azurelinuxagent/common/version.py
+++ b/azurelinuxagent/common/version.py
@@ -113,7 +113,7 @@ def get_distro():
 
 AGENT_NAME = "WALinuxAgent"
 AGENT_LONG_NAME = "Azure Linux Agent"
-AGENT_VERSION = '2.2.18.7'
+AGENT_VERSION = '2.2.19'
 AGENT_LONG_VERSION = "{0}-{1}".format(AGENT_NAME, AGENT_VERSION)
 AGENT_DESCRIPTION = """
 The Azure Linux Agent supports the provisioning and running of Linux


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index 0c24151d..88535f5b 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -1365,6 +1365,10 @@ class TestUpdate(UpdateTestCase):
         agent_versions = self.agent_versions()[:3]
         self.assertTrue(self._test_upgrade_available(versions=agent_versions))
         self.assertEqual(len(agent_versions), len(self.update_handler.agents))
+
+        # Purging always keeps the running agent
+        if CURRENT_VERSION not in agent_versions:
+            agent_versions.append(CURRENT_VERSION)
         self.assertEqual(agent_versions, self.agent_versions())
 
     def test_update_available_returns_true_if_current_gets_blacklisted(self):
Repository: Azure/WALinuxAgent
Pull request #1018 (2018-01-25 06:33:23)

ignore transient iptables error


Patch:
diff --git a/azurelinuxagent/common/osutil/default.py b/azurelinuxagent/common/osutil/default.py
index 2a8053a6..16b7444b 100644
--- a/azurelinuxagent/common/osutil/default.py
+++ b/azurelinuxagent/common/osutil/default.py
@@ -97,6 +97,11 @@ class DefaultOSUtil(object):
             wait = self.get_firewall_will_wait()
 
             rc, output = shellutil.run_get_output(FIREWALL_PACKETS.format(wait))
+            if rc == 3:
+                # Transient error  that we ignore.  This code fires every loop
+                # of the daemon (60m), so we will get the value eventually.
+                return 0
+
             if rc != 0:
                 return -1
 


Test patch:
diff --git a/tests/common/osutil/test_default.py b/tests/common/osutil/test_default.py
index 837d1f22..c9fa1dea 100644
--- a/tests/common/osutil/test_default.py
+++ b/tests/common/osutil/test_default.py
@@ -515,6 +515,16 @@ Match host 192.168.1.2\n\
             (1, Exception)]
         self.assertEqual(-1, util.get_firewall_dropped_packets("not used"))
 
+    @patch('azurelinuxagent.common.utils.shellutil.run_get_output')
+    def test_get_firewall_dropped_packets_transient_error_ignored(self, mock_output):
+        osutil._enable_firewall = True
+        util = osutil.DefaultOSUtil()
+
+        mock_output.side_effect = [
+            (0, "iptables v{0}".format(osutil.IPTABLES_LOCKING_VERSION)),
+            (3, "can't initialize iptables table `security': iptables who? (do you need to insmod?)")]
+        self.assertEqual(0, util.get_firewall_dropped_packets("not used"))
+
     @patch('azurelinuxagent.common.utils.shellutil.run_get_output')
     def test_get_firewall_dropped_packets(self, mock_output):
         osutil._enable_firewall = True
Repository: Azure/WALinuxAgent
Pull request #1024 (2018-01-26 21:42:53)

v2.2.21


Patch:
diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py
index 430fc0d0..f743f115 100644
--- a/azurelinuxagent/common/version.py
+++ b/azurelinuxagent/common/version.py
@@ -113,7 +113,7 @@ def get_distro():
 
 AGENT_NAME = "WALinuxAgent"
 AGENT_LONG_NAME = "Azure Linux Agent"
-AGENT_VERSION = '2.2.20'
+AGENT_VERSION = '2.2.21'
 AGENT_LONG_VERSION = "{0}-{1}".format(AGENT_NAME, AGENT_VERSION)
 AGENT_DESCRIPTION = """
 The Azure Linux Agent supports the provisioning and running of Linux


Test patch:
diff --git a/tests/ga/test_update.py b/tests/ga/test_update.py
index d9547446..21c81e98 100644
--- a/tests/ga/test_update.py
+++ b/tests/ga/test_update.py
@@ -1018,8 +1018,8 @@ class TestUpdate(UpdateTestCase):
         self.assertTrue(2 < len(self.update_handler.agents))
 
         # Purge every other agent
-        kept_agents = self.update_handler.agents[1::2]
-        purged_agents = self.update_handler.agents[::2]
+        purged_agents = self.update_handler.agents[1::2]
+        kept_agents = self.update_handler.agents[::2]
 
         # Reload and assert only the kept agents remain on disk
         self.update_handler.agents = kept_agents
Repository: Azure/WALinuxAgent
Pull request #1121 (2018-04-19 04:39:48)

compress works with strings
The compress method failed on Python 3 because it did not properly handle the difference between a string and byte array.  The compress method is expected to only be called for strings, so I made that clearer in the code, and added a unit test.


Patch:
diff --git a/azurelinuxagent/common/event.py b/azurelinuxagent/common/event.py
index 0a912396..e3352d60 100644
--- a/azurelinuxagent/common/event.py
+++ b/azurelinuxagent/common/event.py
@@ -16,14 +16,12 @@
 #
 
 import atexit
-import base64
 import datetime
 import json
 import os
 import sys
 import time
 import traceback
-import zlib
 
 from datetime import datetime
 
@@ -167,7 +165,7 @@ def _encode_message(op, message):
         return message
 
     try:
-        return textutil.b64encode(textutil.compress(message))
+        return textutil.compress(message)
     except Exception:
         # If the message could not be encoded a dummy message ('<>') is returned.
         # The original message was still sent via telemetry, so all is not lost.
diff --git a/azurelinuxagent/common/utils/textutil.py b/azurelinuxagent/common/utils/textutil.py
index dbab6877..16c6ed58 100644
--- a/azurelinuxagent/common/utils/textutil.py
+++ b/azurelinuxagent/common/utils/textutil.py
@@ -302,10 +302,18 @@ def get_bytes_from_pem(pem_str):
 
 
 def compress(s):
+    """
+    Compress a string, and return the base64 encoded result of the compression.
+
+    This method returns a string instead of a byte array.  It is expected
+    that this method is called to compress smallish strings, not to compress
+    the contents of a file. The output of this method is suitable for
+    embedding in log statements.
+    """
     from azurelinuxagent.common.version import PY_VERSION_MAJOR
     if PY_VERSION_MAJOR > 2:
-        return zlib.compress(bytes(s, 'utf-8'))
-    return zlib.compress(s)
+        return base64.b64encode(zlib.compress(bytes(s, 'utf-8'))).decode('utf-8')
+    return base64.b64encode(zlib.compress(s))
 
 
 def b64encode(s):


Test patch:
diff --git a/tests/utils/test_text_util.py b/tests/utils/test_text_util.py
index 1f9d889c..719210ac 100644
--- a/tests/utils/test_text_util.py
+++ b/tests/utils/test_text_util.py
@@ -137,6 +137,11 @@ class TestTextUtil(AgentTestCase):
 
         for t in data:
             self.assertEqual(t[2], textutil.swap_hexstring(t[0], width=t[1]))
-        
+
+    def test_compress(self):
+        result = textutil.compress('[stdout]\nHello World\n\n[stderr]\n\n')
+        self.assertEqual('eJyLLi5JyS8tieXySM3JyVcIzy/KSeHiigaKphYVxXJxAQDAYQr2', result)
+
+
 if __name__ == '__main__':
     unittest.main()