diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index e85365548ecee0235c11e6b7501dcea90a5797fe..830a0aef5d96be1196e592fe08b611e7150fd11b 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -45,6 +45,8 @@ Drupal 7.50, xxxx-xx-xx (development version)
   User module (minor data structure change). Previously this automatically
   inherited the page callback from the parent "admin/people" menu item, which
   broke contributed modules that override the "admin/people" page.
+- Fixed a bug which caused ip_address() to return nothing when the client IP
+  address and proxy IP address are the same.
 
 Drupal 7.44, 2016-06-15
 -----------------------
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 9775ff675b326f1f3ebc920eb46dd12958b34388..b66ae17789caec86647e55812668450823c72e52 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -2963,8 +2963,15 @@ function ip_address() {
         // Eliminate all trusted IPs.
         $untrusted = array_diff($forwarded, $reverse_proxy_addresses);
 
-        // The right-most IP is the most specific we can trust.
-        $ip_address = array_pop($untrusted);
+        if (!empty($untrusted)) {
+          // The right-most IP is the most specific we can trust.
+          $ip_address = array_pop($untrusted);
+        }
+        else {
+          // All IP addresses in the forwarded array are configured proxy IPs
+          // (and thus trusted). We take the leftmost IP.
+          $ip_address = array_shift($forwarded);
+        }
       }
     }
   }
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
index 427bd8461e309522f22458b5464c9fe81f4ac0e6..3fbec37e58752d714f2098ba26c6fa51a2fcf7f0 100644
--- a/modules/simpletest/tests/bootstrap.test
+++ b/modules/simpletest/tests/bootstrap.test
@@ -70,6 +70,15 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
       'Proxy forwarding with trusted proxy got forwarded IP address.'
     );
 
+    // Proxy forwarding on and proxy address trusted and visiting from proxy.
+    $_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
+    $_SERVER['HTTP_X_FORWARDED_FOR'] = $this->proxy_ip;
+    drupal_static_reset('ip_address');
+    $this->assertTrue(
+      ip_address() == $this->proxy_ip,
+      'Visiting from trusted proxy got proxy IP address.'
+    );
+
     // Multi-tier architecture with comma separated values in header.
     $_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
     $_SERVER['HTTP_X_FORWARDED_FOR'] = implode(', ', array($this->untrusted_ip, $this->forwarded_ip, $this->proxy2_ip));