Text  |   XML   |   Visible Warnings:

Irssi : Irssi analysis 1 : Unreachable Computation  at network-openssl.c:264

Categories: LANG.STRUCT.UC CWE:561
Warning ID: 2132.2134
Similar Warnings: 2132.2133
Procedure: irssi_ssl_get_iochannel
Trace: View
Modified: Wed Sep 2 11:51:26 2009   show details
 
Priority: None
State: None
Finding: None
Owner: None
  edit properties

Legend [ X ]
Warning Location
Contributes
Parse Error
Other Warning
Two or More Loop Iterations
On Execution Path
Comment
Macro
Preprocessor
Include
Keyword
Preprocessed Away

Source  |  Language: C Hide Legend     
LineSource
  /u1/paul/SATE/2010/c/irssi/irssi-0.8.14/src/core/network-openssl.c
  Enter irssi_ssl_get_iochannel
244 static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, const char *mycert, const char *mypkey, const char *cafile, const char *capath, gboolean verify) 
245 {
246         GIOSSLChannel *chan;
247         GIOChannel *gchan;
248         int fd;
249         SSL *ssl;
250         SSL_CTX *ctx = NULL;
251  
252         g_return_val_if_fail(handle != NULL, NULL);
253  
254         if(!ssl_ctx && !irssi_ssl_init())   /* Redundant Condition (ID: 2131.2132) */
255                 return NULL;   /* Unreachable Computation (ID: 2132.2133) */
256  
257         if(!(fd = g_io_channel_unix_get_fd(handle)))
258                 return NULL;
259  
260         if (mycert && *mycert) {
261                 char *scert = NULL, *spkey = NULL;
262                 if ((ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
263                         g_error("Could not allocate memory for SSL context");
264                         return NULL;     /* Unreachable Computation */
265                 }
266                 scert = convert_home(mycert);
267                 if (mypkey && *mypkey)
268                         spkey = convert_home(mypkey);
269                 if (! SSL_CTX_use_certificate_file(ctx, scert, SSL_FILETYPE_PEM))
270                         g_warning("Loading of client certificate '%s' failed", mycert);
271                 else if (! SSL_CTX_use_PrivateKey_file(ctx, spkey ? spkey : scert, SSL_FILETYPE_PEM))
272                         g_warning("Loading of private key '%s' failed", mypkey ? mypkey : mycert);   /* Null Test After Dereference (ID: 2130.2131) */
273                 else if (! SSL_CTX_check_private_key(ctx))
274                         g_warning("Private key does not match the certificate");
275                 g_free(scert);
276                 g_free(spkey);
277         }
278  
279         if ((cafile && *cafile) || (capath && *capath)) {
280                 char *scafile = NULL;
281                 char *scapath = NULL;
282                 if (! ctx && (ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
283                         g_error("Could not allocate memory for SSL context");
284                         return NULL;
285                 }
286                 if (cafile && *cafile)
287                         scafile = convert_home(cafile);
288                 if (capath && *capath)
289                         scapath = convert_home(capath);
290                 if (! SSL_CTX_load_verify_locations(ctx, scafile, scapath)) {
291                         g_warning("Could not load CA list for verifying SSL server certificate");
292                         g_free(scafile);
293                         g_free(scapath);
294                         SSL_CTX_free(ctx);
295                         return NULL;
296                 }
297                 g_free(scafile);
298                 g_free(scapath);
299                 verify = TRUE;
300         }
301  
302         if (ctx == NULL)
303                 ctx = ssl_ctx;
304  
305         if(!(ssl = SSL_new(ctx)))
306         {
307                 g_warning("Failed to allocate SSL structure");
308                 return NULL;
309         }
310  
311         if(!SSL_set_fd(ssl, fd))
312         {
313                 g_warning("Failed to associate socket to SSL stream");
314                 SSL_free(ssl);
315                 if (ctx != ssl_ctx)
316                         SSL_CTX_free(ctx);
317                 return NULL;
318         }
319  
320         chan = g_new0(GIOSSLChannel, 1);
321         chan->fd = fd;
322         chan->giochan = handle;
323         chan->ssl = ssl;
324         chan->ctx = ctx;
325         chan->verify = verify;
326  
327         gchan = (GIOChannel *)chan;
328         gchan->funcs = &irssi_ssl_channel_funcs;
329         g_io_channel_init(gchan);
330         gchan->is_readable = gchan->is_writeable = TRUE;
331         gchan->use_buffer = FALSE;
332  
333         return gchan;
334 




Change Warning 2132.2134 : Unreachable Computation

Because they are very similar, this warning shares annotations with warning 2132.2133.
CodeSonar has selected warning 2132.2133 to represent this group of similar warnings. In order to edit this group, you must edit warning 2132.2133.