[PATCH libSM] Avoid infinite loop when SM rejects RegisterClient

Daniel Drake dsd at laptop.org
Mon Nov 12 12:06:38 PST 2012


We have a couple of cases where libSM enters a seemingly infinite loop
when trying to send a RegisterClient message to the SM.
 - http://bugs.sugarlabs.org/ticket/1624
 - http://dev.laptop.org/ticket/12210

In these cases, the SM rejects registration requests because the session is
shutting down.

However, libSM currently has logic to retry with a NULL previous ID if
the SM rejects a registration - and this behaviour will loop. Avoid this
infinite loop by only retrying with a NULL previous ID when the previous
attempt used a non-NULL ID.

Signed-off-by: Daniel Drake <dsd at laptop.org>
---
 src/sm_client.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/sm_client.c b/src/sm_client.c
index 23d8e32..6908008 100644
--- a/src/sm_client.c
+++ b/src/sm_client.c
@@ -255,8 +255,23 @@ SmcOpenConnection(char *networkIdsList, SmPointer context,
 	    {
 		/*
 		 * Could not register the client because the previous ID
-		 * was bad.  So now we register the client with the
-		 * previous ID set to NULL.
+		 * was bad. If we were trying NULL, return failure.
+		 */
+		if (strlen (previousId) == 0) {
+		    if (errorStringRet && errorLength > 0) {
+			strncpy (errorStringRet, "SM rejected new registration",
+				 errorLength);
+			errorStringRet[errorLength - 1] = '\0';
+		    }
+
+		    free (smcConn->vendor);
+		    free (smcConn->release);
+		    free (smcConn);
+		    return NULL;
+		}
+
+		/*
+		 * Now we register the client with the previous ID set to NULL.
 		 */
 
 		extra = ARRAY8_BYTES (0);
@@ -265,7 +280,8 @@ SmcOpenConnection(char *networkIdsList, SmPointer context,
 		    SIZEOF (smRegisterClientMsg), WORD64COUNT (extra),
 		    smRegisterClientMsg, pMsg, pData);
 
-		STORE_ARRAY8 (pData, 0, "");
+		previousId = "";
+		STORE_ARRAY8 (pData, 0, previousId);
 
 		IceFlush (iceConn);
 
-- 
1.7.11.7



More information about the xorg-devel mailing list