IceDisposeCompleteMessage (_iceConn, _pStart);\
return (0);\
}
+
+#ifndef HAVE_ASPRINTF
+# include <stdarg.h>
+
+/* sprintf variant found in newer libc's which allocates string to print to */
+static int _X_ATTRIBUTE_PRINTF(2,3)
+asprintf(char ** ret, const char *format, ...)
+{
+ char buf[256];
+ int len;
+ va_list ap;
+
+ va_start(ap, format);
+ len = vsnprintf(buf, sizeof(buf), format, ap);
+ va_end(ap);
+
+ if (len < 0)
+ return -1;
+
+ if (len < sizeof(buf))
+ {
+ *ret = strdup(buf);
+ }
+ else
+ {
+ *ret = malloc(len + 1); /* snprintf doesn't count trailing '\0' */
+ if (*ret != NULL)
+ {
+ va_start(ap, format);
+ len = vsnprintf(*ret, len + 1, format, ap);
+ va_end(ap);
+ if (len < 0) {
+ free(*ret);
+ *ret = NULL;
+ }
+ }
+ }
+
+ if (*ret == NULL)
+ return -1;
+
+ return len;
+}
+#endif
+
\f
/*
* IceProcessMessages:
* to use message replies unless we translate opcodes before
* comparing them.
*/
-
+
{
int op;
_IceConnectionError *errorReply =
&(((_IceReply *) (replyWait->reply))->connection_error);
char *errorStr = NULL;
- const char *tempstr;
- char *prefix, *temp;
+ const char *tempstr, *prefix;
+ char *temp;
invokeHandler = 0;
errorReturned = True;
prefix = "Connection Setup Failed, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
prefix = "Authentication Rejected, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
prefix = "Authentication Failed, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
_IceProtocolError *errorReply =
&(((_IceReply *) (replyWait->reply))->protocol_error);
char *errorStr = "";
- char *prefix, *temp;
+ const char *prefix;
+ char *temp;
invokeHandler = 0;
errorReturned = True;
{
case IceNoVersion:
- temp =
- "None of the protocol versions specified are supported";
- errorStr = strdup(temp);
+ errorStr = strdup(
+ "None of the protocol versions specified are supported");
break;
case IceNoAuth:
- temp =
- "None of the authentication protocols specified are supported";
- errorStr = strdup(temp);
+ errorStr = strdup(
+ "None of the authentication protocols specified are supported");
+
break;
case IceSetupFailed:
prefix = "Protocol Setup Failed, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
prefix = "Authentication Rejected, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
prefix = "Authentication Failed, reason : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
prefix = "Protocol was already registered : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
case IceMajorOpcodeDuplicate:
prefix = "The major opcode was already used : ";
- errorStr = (char *) malloc (strlen (prefix) + 2);
- sprintf (errorStr, "%s%d", prefix, (int) *pData);
+ if (asprintf (&errorStr, "%s%d", prefix, (int) *pData) == -1)
+ errorStr = NULL;
break;
case IceUnknownProtocol:
prefix = "Unknown Protocol : ";
EXTRACT_STRING (pData, swap, temp);
- errorStr = (char *) malloc (
- strlen (prefix) + strlen (temp) + 1);
- sprintf (errorStr, "%s%s", prefix, temp);
+ if (asprintf (&errorStr, "%s%s", prefix, temp) == -1)
+ errorStr = NULL;
free (temp);
break;
int hisMajorVersion, hisMinorVersion;
int myAuthCount, hisAuthCount;
int found, i, j;
- char *myAuthName, **hisAuthNames = NULL;
+ char **hisAuthNames = NULL;
char *pData, *pStart, *pEnd;
char *vendor = NULL;
char *release = NULL;
pData = pStart;
pEnd = pStart + (length << 3);
-
- SKIP_STRING (pData, swap, pEnd,
+
+ SKIP_STRING (pData, swap, pEnd,
BAIL_STRING(iceConn, ICE_ConnectionSetup,
pStart)); /* vendor */
- SKIP_STRING (pData, swap, pEnd,
+ SKIP_STRING (pData, swap, pEnd,
BAIL_STRING(iceConn, ICE_ConnectionSetup,
pStart)); /* release */
- SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd,
+ SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd,
BAIL_STRING(iceConn, ICE_ConnectionSetup,
pStart)); /* auth names */
-
+
pData += (message->versionCount * 4); /* versions */
CHECK_COMPLETE_SIZE (iceConn, ICE_ConnectionSetup,
{
for (i = 0; i < hisAuthCount; i++)
free (hisAuthNames[i]);
-
+
free ((char *) hisAuthNames);
}
{
if (authUsableFlags[i])
{
- myAuthName = _IceAuthNames[i];
+ const char *myAuthName = _IceAuthNames[i];
for (j = 0; j < hisAuthCount && !found; j++)
if (strcmp (myAuthName, hisAuthNames[j]) == 0)
{
accept_setup_now = 1;
}
- else
+ else
{
_IceErrorAuthenticationRejected (iceConn,
ICE_ConnectionSetup, "None of the authentication protocols specified are supported and host-based authentication failed");
{
accept_setup_now = 1;
}
+ else
+ {
+ free (vendor);
+ free (release);
+ }
if (authData && authDataLen > 0)
free ((char *) authData);
if (errorString)
free (errorString);
}
-
+
if (accept_setup_now)
{
AcceptConnection (iceConn, hisVersionIndex);
{
for (i = 0; i < hisAuthCount; i++)
free (hisAuthNames[i]);
-
+
free ((char *) hisAuthNames);
}
}
else if (status == IcePoAuthRejected || status == IcePoAuthFailed)
{
- char *prefix, *returnErrorString;
+ const char *prefix;
+ char *returnErrorString;
if (status == IcePoAuthRejected)
{
prefix = "Authentication Failed, reason : ";
}
- returnErrorString = (char *) malloc (strlen (prefix) +
- strlen (errorString) + 1);
- sprintf (returnErrorString, "%s%s", prefix, errorString);
+ if (asprintf (&returnErrorString, "%s%s", prefix, errorString) == -1)
+ returnErrorString = NULL;
free (errorString);
-
+
if (iceConn->connect_to_you)
{
_IceConnectionError *errorReply =
}
else if (status == IcePoAuthRejected || status == IcePoAuthFailed)
{
- char *prefix = NULL, *returnErrorString;
+ const char *prefix = NULL;
+ char *returnErrorString;
if (status == IcePoAuthRejected)
{
prefix = "Authentication Failed, reason : ";
}
- returnErrorString = (char *) malloc (strlen (prefix) +
- strlen (errorString) + 1);
- sprintf (returnErrorString, "%s%s", prefix, errorString);
+ if (asprintf (&returnErrorString, "%s%s", prefix, errorString) == -1)
+ returnErrorString = NULL;
free (errorString);
if (iceConn->connect_to_you)
_IceErrorBadValue (iceConn, 0,
ICE_ConnectionReply, 2, 1, &errIndex);
-
+
errorReply->type = ICE_CONNECTION_ERROR;
errorReply->error_message =
"Received bad version index in Connection Reply";
int myAuthCount, hisAuthCount;
int myOpcode, hisOpcode;
int found, i, j;
- char *myAuthName, **hisAuthNames = NULL;
+ char **hisAuthNames = NULL;
char *protocolName;
char *pData, *pStart, *pEnd;
char *vendor = NULL;
pEnd = pStart + (length << 3);
SKIP_STRING (pData, swap, pEnd,
- BAIL_STRING(iceConn, ICE_ProtocolSetup,
+ BAIL_STRING(iceConn, ICE_ProtocolSetup,
pStart)); /* proto name */
SKIP_STRING (pData, swap, pEnd,
- BAIL_STRING(iceConn, ICE_ProtocolSetup,
+ BAIL_STRING(iceConn, ICE_ProtocolSetup,
pStart)); /* vendor */
SKIP_STRING (pData, swap, pEnd,
- BAIL_STRING(iceConn, ICE_ProtocolSetup,
+ BAIL_STRING(iceConn, ICE_ProtocolSetup,
pStart)); /* release */
SKIP_LISTOF_STRING (pData, swap, (int) message->authCount, pEnd,
- BAIL_STRING(iceConn, ICE_ProtocolSetup,
+ BAIL_STRING(iceConn, ICE_ProtocolSetup,
pStart)); /* auth names */
pData += (message->versionCount * 4); /* versions */
{
for (i = 0; i < hisAuthCount; i++)
free (hisAuthNames[i]);
-
+
free ((char *) hisAuthNames);
}
_IceGetPaValidAuthIndices (
_IceProtocols[myOpcode - 1].protocol_name,
- iceConn->connection_string, myAuthCount, myProtocol->auth_names,
+ iceConn->connection_string, myAuthCount,
+ (const char **) myProtocol->auth_names,
&authUsableCount, authIndices);
for (i = 0; i < myAuthCount; i++)
{
if (authUsableFlags[i])
{
- myAuthName = myProtocol->auth_names[i];
+ const char *myAuthName = myProtocol->auth_names[i];
for (j = 0; j < hisAuthCount && !found; j++)
if (strcmp (myAuthName, hisAuthNames[j]) == 0)
{
accept_setup_now = 1;
}
- else
+ else
{
_IceErrorAuthenticationRejected (iceConn,
ICE_ProtocolSetup, "None of the authentication protocols specified are supported and host-based authentication failed");
_IceProtoSetupToMeInfo *setupInfo;
AuthRequired (iceConn, hisAuthIndex, authDataLen, authData);
-
+
iceConn->protosetup_to_me = setupInfo =
(_IceProtoSetupToMeInfo *) malloc (
sizeof (_IceProtoSetupToMeInfo));
IcePoAuthProc authProc = myProtocol->auth_procs[(int)
(iceConn->protosetup_to_you->my_auth_index)];
-#ifdef SVR4
-
-/*
- * authProc is never NULL, but the cc compiler on UNIX System V/386
- * Release 4.2 Version 1 screws up an optimization. Unless there is
- * some sort of reference to authProc before the function call, the
- * function call will seg fault.
- */
- if (authProc)
-#endif
- (*authProc) (iceConn,
+ (*authProc) (iceConn,
&iceConn->protosetup_to_you->my_auth_state,
True /* clean up */, False /* swap */,
0, NULL, NULL, NULL, NULL);
_IceErrorBadValue (iceConn, 0,
ICE_ProtocolReply, 2, 1, &errIndex);
-
+
errorReply->type = ICE_PROTOCOL_ERROR;
errorReply->error_message =
"Received bad version index in Protocol Reply";
}
else
{
- _IceProtocolReply *reply =
+ _IceProtocolReply *reply =
&(((_IceReply *) (replyWait->reply))->protocol_reply);
reply->type = ICE_PROTOCOL_REPLY;
if (iceConn->ping_waits)
{
_IcePingWait *next = iceConn->ping_waits->next;
-
+
(*iceConn->ping_waits->ping_reply_proc) (iceConn,
iceConn->ping_waits->client_data);