Skip to content

Commit

Permalink
security:choose_mech fix DEAD CODE warning
Browse files Browse the repository at this point in the history
... by removing the "do {} while (0)" block.

Coverity CID 1306669
  • Loading branch information
bagder committed Jun 15, 2015
1 parent 45bad4a commit 99eafc4
Showing 1 changed file with 43 additions and 46 deletions.
89 changes: 43 additions & 46 deletions lib/security.c
Expand Up @@ -480,56 +480,54 @@ static CURLcode choose_mech(struct connectdata *conn)
void *tmp_allocation;
const struct Curl_sec_client_mech *mech = &Curl_krb5_client_mech;

do {
tmp_allocation = realloc(conn->app_data, mech->size);
if(tmp_allocation == NULL) {
failf(data, "Failed realloc of size %u", mech->size);
mech = NULL;
return CURLE_OUT_OF_MEMORY;
}
conn->app_data = tmp_allocation;

if(mech->init) {
ret = mech->init(conn->app_data);
if(ret) {
infof(data, "Failed initialization for %s. Skipping it.\n",
mech->name);
continue;
}
tmp_allocation = realloc(conn->app_data, mech->size);
if(tmp_allocation == NULL) {
failf(data, "Failed realloc of size %u", mech->size);
mech = NULL;
return CURLE_OUT_OF_MEMORY;
}
conn->app_data = tmp_allocation;

if(mech->init) {
ret = mech->init(conn->app_data);
if(ret) {
infof(data, "Failed initialization for %s. Skipping it.\n",
mech->name);
return CURLE_FAILED_INIT;
}
}

infof(data, "Trying mechanism %s...\n", mech->name);
ret = ftp_send_command(conn, "AUTH %s", mech->name);
if(ret < 0)
/* FIXME: This error is too generic but it is OK for now. */
return CURLE_COULDNT_CONNECT;

if(ret/100 != 3) {
switch(ret) {
case 504:
infof(data, "Mechanism %s is not supported by the server (server "
"returned ftp code: 504).\n", mech->name);
break;
case 534:
infof(data, "Mechanism %s was rejected by the server (server returned "
"ftp code: 534).\n", mech->name);
break;
default:
if(ret/100 == 5) {
infof(data, "server does not support the security extensions\n");
return CURLE_USE_SSL_FAILED;
}
break;
infof(data, "Trying mechanism %s...\n", mech->name);
ret = ftp_send_command(conn, "AUTH %s", mech->name);
if(ret < 0)
/* FIXME: This error is too generic but it is OK for now. */
return CURLE_COULDNT_CONNECT;

if(ret/100 != 3) {
switch(ret) {
case 504:
infof(data, "Mechanism %s is not supported by the server (server "
"returned ftp code: 504).\n", mech->name);
break;
case 534:
infof(data, "Mechanism %s was rejected by the server (server returned "
"ftp code: 534).\n", mech->name);
break;
default:
if(ret/100 == 5) {
infof(data, "server does not support the security extensions\n");
return CURLE_USE_SSL_FAILED;
}
continue;
break;
}
return CURLE_LOGIN_DENIED;
}

/* Authenticate */
ret = mech->auth(conn->app_data, conn);
/* Authenticate */
ret = mech->auth(conn->app_data, conn);

if(ret == AUTH_CONTINUE)
continue;
else if(ret != AUTH_OK) {
if(ret != AUTH_CONTINUE) {
if(ret != AUTH_OK) {
/* Mechanism has dumped the error to stderr, don't error here. */
return -1;
}
Expand All @@ -545,8 +543,7 @@ static CURLcode choose_mech(struct connectdata *conn)
/* Set the requested protection level */
/* BLOCKING */
(void)sec_set_protection_level(conn);

} WHILE_FALSE;
}

return CURLE_OK;
}
Expand Down

0 comments on commit 99eafc4

Please sign in to comment.