idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
5,700
|
tt_face_get_location( TT_Face face,
FT_UInt gindex,
FT_UInt *asize )
{
FT_ULong pos1, pos2;
FT_Byte* p;
FT_Byte* p_limit;
pos1 = pos2 = 0;
if ( gindex < face->num_locations )
{
if ( face->header.Index_To_Loc_Format != 0 )
{
p = face->glyph_locations + gindex * 4;
p_limit = face->glyph_locations + face->num_locations * 4;
pos1 = FT_NEXT_ULONG( p );
pos2 = pos1;
if ( p + 4 <= p_limit )
pos2 = FT_NEXT_ULONG( p );
}
else
{
p = face->glyph_locations + gindex * 2;
p_limit = face->glyph_locations + face->num_locations * 2;
pos1 = FT_NEXT_USHORT( p );
pos2 = pos1;
if ( p + 2 <= p_limit )
pos2 = FT_NEXT_USHORT( p );
pos1 <<= 1;
pos2 <<= 1;
}
}
/* Check broken location data */
if ( pos1 > face->glyf_len )
{
FT_TRACE1(( "tt_face_get_location:"
" too large offset=0x%08lx found for gid=0x%04lx,"
" exceeding the end of glyf table (0x%08lx)\n",
pos1, gindex, face->glyf_len ));
*asize = 0;
return 0;
}
if ( pos2 > face->glyf_len )
{
FT_TRACE1(( "tt_face_get_location:"
" too large offset=0x%08lx found for gid=0x%04lx,"
" truncate at the end of glyf table (0x%08lx)\n",
pos2, gindex + 1, face->glyf_len ));
pos2 = face->glyf_len;
}
/* The `loca' table must be ordered; it refers to the length of */
/* an entry as the difference between the current and the next */
/* position. However, there do exist (malformed) fonts which */
/* don't obey this rule, so we are only able to provide an */
/* upper bound for the size. */
/* */
/* We get (intentionally) a wrong, non-zero result in case the */
/* `glyf' table is missing. */
if ( pos2 >= pos1 )
*asize = (FT_UInt)( pos2 - pos1 );
else
*asize = (FT_UInt)( face->glyf_len - pos1 );
return pos1;
}
|
DoS
| 0
|
tt_face_get_location( TT_Face face,
FT_UInt gindex,
FT_UInt *asize )
{
FT_ULong pos1, pos2;
FT_Byte* p;
FT_Byte* p_limit;
pos1 = pos2 = 0;
if ( gindex < face->num_locations )
{
if ( face->header.Index_To_Loc_Format != 0 )
{
p = face->glyph_locations + gindex * 4;
p_limit = face->glyph_locations + face->num_locations * 4;
pos1 = FT_NEXT_ULONG( p );
pos2 = pos1;
if ( p + 4 <= p_limit )
pos2 = FT_NEXT_ULONG( p );
}
else
{
p = face->glyph_locations + gindex * 2;
p_limit = face->glyph_locations + face->num_locations * 2;
pos1 = FT_NEXT_USHORT( p );
pos2 = pos1;
if ( p + 2 <= p_limit )
pos2 = FT_NEXT_USHORT( p );
pos1 <<= 1;
pos2 <<= 1;
}
}
/* Check broken location data */
if ( pos1 > face->glyf_len )
{
FT_TRACE1(( "tt_face_get_location:"
" too large offset=0x%08lx found for gid=0x%04lx,"
" exceeding the end of glyf table (0x%08lx)\n",
pos1, gindex, face->glyf_len ));
*asize = 0;
return 0;
}
if ( pos2 > face->glyf_len )
{
FT_TRACE1(( "tt_face_get_location:"
" too large offset=0x%08lx found for gid=0x%04lx,"
" truncate at the end of glyf table (0x%08lx)\n",
pos2, gindex + 1, face->glyf_len ));
pos2 = face->glyf_len;
}
/* The `loca' table must be ordered; it refers to the length of */
/* an entry as the difference between the current and the next */
/* position. However, there do exist (malformed) fonts which */
/* don't obey this rule, so we are only able to provide an */
/* upper bound for the size. */
/* */
/* We get (intentionally) a wrong, non-zero result in case the */
/* `glyf' table is missing. */
if ( pos2 >= pos1 )
*asize = (FT_UInt)( pos2 - pos1 );
else
*asize = (FT_UInt)( face->glyf_len - pos1 );
return pos1;
}
|
@@ -508,9 +508,9 @@
record_size = FT_NEXT_ULONG( p );
/* The maximum number of bytes in an hdmx device record is the */
- /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */
- /* the reason why `record_size' is a long (which we read as */
- /* unsigned long for convenience). In practice, two bytes */
+ /* maximum number of glyphs + 2; this is 0xFFFF + 2, thus */
+ /* explaining why `record_size' is a long (which we read as */
+ /* unsigned long for convenience). In practice, two bytes are */
/* sufficient to hold the size value. */
/* */
/* There are at least two fonts, HANNOM-A and HANNOM-B version */
@@ -522,8 +522,10 @@
record_size &= 0xFFFFU;
/* The limit for `num_records' is a heuristic value. */
-
- if ( version != 0 || num_records > 255 || record_size > 0x10001L )
+ if ( version != 0 ||
+ num_records > 255 ||
+ record_size > 0x10001L ||
+ record_size < 4 )
{
error = FT_THROW( Invalid_File_Format );
goto Fail;
|
CWE-125
| null | null |
5,701
|
tt_face_load_cvt( TT_Face face,
FT_Stream stream )
{
#ifdef TT_USE_BYTECODE_INTERPRETER
FT_Error error;
FT_Memory memory = stream->memory;
FT_ULong table_len;
FT_TRACE2(( "CVT " ));
error = face->goto_table( face, TTAG_cvt, stream, &table_len );
if ( error )
{
FT_TRACE2(( "is missing\n" ));
face->cvt_size = 0;
face->cvt = NULL;
error = FT_Err_Ok;
goto Exit;
}
face->cvt_size = table_len / 2;
if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) )
goto Exit;
if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
goto Exit;
{
FT_Short* cur = face->cvt;
FT_Short* limit = cur + face->cvt_size;
for ( ; cur < limit; cur++ )
*cur = FT_GET_SHORT();
}
FT_FRAME_EXIT();
FT_TRACE2(( "loaded\n" ));
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
if ( face->doblend )
error = tt_face_vary_cvt( face, stream );
#endif
Exit:
return error;
#else /* !TT_USE_BYTECODE_INTERPRETER */
FT_UNUSED( face );
FT_UNUSED( stream );
return FT_Err_Ok;
#endif
}
|
DoS
| 0
|
tt_face_load_cvt( TT_Face face,
FT_Stream stream )
{
#ifdef TT_USE_BYTECODE_INTERPRETER
FT_Error error;
FT_Memory memory = stream->memory;
FT_ULong table_len;
FT_TRACE2(( "CVT " ));
error = face->goto_table( face, TTAG_cvt, stream, &table_len );
if ( error )
{
FT_TRACE2(( "is missing\n" ));
face->cvt_size = 0;
face->cvt = NULL;
error = FT_Err_Ok;
goto Exit;
}
face->cvt_size = table_len / 2;
if ( FT_NEW_ARRAY( face->cvt, face->cvt_size ) )
goto Exit;
if ( FT_FRAME_ENTER( face->cvt_size * 2L ) )
goto Exit;
{
FT_Short* cur = face->cvt;
FT_Short* limit = cur + face->cvt_size;
for ( ; cur < limit; cur++ )
*cur = FT_GET_SHORT();
}
FT_FRAME_EXIT();
FT_TRACE2(( "loaded\n" ));
#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
if ( face->doblend )
error = tt_face_vary_cvt( face, stream );
#endif
Exit:
return error;
#else /* !TT_USE_BYTECODE_INTERPRETER */
FT_UNUSED( face );
FT_UNUSED( stream );
return FT_Err_Ok;
#endif
}
|
@@ -508,9 +508,9 @@
record_size = FT_NEXT_ULONG( p );
/* The maximum number of bytes in an hdmx device record is the */
- /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */
- /* the reason why `record_size' is a long (which we read as */
- /* unsigned long for convenience). In practice, two bytes */
+ /* maximum number of glyphs + 2; this is 0xFFFF + 2, thus */
+ /* explaining why `record_size' is a long (which we read as */
+ /* unsigned long for convenience). In practice, two bytes are */
/* sufficient to hold the size value. */
/* */
/* There are at least two fonts, HANNOM-A and HANNOM-B version */
@@ -522,8 +522,10 @@
record_size &= 0xFFFFU;
/* The limit for `num_records' is a heuristic value. */
-
- if ( version != 0 || num_records > 255 || record_size > 0x10001L )
+ if ( version != 0 ||
+ num_records > 255 ||
+ record_size > 0x10001L ||
+ record_size < 4 )
{
error = FT_THROW( Invalid_File_Format );
goto Fail;
|
CWE-125
| null | null |
5,702
|
tt_face_load_loca( TT_Face face,
FT_Stream stream )
{
FT_Error error;
FT_ULong table_len;
FT_Int shift;
/* we need the size of the `glyf' table for malformed `loca' tables */
error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len );
/* it is possible that a font doesn't have a glyf table at all */
/* or its size is zero */
if ( FT_ERR_EQ( error, Table_Missing ) )
face->glyf_len = 0;
else if ( error )
goto Exit;
FT_TRACE2(( "Locations " ));
error = face->goto_table( face, TTAG_loca, stream, &table_len );
if ( error )
{
error = FT_THROW( Locations_Missing );
goto Exit;
}
if ( face->header.Index_To_Loc_Format != 0 )
{
shift = 2;
if ( table_len >= 0x40000L )
{
FT_TRACE2(( "table too large\n" ));
error = FT_THROW( Invalid_Table );
goto Exit;
}
face->num_locations = table_len >> shift;
}
else
{
shift = 1;
if ( table_len >= 0x20000L )
{
FT_TRACE2(( "table too large\n" ));
error = FT_THROW( Invalid_Table );
goto Exit;
}
face->num_locations = table_len >> shift;
}
if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 )
{
FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n",
face->num_locations - 1, face->root.num_glyphs ));
/* we only handle the case where `maxp' gives a larger value */
if ( face->num_locations <= (FT_ULong)face->root.num_glyphs )
{
FT_Long new_loca_len =
( (FT_Long)( face->root.num_glyphs ) + 1 ) << shift;
TT_Table entry = face->dir_tables;
TT_Table limit = entry + face->num_tables;
FT_Long pos = FT_Stream_Pos( stream );
FT_Long dist = 0x7FFFFFFFL;
/* compute the distance to next table in font file */
for ( ; entry < limit; entry++ )
{
FT_Long diff = entry->Offset - pos;
if ( diff > 0 && diff < dist )
dist = diff;
}
if ( entry == limit )
{
/* `loca' is the last table */
dist = stream->size - pos;
}
if ( new_loca_len <= dist )
{
face->num_locations = face->root.num_glyphs + 1;
table_len = new_loca_len;
FT_TRACE2(( "adjusting num_locations to %d\n",
face->num_locations ));
}
}
}
/*
* Extract the frame. We don't need to decompress it since
* we are able to parse it directly.
*/
if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) )
goto Exit;
FT_TRACE2(( "loaded\n" ));
Exit:
return error;
}
|
DoS
| 0
|
tt_face_load_loca( TT_Face face,
FT_Stream stream )
{
FT_Error error;
FT_ULong table_len;
FT_Int shift;
/* we need the size of the `glyf' table for malformed `loca' tables */
error = face->goto_table( face, TTAG_glyf, stream, &face->glyf_len );
/* it is possible that a font doesn't have a glyf table at all */
/* or its size is zero */
if ( FT_ERR_EQ( error, Table_Missing ) )
face->glyf_len = 0;
else if ( error )
goto Exit;
FT_TRACE2(( "Locations " ));
error = face->goto_table( face, TTAG_loca, stream, &table_len );
if ( error )
{
error = FT_THROW( Locations_Missing );
goto Exit;
}
if ( face->header.Index_To_Loc_Format != 0 )
{
shift = 2;
if ( table_len >= 0x40000L )
{
FT_TRACE2(( "table too large\n" ));
error = FT_THROW( Invalid_Table );
goto Exit;
}
face->num_locations = table_len >> shift;
}
else
{
shift = 1;
if ( table_len >= 0x20000L )
{
FT_TRACE2(( "table too large\n" ));
error = FT_THROW( Invalid_Table );
goto Exit;
}
face->num_locations = table_len >> shift;
}
if ( face->num_locations != (FT_ULong)face->root.num_glyphs + 1 )
{
FT_TRACE2(( "glyph count mismatch! loca: %d, maxp: %d\n",
face->num_locations - 1, face->root.num_glyphs ));
/* we only handle the case where `maxp' gives a larger value */
if ( face->num_locations <= (FT_ULong)face->root.num_glyphs )
{
FT_Long new_loca_len =
( (FT_Long)( face->root.num_glyphs ) + 1 ) << shift;
TT_Table entry = face->dir_tables;
TT_Table limit = entry + face->num_tables;
FT_Long pos = FT_Stream_Pos( stream );
FT_Long dist = 0x7FFFFFFFL;
/* compute the distance to next table in font file */
for ( ; entry < limit; entry++ )
{
FT_Long diff = entry->Offset - pos;
if ( diff > 0 && diff < dist )
dist = diff;
}
if ( entry == limit )
{
/* `loca' is the last table */
dist = stream->size - pos;
}
if ( new_loca_len <= dist )
{
face->num_locations = face->root.num_glyphs + 1;
table_len = new_loca_len;
FT_TRACE2(( "adjusting num_locations to %d\n",
face->num_locations ));
}
}
}
/*
* Extract the frame. We don't need to decompress it since
* we are able to parse it directly.
*/
if ( FT_FRAME_EXTRACT( table_len, face->glyph_locations ) )
goto Exit;
FT_TRACE2(( "loaded\n" ));
Exit:
return error;
}
|
@@ -508,9 +508,9 @@
record_size = FT_NEXT_ULONG( p );
/* The maximum number of bytes in an hdmx device record is the */
- /* maximum number of glyphs + 2; this is 0xFFFF + 2; this is */
- /* the reason why `record_size' is a long (which we read as */
- /* unsigned long for convenience). In practice, two bytes */
+ /* maximum number of glyphs + 2; this is 0xFFFF + 2, thus */
+ /* explaining why `record_size' is a long (which we read as */
+ /* unsigned long for convenience). In practice, two bytes are */
/* sufficient to hold the size value. */
/* */
/* There are at least two fonts, HANNOM-A and HANNOM-B version */
@@ -522,8 +522,10 @@
record_size &= 0xFFFFU;
/* The limit for `num_records' is a heuristic value. */
-
- if ( version != 0 || num_records > 255 || record_size > 0x10001L )
+ if ( version != 0 ||
+ num_records > 255 ||
+ record_size > 0x10001L ||
+ record_size < 4 )
{
error = FT_THROW( Invalid_File_Format );
goto Fail;
|
CWE-125
| null | null |
5,703
|
static int aesni_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
const unsigned char *inkey,
const unsigned char *iv, int enc)
{
EVP_AES_HMAC_SHA1 *key = data(ctx);
int ret;
if (enc)
ret=aesni_set_encrypt_key(inkey,ctx->key_len*8,&key->ks);
else
ret=aesni_set_decrypt_key(inkey,ctx->key_len*8,&key->ks);
SHA1_Init(&key->head); /* handy when benchmarking */
key->tail = key->head;
key->md = key->head;
key->payload_length = NO_PAYLOAD_LENGTH;
return ret<0?0:1;
}
|
DoS
| 0
|
static int aesni_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx,
const unsigned char *inkey,
const unsigned char *iv, int enc)
{
EVP_AES_HMAC_SHA1 *key = data(ctx);
int ret;
if (enc)
ret=aesni_set_encrypt_key(inkey,ctx->key_len*8,&key->ks);
else
ret=aesni_set_decrypt_key(inkey,ctx->key_len*8,&key->ks);
SHA1_Init(&key->head); /* handy when benchmarking */
key->tail = key->head;
key->md = key->head;
key->payload_length = NO_PAYLOAD_LENGTH;
return ret<0?0:1;
}
|
@@ -1,5 +1,5 @@
/* ====================================================================
- * Copyright (c) 2011 The OpenSSL Project. All rights reserved.
+ * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -90,6 +90,10 @@ typedef struct
defined(_M_AMD64) || defined(_M_X64) || \
defined(__INTEL__) )
+#if defined(__GNUC__) && __GNUC__>=2 && !defined(PEDANTIC)
+# define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; })
+#endif
+
extern unsigned int OPENSSL_ia32cap_P[2];
#define AESNI_CAPABLE (1<<(57-32))
@@ -167,6 +171,9 @@ static void sha1_update(SHA_CTX *c,const void *data,size_t len)
SHA1_Update(c,ptr,res);
}
+#ifdef SHA1_Update
+#undef SHA1_Update
+#endif
#define SHA1_Update sha1_update
static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
@@ -184,6 +191,8 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
sha_off = SHA_CBLOCK-key->md.num;
#endif
+ key->payload_length = NO_PAYLOAD_LENGTH;
+
if (len%AES_BLOCK_SIZE) return 0;
if (ctx->encrypt) {
@@ -234,47 +243,203 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
&key->ks,ctx->iv,1);
}
} else {
- unsigned char mac[SHA_DIGEST_LENGTH];
+ union { unsigned int u[SHA_DIGEST_LENGTH/sizeof(unsigned int)];
+ unsigned char c[SHA_DIGEST_LENGTH]; } mac;
/* decrypt HMAC|padding at once */
aesni_cbc_encrypt(in,out,len,
&key->ks,ctx->iv,0);
if (plen) { /* "TLS" mode of operation */
- /* figure out payload length */
- if (len<(size_t)(out[len-1]+1+SHA_DIGEST_LENGTH))
- return 0;
-
- len -= (out[len-1]+1+SHA_DIGEST_LENGTH);
+ size_t inp_len, mask, j, i;
+ unsigned int res, maxpad, pad, bitlen;
+ int ret = 1;
+ union { unsigned int u[SHA_LBLOCK];
+ unsigned char c[SHA_CBLOCK]; }
+ *data = (void *)key->md.data;
if ((key->aux.tls_aad[plen-4]<<8|key->aux.tls_aad[plen-3])
- >= TLS1_1_VERSION) {
- len -= AES_BLOCK_SIZE;
+ >= TLS1_1_VERSION)
iv = AES_BLOCK_SIZE;
- }
- key->aux.tls_aad[plen-2] = len>>8;
- key->aux.tls_aad[plen-1] = len;
+ if (len<(iv+SHA_DIGEST_LENGTH+1))
+ return 0;
+
+ /* omit explicit iv */
+ out += iv;
+ len -= iv;
+
+ /* figure out payload length */
+ pad = out[len-1];
+ maxpad = len-(SHA_DIGEST_LENGTH+1);
+ maxpad |= (255-maxpad)>>(sizeof(maxpad)*8-8);
+ maxpad &= 255;
+
+ inp_len = len - (SHA_DIGEST_LENGTH+pad+1);
+ mask = (0-((inp_len-len)>>(sizeof(inp_len)*8-1)));
+ inp_len &= mask;
+ ret &= (int)mask;
- /* calculate HMAC and verify it */
+ key->aux.tls_aad[plen-2] = inp_len>>8;
+ key->aux.tls_aad[plen-1] = inp_len;
+
+ /* calculate HMAC */
key->md = key->head;
SHA1_Update(&key->md,key->aux.tls_aad,plen);
- SHA1_Update(&key->md,out+iv,len);
- SHA1_Final(mac,&key->md);
+#if 1
+ len -= SHA_DIGEST_LENGTH; /* amend mac */
+ if (len>=(256+SHA_CBLOCK)) {
+ j = (len-(256+SHA_CBLOCK))&(0-SHA_CBLOCK);
+ j += SHA_CBLOCK-key->md.num;
+ SHA1_Update(&key->md,out,j);
+ out += j;
+ len -= j;
+ inp_len -= j;
+ }
+
+ /* but pretend as if we hashed padded payload */
+ bitlen = key->md.Nl+(inp_len<<3); /* at most 18 bits */
+ mac.c[0] = 0;
+ mac.c[1] = (unsigned char)(bitlen>>16);
+ mac.c[2] = (unsigned char)(bitlen>>8);
+ mac.c[3] = (unsigned char)bitlen;
+ bitlen = mac.u[0];
+
+ mac.u[0]=0;
+ mac.u[1]=0;
+ mac.u[2]=0;
+ mac.u[3]=0;
+ mac.u[4]=0;
+
+ for (res=key->md.num, j=0;j<len;j++) {
+ size_t c = out[j];
+ mask = (j-inp_len)>>(sizeof(j)*8-8);
+ c &= mask;
+ c |= 0x80&~mask&~((inp_len-j)>>(sizeof(j)*8-8));
+ data->c[res++]=(unsigned char)c;
+
+ if (res!=SHA_CBLOCK) continue;
+
+ mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1));
+ data->u[SHA_LBLOCK-1] |= bitlen&mask;
+ sha1_block_data_order(&key->md,data,1);
+ mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1));
+ mac.u[0] |= key->md.h0 & mask;
+ mac.u[1] |= key->md.h1 & mask;
+ mac.u[2] |= key->md.h2 & mask;
+ mac.u[3] |= key->md.h3 & mask;
+ mac.u[4] |= key->md.h4 & mask;
+ res=0;
+ }
+
+ for(i=res;i<SHA_CBLOCK;i++,j++) data->c[i]=0;
+
+ if (res>SHA_CBLOCK-8) {
+ mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1));
+ data->u[SHA_LBLOCK-1] |= bitlen&mask;
+ sha1_block_data_order(&key->md,data,1);
+ mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1));
+ mac.u[0] |= key->md.h0 & mask;
+ mac.u[1] |= key->md.h1 & mask;
+ mac.u[2] |= key->md.h2 & mask;
+ mac.u[3] |= key->md.h3 & mask;
+ mac.u[4] |= key->md.h4 & mask;
+
+ memset(data,0,SHA_CBLOCK);
+ j+=64;
+ }
+ data->u[SHA_LBLOCK-1] = bitlen;
+ sha1_block_data_order(&key->md,data,1);
+ mask = 0-((j-inp_len-73)>>(sizeof(j)*8-1));
+ mac.u[0] |= key->md.h0 & mask;
+ mac.u[1] |= key->md.h1 & mask;
+ mac.u[2] |= key->md.h2 & mask;
+ mac.u[3] |= key->md.h3 & mask;
+ mac.u[4] |= key->md.h4 & mask;
+
+#ifdef BSWAP
+ mac.u[0] = BSWAP(mac.u[0]);
+ mac.u[1] = BSWAP(mac.u[1]);
+ mac.u[2] = BSWAP(mac.u[2]);
+ mac.u[3] = BSWAP(mac.u[3]);
+ mac.u[4] = BSWAP(mac.u[4]);
+#else
+ for (i=0;i<5;i++) {
+ res = mac.u[i];
+ mac.c[4*i+0]=(unsigned char)(res>>24);
+ mac.c[4*i+1]=(unsigned char)(res>>16);
+ mac.c[4*i+2]=(unsigned char)(res>>8);
+ mac.c[4*i+3]=(unsigned char)res;
+ }
+#endif
+ len += SHA_DIGEST_LENGTH;
+#else
+ SHA1_Update(&key->md,out,inp_len);
+ res = key->md.num;
+ SHA1_Final(mac.c,&key->md);
+
+ {
+ unsigned int inp_blocks, pad_blocks;
+
+ /* but pretend as if we hashed padded payload */
+ inp_blocks = 1+((SHA_CBLOCK-9-res)>>(sizeof(res)*8-1));
+ res += (unsigned int)(len-inp_len);
+ pad_blocks = res / SHA_CBLOCK;
+ res %= SHA_CBLOCK;
+ pad_blocks += 1+((SHA_CBLOCK-9-res)>>(sizeof(res)*8-1));
+ for (;inp_blocks<pad_blocks;inp_blocks++)
+ sha1_block_data_order(&key->md,data,1);
+ }
+#endif
key->md = key->tail;
- SHA1_Update(&key->md,mac,SHA_DIGEST_LENGTH);
- SHA1_Final(mac,&key->md);
+ SHA1_Update(&key->md,mac.c,SHA_DIGEST_LENGTH);
+ SHA1_Final(mac.c,&key->md);
- if (memcmp(out+iv+len,mac,SHA_DIGEST_LENGTH))
- return 0;
+ /* verify HMAC */
+ out += inp_len;
+ len -= inp_len;
+#if 1
+ {
+ unsigned char *p = out+len-1-maxpad-SHA_DIGEST_LENGTH;
+ size_t off = out-p;
+ unsigned int c, cmask;
+
+ maxpad += SHA_DIGEST_LENGTH;
+ for (res=0,i=0,j=0;j<maxpad;j++) {
+ c = p[j];
+ cmask = ((int)(j-off-SHA_DIGEST_LENGTH))>>(sizeof(int)*8-1);
+ res |= (c^pad)&~cmask; /* ... and padding */
+ cmask &= ((int)(off-1-j))>>(sizeof(int)*8-1);
+ res |= (c^mac.c[i])&cmask;
+ i += 1&cmask;
+ }
+ maxpad -= SHA_DIGEST_LENGTH;
+
+ res = 0-((0-res)>>(sizeof(res)*8-1));
+ ret &= (int)~res;
+ }
+#else
+ for (res=0,i=0;i<SHA_DIGEST_LENGTH;i++)
+ res |= out[i]^mac.c[i];
+ res = 0-((0-res)>>(sizeof(res)*8-1));
+ ret &= (int)~res;
+
+ /* verify padding */
+ pad = (pad&~res) | (maxpad&res);
+ out = out+len-1-pad;
+ for (res=0,i=0;i<pad;i++)
+ res |= out[i]^pad;
+
+ res = (0-res)>>(sizeof(res)*8-1);
+ ret &= (int)~res;
+#endif
+ return ret;
} else {
SHA1_Update(&key->md,out,len);
}
}
- key->payload_length = NO_PAYLOAD_LENGTH;
-
return 1;
}
|
CWE-310
| null | null |
5,704
|
static unsigned char constant_time_eq_8(unsigned char a, unsigned char b)
{
unsigned c = a ^ b;
c--;
return DUPLICATE_MSB_TO_ALL_8(c);
}
|
DoS
| 0
|
static unsigned char constant_time_eq_8(unsigned char a, unsigned char b)
{
unsigned c = a ^ b;
c--;
return DUPLICATE_MSB_TO_ALL_8(c);
}
|
@@ -150,6 +150,21 @@ int tls1_cbc_remove_padding(const SSL* s,
if (overhead > rec->length)
return 0;
+ /* We can always safely skip the explicit IV. We check at the beginning
+ * of this function that the record has at least enough space for the
+ * IV, MAC and padding length byte. (These can be checked in
+ * non-constant time because it's all public information.) So, if the
+ * padding was invalid, then we didn't change |rec->length| and this is
+ * safe. If the padding was valid then we know that we have at least
+ * overhead+padding_length bytes of space and so this is still safe
+ * because overhead accounts for the explicit IV. */
+ if (has_explicit_iv)
+ {
+ rec->data += block_size;
+ rec->input += block_size;
+ rec->length -= block_size;
+ }
+
padding_length = rec->data[rec->length-1];
/* NB: if compression is in operation the first packet may not be of
@@ -172,6 +187,13 @@ int tls1_cbc_remove_padding(const SSL* s,
}
}
+ if (EVP_CIPHER_flags(s->enc_read_ctx->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER)
+ {
+ /* padding is already verified */
+ rec->length -= padding_length;
+ return 1;
+ }
+
good = constant_time_ge(rec->length, overhead+padding_length);
/* The padding consists of a length byte at the end of the record and
* then that many bytes of padding, all with the same value as the
@@ -209,21 +231,6 @@ int tls1_cbc_remove_padding(const SSL* s,
rec->length -= padding_length;
rec->type |= padding_length<<8; /* kludge: pass padding length */
- /* We can always safely skip the explicit IV. We check at the beginning
- * of this function that the record has at least enough space for the
- * IV, MAC and padding length byte. (These can be checked in
- * non-constant time because it's all public information.) So, if the
- * padding was invalid, then we didn't change |rec->length| and this is
- * safe. If the padding was valid then we know that we have at least
- * overhead+padding_length bytes of space and so this is still safe
- * because overhead accounts for the explicit IV. */
- if (has_explicit_iv)
- {
- rec->data += block_size;
- rec->input += block_size;
- rec->length -= block_size;
- }
-
return (int)((good & 1) | (~good & -1));
}
|
CWE-310
| null | null |
5,705
|
static unsigned constant_time_ge(unsigned a, unsigned b)
{
a -= b;
return DUPLICATE_MSB_TO_ALL(~a);
}
|
DoS
| 0
|
static unsigned constant_time_ge(unsigned a, unsigned b)
{
a -= b;
return DUPLICATE_MSB_TO_ALL(~a);
}
|
@@ -150,6 +150,21 @@ int tls1_cbc_remove_padding(const SSL* s,
if (overhead > rec->length)
return 0;
+ /* We can always safely skip the explicit IV. We check at the beginning
+ * of this function that the record has at least enough space for the
+ * IV, MAC and padding length byte. (These can be checked in
+ * non-constant time because it's all public information.) So, if the
+ * padding was invalid, then we didn't change |rec->length| and this is
+ * safe. If the padding was valid then we know that we have at least
+ * overhead+padding_length bytes of space and so this is still safe
+ * because overhead accounts for the explicit IV. */
+ if (has_explicit_iv)
+ {
+ rec->data += block_size;
+ rec->input += block_size;
+ rec->length -= block_size;
+ }
+
padding_length = rec->data[rec->length-1];
/* NB: if compression is in operation the first packet may not be of
@@ -172,6 +187,13 @@ int tls1_cbc_remove_padding(const SSL* s,
}
}
+ if (EVP_CIPHER_flags(s->enc_read_ctx->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER)
+ {
+ /* padding is already verified */
+ rec->length -= padding_length;
+ return 1;
+ }
+
good = constant_time_ge(rec->length, overhead+padding_length);
/* The padding consists of a length byte at the end of the record and
* then that many bytes of padding, all with the same value as the
@@ -209,21 +231,6 @@ int tls1_cbc_remove_padding(const SSL* s,
rec->length -= padding_length;
rec->type |= padding_length<<8; /* kludge: pass padding length */
- /* We can always safely skip the explicit IV. We check at the beginning
- * of this function that the record has at least enough space for the
- * IV, MAC and padding length byte. (These can be checked in
- * non-constant time because it's all public information.) So, if the
- * padding was invalid, then we didn't change |rec->length| and this is
- * safe. If the padding was valid then we know that we have at least
- * overhead+padding_length bytes of space and so this is still safe
- * because overhead accounts for the explicit IV. */
- if (has_explicit_iv)
- {
- rec->data += block_size;
- rec->input += block_size;
- rec->length -= block_size;
- }
-
return (int)((good & 1) | (~good & -1));
}
|
CWE-310
| null | null |
5,706
|
int ssl3_cbc_remove_padding(const SSL* s,
SSL3_RECORD *rec,
unsigned block_size,
unsigned mac_size)
{
unsigned padding_length, good;
const unsigned overhead = 1 /* padding length byte */ + mac_size;
/* These lengths are all public so we can test them in non-constant
* time. */
if (overhead > rec->length)
return 0;
padding_length = rec->data[rec->length-1];
good = constant_time_ge(rec->length, padding_length+overhead);
/* SSLv3 requires that the padding is minimal. */
good &= constant_time_ge(block_size, padding_length+1);
padding_length = good & (padding_length+1);
rec->length -= padding_length;
rec->type |= padding_length<<8; /* kludge: pass padding length */
return (int)((good & 1) | (~good & -1));
}
|
DoS
| 0
|
int ssl3_cbc_remove_padding(const SSL* s,
SSL3_RECORD *rec,
unsigned block_size,
unsigned mac_size)
{
unsigned padding_length, good;
const unsigned overhead = 1 /* padding length byte */ + mac_size;
/* These lengths are all public so we can test them in non-constant
* time. */
if (overhead > rec->length)
return 0;
padding_length = rec->data[rec->length-1];
good = constant_time_ge(rec->length, padding_length+overhead);
/* SSLv3 requires that the padding is minimal. */
good &= constant_time_ge(block_size, padding_length+1);
padding_length = good & (padding_length+1);
rec->length -= padding_length;
rec->type |= padding_length<<8; /* kludge: pass padding length */
return (int)((good & 1) | (~good & -1));
}
|
@@ -150,6 +150,21 @@ int tls1_cbc_remove_padding(const SSL* s,
if (overhead > rec->length)
return 0;
+ /* We can always safely skip the explicit IV. We check at the beginning
+ * of this function that the record has at least enough space for the
+ * IV, MAC and padding length byte. (These can be checked in
+ * non-constant time because it's all public information.) So, if the
+ * padding was invalid, then we didn't change |rec->length| and this is
+ * safe. If the padding was valid then we know that we have at least
+ * overhead+padding_length bytes of space and so this is still safe
+ * because overhead accounts for the explicit IV. */
+ if (has_explicit_iv)
+ {
+ rec->data += block_size;
+ rec->input += block_size;
+ rec->length -= block_size;
+ }
+
padding_length = rec->data[rec->length-1];
/* NB: if compression is in operation the first packet may not be of
@@ -172,6 +187,13 @@ int tls1_cbc_remove_padding(const SSL* s,
}
}
+ if (EVP_CIPHER_flags(s->enc_read_ctx->cipher)&EVP_CIPH_FLAG_AEAD_CIPHER)
+ {
+ /* padding is already verified */
+ rec->length -= padding_length;
+ return 1;
+ }
+
good = constant_time_ge(rec->length, overhead+padding_length);
/* The padding consists of a length byte at the end of the record and
* then that many bytes of padding, all with the same value as the
@@ -209,21 +231,6 @@ int tls1_cbc_remove_padding(const SSL* s,
rec->length -= padding_length;
rec->type |= padding_length<<8; /* kludge: pass padding length */
- /* We can always safely skip the explicit IV. We check at the beginning
- * of this function that the record has at least enough space for the
- * IV, MAC and padding length byte. (These can be checked in
- * non-constant time because it's all public information.) So, if the
- * padding was invalid, then we didn't change |rec->length| and this is
- * safe. If the padding was valid then we know that we have at least
- * overhead+padding_length bytes of space and so this is still safe
- * because overhead accounts for the explicit IV. */
- if (has_explicit_iv)
- {
- rec->data += block_size;
- rec->input += block_size;
- rec->length -= block_size;
- }
-
return (int)((good & 1) | (~good & -1));
}
|
CWE-310
| null | null |
5,707
|
Private() {}
|
+Priv
| 0
|
Private() {}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,708
|
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
Q_UNUSED(action)
Q_UNUSED(parent)
}
|
+Priv
| 0
|
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
Q_UNUSED(action)
Q_UNUSED(parent)
}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,709
|
AuthBackend::Capabilities AuthBackend::capabilities() const
{
return d->capabilities;
}
|
+Priv
| 0
|
AuthBackend::Capabilities AuthBackend::capabilities() const
{
return d->capabilities;
}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,710
|
virtual ~Private() {}
|
+Priv
| 0
|
virtual ~Private() {}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString &action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,711
|
DBusHelperProxy::DBusHelperProxy()
: responder(nullptr)
, m_stopRequest(false)
, m_busConnection(QDBusConnection::systemBus())
{
}
|
+Priv
| 0
|
DBusHelperProxy::DBusHelperProxy()
: responder(nullptr)
, m_stopRequest(false)
, m_busConnection(QDBusConnection::systemBus())
{
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,712
|
DBusHelperProxy::DBusHelperProxy(const QDBusConnection &busConnection)
: responder(nullptr)
, m_stopRequest(false)
, m_busConnection(busConnection)
{
}
|
+Priv
| 0
|
DBusHelperProxy::DBusHelperProxy(const QDBusConnection &busConnection)
: responder(nullptr)
, m_stopRequest(false)
, m_busConnection(busConnection)
{
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,713
|
Action::AuthStatus DBusHelperProxy::authorizeAction(const QString &action, const QString &helperID)
{
if (!m_actionsInProgress.isEmpty()) {
return Action::ErrorStatus;
}
m_busConnection.interface()->startService(helperID);
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("authorizeAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID();
message.setArguments(args);
m_actionsInProgress.push_back(action);
QEventLoop e;
QDBusPendingCall pendingCall = m_busConnection.asyncCall(message);
QDBusPendingCallWatcher watcher(pendingCall, this);
connect(&watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), &e, SLOT(quit()));
e.exec();
m_actionsInProgress.removeOne(action);
QDBusMessage reply = pendingCall.reply();
if (reply.type() == QDBusMessage::ErrorMessage || reply.arguments().size() != 1) {
return Action::ErrorStatus;
}
return static_cast<Action::AuthStatus>(reply.arguments().first().toUInt());
}
|
+Priv
| 0
|
Action::AuthStatus DBusHelperProxy::authorizeAction(const QString &action, const QString &helperID)
{
if (!m_actionsInProgress.isEmpty()) {
return Action::ErrorStatus;
}
m_busConnection.interface()->startService(helperID);
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("authorizeAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID();
message.setArguments(args);
m_actionsInProgress.push_back(action);
QEventLoop e;
QDBusPendingCall pendingCall = m_busConnection.asyncCall(message);
QDBusPendingCallWatcher watcher(pendingCall, this);
connect(&watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), &e, SLOT(quit()));
e.exec();
m_actionsInProgress.removeOne(action);
QDBusMessage reply = pendingCall.reply();
if (reply.type() == QDBusMessage::ErrorMessage || reply.arguments().size() != 1) {
return Action::ErrorStatus;
}
return static_cast<Action::AuthStatus>(reply.arguments().first().toUInt());
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,714
|
void DBusHelperProxy::executeAction(const QString &action, const QString &helperID, const QVariantMap &arguments, int timeout)
{
QByteArray blob;
{
QDataStream stream(&blob, QIODevice::WriteOnly);
stream << arguments;
}
const auto reply = m_busConnection.interface()->startService(helperID);
if (!reply.isValid() && !m_busConnection.interface()->isServiceRegistered(helperID)) {
ActionReply errorReply = ActionReply::DBusErrorReply();
errorReply.setErrorDescription(tr("DBus Backend error: service start %1 failed: %2").arg(helperID, reply.error().message()));
emit actionPerformed(action, errorReply);
return;
}
const bool connected = m_busConnection.connect(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("remoteSignal"), this, SLOT(remoteSignalReceived(int,QString,QByteArray)));
if (!connected && m_busConnection.lastError().isValid()) {
ActionReply errorReply = ActionReply::DBusErrorReply();
errorReply.setErrorDescription(tr("DBus Backend error: connection to helper failed. %1\n(application: %2 helper: %3)").arg(
m_busConnection.lastError().message(),
qApp->applicationName(),
helperID));
emit actionPerformed(action, errorReply);
return;
}
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("performAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID() << blob;
message.setArguments(args);
m_actionsInProgress.push_back(action);
QDBusPendingCall pendingCall = m_busConnection.asyncCall(message, timeout);
auto watcher = new QDBusPendingCallWatcher(pendingCall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, action, watcher]() {
watcher->deleteLater();
const QDBusMessage reply = watcher->reply();
if (reply.type() == QDBusMessage::ErrorMessage) {
ActionReply r = ActionReply::DBusErrorReply();
r.setErrorDescription(tr("DBus Backend error: could not contact the helper. "
"Connection error: %1. Message error: %2").arg(reply.errorMessage(), m_busConnection.lastError().message()));
qCWarning(KAUTH) << reply.errorMessage();
emit actionPerformed(action, r);
}
});
}
|
+Priv
| 0
|
void DBusHelperProxy::executeAction(const QString &action, const QString &helperID, const QVariantMap &arguments, int timeout)
{
QByteArray blob;
{
QDataStream stream(&blob, QIODevice::WriteOnly);
stream << arguments;
}
const auto reply = m_busConnection.interface()->startService(helperID);
if (!reply.isValid() && !m_busConnection.interface()->isServiceRegistered(helperID)) {
ActionReply errorReply = ActionReply::DBusErrorReply();
errorReply.setErrorDescription(tr("DBus Backend error: service start %1 failed: %2").arg(helperID, reply.error().message()));
emit actionPerformed(action, errorReply);
return;
}
const bool connected = m_busConnection.connect(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("remoteSignal"), this, SLOT(remoteSignalReceived(int,QString,QByteArray)));
if (!connected && m_busConnection.lastError().isValid()) {
ActionReply errorReply = ActionReply::DBusErrorReply();
errorReply.setErrorDescription(tr("DBus Backend error: connection to helper failed. %1\n(application: %2 helper: %3)").arg(
m_busConnection.lastError().message(),
qApp->applicationName(),
helperID));
emit actionPerformed(action, errorReply);
return;
}
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.kf5auth"), QLatin1String("performAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID() << blob;
message.setArguments(args);
m_actionsInProgress.push_back(action);
QDBusPendingCall pendingCall = m_busConnection.asyncCall(message, timeout);
auto watcher = new QDBusPendingCallWatcher(pendingCall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, action, watcher]() {
watcher->deleteLater();
const QDBusMessage reply = watcher->reply();
if (reply.type() == QDBusMessage::ErrorMessage) {
ActionReply r = ActionReply::DBusErrorReply();
r.setErrorDescription(tr("DBus Backend error: could not contact the helper. "
"Connection error: %1. Message error: %2").arg(reply.errorMessage(), m_busConnection.lastError().message()));
qCWarning(KAUTH) << reply.errorMessage();
emit actionPerformed(action, r);
}
});
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,715
|
bool DBusHelperProxy::hasToStopAction()
{
QEventLoop loop;
loop.processEvents(QEventLoop::AllEvents);
return m_stopRequest;
}
|
+Priv
| 0
|
bool DBusHelperProxy::hasToStopAction()
{
QEventLoop loop;
loop.processEvents(QEventLoop::AllEvents);
return m_stopRequest;
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,716
|
bool DBusHelperProxy::initHelper(const QString &name)
{
new Kf5authAdaptor(this);
if (!m_busConnection.registerService(name)) {
qCWarning(KAUTH) << "Error registering helper DBus service" << name << m_busConnection.lastError().message();
return false;
}
if (!m_busConnection.registerObject(QLatin1String("/"), this)) {
qCWarning(KAUTH) << "Error registering helper DBus object:" << m_busConnection.lastError().message();
return false;
}
m_name = name;
return true;
}
|
+Priv
| 0
|
bool DBusHelperProxy::initHelper(const QString &name)
{
new Kf5authAdaptor(this);
if (!m_busConnection.registerService(name)) {
qCWarning(KAUTH) << "Error registering helper DBus service" << name << m_busConnection.lastError().message();
return false;
}
if (!m_busConnection.registerObject(QLatin1String("/"), this)) {
qCWarning(KAUTH) << "Error registering helper DBus object:" << m_busConnection.lastError().message();
return false;
}
m_name = name;
return true;
}
|
@@ -235,6 +235,29 @@ bool DBusHelperProxy::hasToStopAction()
return m_stopRequest;
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -259,7 +282,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -301,7 +324,7 @@ uint DBusHelperProxy::authorizeAction(const QString &action, const QByteArray &c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer *>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::AuthorizedStatus);
} else {
retVal = static_cast<uint>(Action::DeniedStatus);
|
CWE-290
| null | null |
5,717
|
PolicyKitBackend::PolicyKitBackend()
: AuthBackend()
{
setCapabilities(AuthorizeFromClientCapability);
}
|
+Priv
| 0
|
PolicyKitBackend::PolicyKitBackend()
: AuthBackend()
{
setCapabilities(AuthorizeFromClientCapability);
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,718
|
Action::AuthStatus PolicyKitBackend::actionStatus(const QString &action)
{
PolkitQt::Auth::Result r = PolkitQt::Auth::isCallerAuthorized(action, QCoreApplication::applicationPid(),
false);
switch (r) {
case PolkitQt::Auth::Yes:
return Action::StatusAuthorized;
case PolkitQt::Auth::No:
case PolkitQt::Auth::Unknown:
return Action::StatusDenied;
default:
return Action::StatusAuthRequired;
}
}
|
+Priv
| 0
|
Action::AuthStatus PolicyKitBackend::actionStatus(const QString &action)
{
PolkitQt::Auth::Result r = PolkitQt::Auth::isCallerAuthorized(action, QCoreApplication::applicationPid(),
false);
switch (r) {
case PolkitQt::Auth::Yes:
return Action::StatusAuthorized;
case PolkitQt::Auth::No:
case PolkitQt::Auth::Unknown:
return Action::StatusDenied;
default:
return Action::StatusAuthRequired;
}
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,719
|
Action::AuthStatus PolicyKitBackend::authorizeAction(const QString &action)
{
switch (PolkitQt::Auth::computeAndObtainAuth(action)) {
case PolkitQt::Auth::Yes:
return Action::StatusAuthorized;
default:
return Action::StatusDenied;
}
}
|
+Priv
| 0
|
Action::AuthStatus PolicyKitBackend::authorizeAction(const QString &action)
{
switch (PolkitQt::Auth::computeAndObtainAuth(action)) {
case PolkitQt::Auth::Yes:
return Action::StatusAuthorized;
default:
return Action::StatusDenied;
}
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,720
|
QByteArray PolicyKitBackend::callerID() const
{
QByteArray a;
QDataStream s(&a, QIODevice::WriteOnly);
s << QCoreApplication::applicationPid();
return a;
}
|
+Priv
| 0
|
QByteArray PolicyKitBackend::callerID() const
{
QByteArray a;
QDataStream s(&a, QIODevice::WriteOnly);
s << QCoreApplication::applicationPid();
return a;
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,721
|
void PolicyKitBackend::checkForResultChanged()
{
QHash<QString, Action::AuthStatus>::iterator i;
for (i = m_cachedResults.begin(); i != m_cachedResults.end(); ++i) {
if (i.value() != actionStatus(i.key())) {
i.value() = actionStatus(i.key());
emit actionStatusChanged(i.key(), i.value());
}
}
}
|
+Priv
| 0
|
void PolicyKitBackend::checkForResultChanged()
{
QHash<QString, Action::AuthStatus>::iterator i;
for (i = m_cachedResults.begin(); i != m_cachedResults.end(); ++i) {
if (i.value() != actionStatus(i.key())) {
i.value() = actionStatus(i.key());
emit actionStatusChanged(i.key(), i.value());
}
}
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,722
|
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
}
|
+Priv
| 0
|
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,723
|
void PolicyKitBackend::setupAction(const QString &action)
{
connect(PolkitQt::Context::instance(), SIGNAL(configChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt::Context::instance(), SIGNAL(consoleKitDBChanged()),
this, SLOT(checkForResultChanged()));
m_cachedResults[action] = actionStatus(action);
}
|
+Priv
| 0
|
void PolicyKitBackend::setupAction(const QString &action)
{
connect(PolkitQt::Context::instance(), SIGNAL(configChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt::Context::instance(), SIGNAL(consoleKitDBChanged()),
this, SLOT(checkForResultChanged()));
m_cachedResults[action] = actionStatus(action);
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,724
|
Polkit1Backend::Polkit1Backend()
: AuthBackend()
, m_flyingActions(false)
{
setCapabilities(AuthorizeFromHelperCapability | CheckActionExistenceCapability | PreAuthActionCapability);
connect(PolkitQt1::Authority::instance(), SIGNAL(configChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt1::Authority::instance(), SIGNAL(consoleKitDBChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt1::Authority::instance(), SIGNAL(enumerateActionsFinished(PolkitQt1::ActionDescription::List)),
this, SLOT(updateCachedActions(PolkitQt1::ActionDescription::List)));
m_flyingActions = true;
PolkitQt1::Authority::instance()->enumerateActions();
}
|
+Priv
| 0
|
Polkit1Backend::Polkit1Backend()
: AuthBackend()
, m_flyingActions(false)
{
setCapabilities(AuthorizeFromHelperCapability | CheckActionExistenceCapability | PreAuthActionCapability);
connect(PolkitQt1::Authority::instance(), SIGNAL(configChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt1::Authority::instance(), SIGNAL(consoleKitDBChanged()),
this, SLOT(checkForResultChanged()));
connect(PolkitQt1::Authority::instance(), SIGNAL(enumerateActionsFinished(PolkitQt1::ActionDescription::List)),
this, SLOT(updateCachedActions(PolkitQt1::ActionDescription::List)));
m_flyingActions = true;
PolkitQt1::Authority::instance()->enumerateActions();
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,725
|
PolkitResultEventLoop::PolkitResultEventLoop(QObject *parent)
: QEventLoop(parent)
{
}
|
+Priv
| 0
|
PolkitResultEventLoop::PolkitResultEventLoop(QObject *parent)
: QEventLoop(parent)
{
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,726
|
bool Polkit1Backend::actionExists(const QString &action)
{
if (m_flyingActions) {
int tries = 0;
while (m_flyingActions && tries < 10) {
QEventLoop e;
QTimer::singleShot(200, &e, SLOT(quit()));
e.exec();
++tries;
}
}
return m_knownActions.contains(action);
}
|
+Priv
| 0
|
bool Polkit1Backend::actionExists(const QString &action)
{
if (m_flyingActions) {
int tries = 0;
while (m_flyingActions && tries < 10) {
QEventLoop e;
QTimer::singleShot(200, &e, SLOT(quit()));
e.exec();
++tries;
}
}
return m_knownActions.contains(action);
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,727
|
Action::AuthStatus Polkit1Backend::actionStatus(const QString &action)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID()));
PolkitQt1::Authority::Result r = PolkitQt1::Authority::instance()->checkAuthorizationSync(action, subject,
PolkitQt1::Authority::None);
switch (r) {
case PolkitQt1::Authority::Yes:
return Action::AuthorizedStatus;
case PolkitQt1::Authority::No:
case PolkitQt1::Authority::Unknown:
return Action::DeniedStatus;
default:
return Action::AuthRequiredStatus;
}
}
|
+Priv
| 0
|
Action::AuthStatus Polkit1Backend::actionStatus(const QString &action)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID()));
PolkitQt1::Authority::Result r = PolkitQt1::Authority::instance()->checkAuthorizationSync(action, subject,
PolkitQt1::Authority::None);
switch (r) {
case PolkitQt1::Authority::Yes:
return Action::AuthorizedStatus;
case PolkitQt1::Authority::No:
case PolkitQt1::Authority::Unknown:
return Action::DeniedStatus;
default:
return Action::AuthRequiredStatus;
}
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,728
|
Action::AuthStatus Polkit1Backend::authorizeAction(const QString &action)
{
Q_UNUSED(action)
return Action::AuthorizedStatus;
}
|
+Priv
| 0
|
Action::AuthStatus Polkit1Backend::authorizeAction(const QString &action)
{
Q_UNUSED(action)
return Action::AuthorizedStatus;
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,729
|
QByteArray Polkit1Backend::callerID() const
{
return QDBusConnection::systemBus().baseService().toUtf8();
}
|
+Priv
| 0
|
QByteArray Polkit1Backend::callerID() const
{
return QDBusConnection::systemBus().baseService().toUtf8();
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,730
|
void Polkit1Backend::checkForResultChanged()
{
Q_FOREACH (const QString &action, m_cachedResults.keys()) {
if (m_cachedResults[action] != actionStatus(action)) {
m_cachedResults[action] = actionStatus(action);
emit actionStatusChanged(action, m_cachedResults[action]);
}
}
PolkitQt1::Authority::instance()->enumerateActions();
m_flyingActions = true;
}
|
+Priv
| 0
|
void Polkit1Backend::checkForResultChanged()
{
Q_FOREACH (const QString &action, m_cachedResults.keys()) {
if (m_cachedResults[action] != actionStatus(action)) {
m_cachedResults[action] = actionStatus(action);
emit actionStatusChanged(action, m_cachedResults[action]);
}
}
PolkitQt1::Authority::instance()->enumerateActions();
m_flyingActions = true;
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,731
|
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
authority->checkAuthorization(action, subject, PolkitQt1::Authority::AllowUserInteraction);
e.exec();
switch (e.result()) {
case PolkitQt1::Authority::Yes:
return true;
default:
return false;
}
return false;
}
|
+Priv
| 0
|
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
authority->checkAuthorization(action, subject, PolkitQt1::Authority::AllowUserInteraction);
e.exec();
switch (e.result()) {
case PolkitQt1::Authority::Yes:
return true;
default:
return false;
}
return false;
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,732
|
void Polkit1Backend::preAuthAction(const QString &action, QWidget *parent)
{
if (!parent) {
qCDebug(KAUTH) << "Parent widget does not exist, skipping";
return;
}
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.polkit-kde-authentication-agent-1"))) {
if (qApp == 0 || !qobject_cast<QApplication *>(qApp)) {
qCDebug(KAUTH) << "Not streaming parent as we are on a TTY application";
}
qulonglong wId = parent->effectiveWinId();
QDBusMessage methodCall =
QDBusMessage::createMethodCall(QLatin1String("org.kde.polkit-kde-authentication-agent-1"), QLatin1String("/org/kde/Polkit1AuthAgent"), QLatin1String("org.kde.Polkit1AuthAgent"),
QLatin1String("setWIdForAction"));
methodCall << action;
methodCall << wId;
QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(methodCall);
call.waitForFinished();
if (call.isError()) {
qCWarning(KAUTH) << "ERROR while streaming the parent!!" << call.error();
}
} else {
qCDebug(KAUTH) << "KDE polkit agent appears too old or not registered on the bus";
}
}
|
+Priv
| 0
|
void Polkit1Backend::preAuthAction(const QString &action, QWidget *parent)
{
if (!parent) {
qCDebug(KAUTH) << "Parent widget does not exist, skipping";
return;
}
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.polkit-kde-authentication-agent-1"))) {
if (qApp == 0 || !qobject_cast<QApplication *>(qApp)) {
qCDebug(KAUTH) << "Not streaming parent as we are on a TTY application";
}
qulonglong wId = parent->effectiveWinId();
QDBusMessage methodCall =
QDBusMessage::createMethodCall(QLatin1String("org.kde.polkit-kde-authentication-agent-1"), QLatin1String("/org/kde/Polkit1AuthAgent"), QLatin1String("org.kde.Polkit1AuthAgent"),
QLatin1String("setWIdForAction"));
methodCall << action;
methodCall << wId;
QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(methodCall);
call.waitForFinished();
if (call.isError()) {
qCWarning(KAUTH) << "ERROR while streaming the parent!!" << call.error();
}
} else {
qCDebug(KAUTH) << "KDE polkit agent appears too old or not registered on the bus";
}
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,733
|
void PolkitResultEventLoop::requestQuit(const PolkitQt1::Authority::Result &result)
{
m_result = result;
quit();
}
|
+Priv
| 0
|
void PolkitResultEventLoop::requestQuit(const PolkitQt1::Authority::Result &result)
{
m_result = result;
quit();
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,734
|
PolkitQt1::Authority::Result PolkitResultEventLoop::result() const
{
return m_result;
}
|
+Priv
| 0
|
PolkitQt1::Authority::Result PolkitResultEventLoop::result() const
{
return m_result;
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,735
|
void Polkit1Backend::updateCachedActions(const PolkitQt1::ActionDescription::List &actions)
{
m_knownActions.clear();
Q_FOREACH (const PolkitQt1::ActionDescription &action, actions) {
m_knownActions << action.actionId();
}
m_flyingActions = false;
}
|
+Priv
| 0
|
void Polkit1Backend::updateCachedActions(const PolkitQt1::ActionDescription::List &actions)
{
m_knownActions.clear();
Q_FOREACH (const PolkitQt1::ActionDescription &action, actions) {
m_knownActions << action.actionId();
}
m_flyingActions = false;
}
|
@@ -162,6 +162,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,736
|
AuthBackend::AuthBackend()
: QObject(0)
, d(new Private)
{
}
|
+Priv
| 0
|
AuthBackend::AuthBackend()
: QObject(0)
, d(new Private)
{
}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString& action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,737
|
bool AuthBackend::actionExists(const QString& action)
{
Q_UNUSED(action);
Q_UNUSED(action)
Q_UNUSED(parent)
}
|
+Priv
| 0
|
bool AuthBackend::actionExists(const QString& action)
{
Q_UNUSED(action);
Q_UNUSED(action)
Q_UNUSED(parent)
}
|
@@ -54,6 +54,11 @@ void AuthBackend::setCapabilities(AuthBackend::Capabilities capabilities)
d->capabilities = capabilities;
}
+AuthBackend::ExtraCallerIDVerificationMethod AuthBackend::extraCallerIDVerificationMethod() const
+{
+ return NoExtraCallerIDVerificationMethod;
+}
+
bool AuthBackend::actionExists(const QString& action)
{
Q_UNUSED(action);
|
CWE-290
| null | null |
5,738
|
Action::AuthStatus DBusHelperProxy::authorizeAction(const QString& action, const QString& helperID)
{
if (!m_actionsInProgress.isEmpty()) {
return Action::Error;
}
QDBusConnection::systemBus().interface()->startService(helperID);
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("authorizeAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID();
message.setArguments(args);
m_actionsInProgress.push_back(action);
QEventLoop e;
QDBusPendingCall pendingCall = QDBusConnection::systemBus().asyncCall(message);
QDBusPendingCallWatcher watcher(pendingCall, this);
connect(&watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), &e, SLOT(quit()));
e.exec();
m_actionsInProgress.removeOne(action);
QDBusMessage reply = pendingCall.reply();
if (reply.type() == QDBusMessage::ErrorMessage || reply.arguments().size() != 1) {
return Action::Error;
}
return static_cast<Action::AuthStatus>(reply.arguments().first().toUInt());
}
|
+Priv
| 0
|
Action::AuthStatus DBusHelperProxy::authorizeAction(const QString& action, const QString& helperID)
{
if (!m_actionsInProgress.isEmpty()) {
return Action::Error;
}
QDBusConnection::systemBus().interface()->startService(helperID);
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("authorizeAction"));
QList<QVariant> args;
args << action << BackendsManager::authBackend()->callerID();
message.setArguments(args);
m_actionsInProgress.push_back(action);
QEventLoop e;
QDBusPendingCall pendingCall = QDBusConnection::systemBus().asyncCall(message);
QDBusPendingCallWatcher watcher(pendingCall, this);
connect(&watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), &e, SLOT(quit()));
e.exec();
m_actionsInProgress.removeOne(action);
QDBusMessage reply = pendingCall.reply();
if (reply.type() == QDBusMessage::ErrorMessage || reply.arguments().size() != 1) {
return Action::Error;
}
return static_cast<Action::AuthStatus>(reply.arguments().first().toUInt());
}
|
@@ -271,6 +271,29 @@ void DBusHelperProxy::performActions(QByteArray blob, const QByteArray &callerID
}
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -295,7 +318,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -338,7 +361,7 @@ uint DBusHelperProxy::authorizeAction(const QString& action, const QByteArray& c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::Authorized);
} else {
retVal = static_cast<uint>(Action::Denied);
|
CWE-290
| null | null |
5,739
|
bool DBusHelperProxy::executeActions(const QList<QPair<QString, QVariantMap> > &list, const QString &helperID)
{
QByteArray blob;
QDataStream stream(&blob, QIODevice::WriteOnly);
stream << list;
QDBusConnection::systemBus().interface()->startService(helperID);
if (!QDBusConnection::systemBus().connect(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("remoteSignal"), this, SLOT(remoteSignalReceived(int,QString,QByteArray)))) {
return false;
}
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performActions"));
QList<QVariant> args;
args << blob << BackendsManager::authBackend()->callerID();
message.setArguments(args);
QDBusPendingCall reply = QDBusConnection::systemBus().asyncCall(message); // This is a NO_REPLY method
if (reply.reply().type() == QDBusMessage::ErrorMessage) {
return false;
}
return true;
}
|
+Priv
| 0
|
bool DBusHelperProxy::executeActions(const QList<QPair<QString, QVariantMap> > &list, const QString &helperID)
{
QByteArray blob;
QDataStream stream(&blob, QIODevice::WriteOnly);
stream << list;
QDBusConnection::systemBus().interface()->startService(helperID);
if (!QDBusConnection::systemBus().connect(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("remoteSignal"), this, SLOT(remoteSignalReceived(int,QString,QByteArray)))) {
return false;
}
QDBusMessage message;
message = QDBusMessage::createMethodCall(helperID, QLatin1String("/"), QLatin1String("org.kde.auth"), QLatin1String("performActions"));
QList<QVariant> args;
args << blob << BackendsManager::authBackend()->callerID();
message.setArguments(args);
QDBusPendingCall reply = QDBusConnection::systemBus().asyncCall(message); // This is a NO_REPLY method
if (reply.reply().type() == QDBusMessage::ErrorMessage) {
return false;
}
return true;
}
|
@@ -271,6 +271,29 @@ void DBusHelperProxy::performActions(QByteArray blob, const QByteArray &callerID
}
}
+bool DBusHelperProxy::isCallerAuthorized(const QString &action, const QByteArray &callerID)
+{
+ // Check the caller is really who it says it is
+ switch (BackendsManager::authBackend()->extraCallerIDVerificationMethod()) {
+ case AuthBackend::NoExtraCallerIDVerificationMethod:
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServiceName:
+ if (message().service().toUtf8() != callerID) {
+ return false;
+ }
+ break;
+
+ case AuthBackend::VerifyAgainstDBusServicePid:
+ if (connection().interface()->servicePid(message().service()).value() != callerID.toUInt()) {
+ return false;
+ }
+ break;
+ }
+
+ return BackendsManager::authBackend()->isCallerAuthorized(action, callerID);
+}
+
QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArray &callerID, QByteArray arguments)
{
if (!responder) {
@@ -295,7 +318,7 @@ QByteArray DBusHelperProxy::performAction(const QString &action, const QByteArra
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
QString slotname = action;
if (slotname.startsWith(m_name + QLatin1Char('.'))) {
slotname = slotname.right(slotname.length() - m_name.length() - 1);
@@ -338,7 +361,7 @@ uint DBusHelperProxy::authorizeAction(const QString& action, const QByteArray& c
QTimer *timer = responder->property("__KAuth_Helper_Shutdown_Timer").value<QTimer*>();
timer->stop();
- if (BackendsManager::authBackend()->isCallerAuthorized(action, callerID)) {
+ if (isCallerAuthorized(action, callerID)) {
retVal = static_cast<uint>(Action::Authorized);
} else {
retVal = static_cast<uint>(Action::Denied);
|
CWE-290
| null | null |
5,740
|
Action::AuthStatus PolicyKitBackend::actionStatus(const QString &action)
{
PolkitQt::Auth::Result r = PolkitQt::Auth::isCallerAuthorized(action, QCoreApplication::applicationPid(),
false);
switch (r) {
case PolkitQt::Auth::Yes:
return Action::Authorized;
case PolkitQt::Auth::No:
case PolkitQt::Auth::Unknown:
return Action::Denied;
default:
return Action::AuthRequired;
}
}
|
+Priv
| 0
|
Action::AuthStatus PolicyKitBackend::actionStatus(const QString &action)
{
PolkitQt::Auth::Result r = PolkitQt::Auth::isCallerAuthorized(action, QCoreApplication::applicationPid(),
false);
switch (r) {
case PolkitQt::Auth::Yes:
return Action::Authorized;
case PolkitQt::Auth::No:
case PolkitQt::Auth::Unknown:
return Action::Denied;
default:
return Action::AuthRequired;
}
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,741
|
Action::AuthStatus PolicyKitBackend::authorizeAction(const QString &action)
{
switch (PolkitQt::Auth::computeAndObtainAuth(action)) {
case PolkitQt::Auth::Yes:
return Action::Authorized;
default:
return Action::Denied;
}
}
|
+Priv
| 0
|
Action::AuthStatus PolicyKitBackend::authorizeAction(const QString &action)
{
switch (PolkitQt::Auth::computeAndObtainAuth(action)) {
case PolkitQt::Auth::Yes:
return Action::Authorized;
default:
return Action::Denied;
}
}
|
@@ -78,6 +78,11 @@ QByteArray PolicyKitBackend::callerID() const
return a;
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServicePid;
+}
+
bool PolicyKitBackend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
QDataStream s(&callerID, QIODevice::ReadOnly);
|
CWE-290
| null | null |
5,742
|
PolkitResultEventLoop::PolkitResultEventLoop(QObject* parent)
: QEventLoop(parent)
{
}
|
+Priv
| 0
|
PolkitResultEventLoop::PolkitResultEventLoop(QObject* parent)
: QEventLoop(parent)
{
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,743
|
bool Polkit1Backend::actionExists(const QString& action)
{
if (m_flyingActions) {
int tries = 0;
while (m_flyingActions && tries < 10) {
QEventLoop e;
QTimer::singleShot(200, &e, SLOT(quit()));
e.exec();
++tries;
}
}
return m_knownActions.contains(action);
}
|
+Priv
| 0
|
bool Polkit1Backend::actionExists(const QString& action)
{
if (m_flyingActions) {
int tries = 0;
while (m_flyingActions && tries < 10) {
QEventLoop e;
QTimer::singleShot(200, &e, SLOT(quit()));
e.exec();
++tries;
}
}
return m_knownActions.contains(action);
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,744
|
Action::AuthStatus Polkit1Backend::actionStatus(const QString &action)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID()));
PolkitQt1::Authority::Result r = PolkitQt1::Authority::instance()->checkAuthorizationSync(action, subject,
PolkitQt1::Authority::None);
switch (r) {
case PolkitQt1::Authority::Yes:
return Action::Authorized;
case PolkitQt1::Authority::No:
case PolkitQt1::Authority::Unknown:
return Action::Denied;
default:
return Action::AuthRequired;
}
}
|
+Priv
| 0
|
Action::AuthStatus Polkit1Backend::actionStatus(const QString &action)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID()));
PolkitQt1::Authority::Result r = PolkitQt1::Authority::instance()->checkAuthorizationSync(action, subject,
PolkitQt1::Authority::None);
switch (r) {
case PolkitQt1::Authority::Yes:
return Action::Authorized;
case PolkitQt1::Authority::No:
case PolkitQt1::Authority::Unknown:
return Action::Denied;
default:
return Action::AuthRequired;
}
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,745
|
Action::AuthStatus Polkit1Backend::authorizeAction(const QString &action)
{
Q_UNUSED(action)
return Action::Authorized;
}
|
+Priv
| 0
|
Action::AuthStatus Polkit1Backend::authorizeAction(const QString &action)
{
Q_UNUSED(action)
return Action::Authorized;
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,746
|
QByteArray Polkit1Backend::callerID() const
{
return QDBusConnection::systemBus().baseService().toUtf8();
}
|
+Priv
| 0
|
QByteArray Polkit1Backend::callerID() const
{
return QDBusConnection::systemBus().baseService().toUtf8();
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,747
|
void Polkit1Backend::checkForResultChanged()
{
foreach(const QString &action, m_cachedResults.keys()) {
if (m_cachedResults[action] != actionStatus(action)) {
m_cachedResults[action] = actionStatus(action);
emit actionStatusChanged(action, m_cachedResults[action]);
}
}
PolkitQt1::Authority::instance()->enumerateActions();
m_flyingActions = true;
}
|
+Priv
| 0
|
void Polkit1Backend::checkForResultChanged()
{
foreach(const QString &action, m_cachedResults.keys()) {
if (m_cachedResults[action] != actionStatus(action)) {
m_cachedResults[action] = actionStatus(action);
emit actionStatusChanged(action, m_cachedResults[action]);
}
}
PolkitQt1::Authority::instance()->enumerateActions();
m_flyingActions = true;
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,748
|
void PolkitResultEventLoop::requestQuit(const PolkitQt1::Authority::Result& result)
{
m_result = result;
quit();
}
|
+Priv
| 0
|
void PolkitResultEventLoop::requestQuit(const PolkitQt1::Authority::Result& result)
{
m_result = result;
quit();
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,749
|
void Polkit1Backend::updateCachedActions(const PolkitQt1::ActionDescription::List& actions)
{
m_knownActions.clear();
foreach (const PolkitQt1::ActionDescription& action, actions) {
m_knownActions << action.actionId();
}
m_flyingActions = false;
}
|
+Priv
| 0
|
void Polkit1Backend::updateCachedActions(const PolkitQt1::ActionDescription::List& actions)
{
m_knownActions.clear();
foreach (const PolkitQt1::ActionDescription& action, actions) {
m_knownActions << action.actionId();
}
m_flyingActions = false;
}
|
@@ -163,6 +163,11 @@ QByteArray Polkit1Backend::callerID() const
return QDBusConnection::systemBus().baseService().toUtf8();
}
+AuthBackend::ExtraCallerIDVerificationMethod Polkit1Backend::extraCallerIDVerificationMethod() const
+{
+ return VerifyAgainstDBusServiceName;
+}
+
bool Polkit1Backend::isCallerAuthorized(const QString &action, QByteArray callerID)
{
PolkitQt1::SystemBusNameSubject subject(QString::fromUtf8(callerID));
|
CWE-290
| null | null |
5,750
|
static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
{
DIR *dir;
char dentry[sizeof(struct dirent) + MAXPATHLEN];
struct dirent *entry = (struct dirent *) &dentry;
struct stat sbuf;
char buf[MAXPATHLEN];
time_t now;
int nrdels = 0;
size_t dirname_len;
dir = opendir(dirname);
if (!dir) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)", dirname, strerror(errno), errno);
return (0);
}
time(&now);
return (nrdels);
}
| null | 0
|
static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
{
DIR *dir;
char dentry[sizeof(struct dirent) + MAXPATHLEN];
struct dirent *entry = (struct dirent *) &dentry;
struct stat sbuf;
char buf[MAXPATHLEN];
time_t now;
int nrdels = 0;
size_t dirname_len;
dir = opendir(dirname);
if (!dir) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ps_files_cleanup_dir: opendir(%s) failed: %s (%d)", dirname, strerror(errno), errno);
return (0);
}
time(&now);
return (nrdels);
}
|
@@ -61,40 +61,9 @@ typedef struct {
} ps_files;
ps_module ps_mod_files = {
- PS_MOD(files)
+ PS_MOD_SID(files)
};
-/* If you change the logic here, please also update the error message in
- * ps_files_open() appropriately */
-static int ps_files_valid_key(const char *key)
-{
- size_t len;
- const char *p;
- char c;
- int ret = 1;
-
- for (p = key; (c = *p); p++) {
- /* valid characters are a..z,A..Z,0..9 */
- if (!((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || (c >= '0' && c <= '9')
- || c == ','
- || c == '-')) {
- ret = 0;
- break;
- }
- }
-
- len = p - key;
-
- /* Somewhat arbitrary length limit here, but should be way more than
- anyone needs and avoids file-level warnings later on if we exceed MAX_PATH */
- if (len == 0 || len > 128) {
- ret = 0;
- }
-
- return ret;
-}
static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, const char *key)
{
@@ -155,11 +124,11 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
ps_files_close(data);
- if (!ps_files_valid_key(key)) {
+ if (php_session_valid_key(key) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,'");
- PS(invalid_session_id) = 1;
return;
}
+
if (!ps_files_path_create(buf, sizeof(buf), data, key)) {
return;
}
@@ -253,6 +222,21 @@ static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
return (nrdels);
}
+static int ps_files_key_exists(ps_files *data, const char *key TSRMLS_DC)
+{
+ char buf[MAXPATHLEN];
+ struct stat sbuf;
+
+ if (!key || !ps_files_path_create(buf, sizeof(buf), data, key)) {
+ return FAILURE;
+ }
+ if (VCWD_STAT(buf, &sbuf)) {
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+
+
#define PS_FILES_DATA ps_files *data = PS_GET_MOD_DATA()
PS_OPEN_FUNC(files)
@@ -342,6 +326,24 @@ PS_READ_FUNC(files)
struct stat sbuf;
PS_FILES_DATA;
+ /* If strict mode, check session id existence */
+ if (PS(use_strict_mode) &&
+ ps_files_key_exists(data, key TSRMLS_CC) == FAILURE) {
+ /* key points to PS(id), but cannot change here. */
+ if (key) {
+ efree(PS(id));
+ PS(id) = NULL;
+ }
+ PS(id) = PS(mod)->s_create_sid((void **)&data, NULL TSRMLS_CC);
+ if (!PS(id)) {
+ return FAILURE;
+ }
+ php_session_reset_id(TSRMLS_C);
+ if (PS(use_cookies)) {
+ PS(send_cookie) = 1;
+ }
+ }
+
ps_files_open(data, key TSRMLS_CC);
if (data->fd < 0) {
return FAILURE;
@@ -454,6 +456,17 @@ PS_GC_FUNC(files)
return SUCCESS;
}
+PS_CREATE_SID_FUNC(files)
+{
+ char *sid;
+ PS_FILES_DATA;
+
+ sid = php_session_create_id((void **)&data, newlen TSRMLS_CC);
+
+ return sid;
+}
+
+
/*
* Local variables:
* tab-width: 4
|
CWE-264
| null | null |
5,751
|
static inline php_uint32 ps_sd_hash(const char *data, int len)
{
php_uint32 h;
const char *e = data + len;
for (h = 2166136261U; data < e; ) {
h *= 16777619;
h ^= *data++;
}
return h;
}
| null | 0
|
static inline php_uint32 ps_sd_hash(const char *data, int len)
{
php_uint32 h;
const char *e = data + len;
for (h = 2166136261U; data < e; ) {
h *= 16777619;
h ^= *data++;
}
return h;
}
|
@@ -124,7 +124,7 @@ static ps_sd *ps_sd_new(ps_mm *data, const char *key)
if (!sd) {
TSRMLS_FETCH();
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "mm_malloc failed, avail %d, err %s", mm_available(data->mm), mm_error());
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "mm_malloc failed, avail %ld, err %s", mm_available(data->mm), mm_error());
return NULL;
}
@@ -208,8 +208,22 @@ static ps_sd *ps_sd_lookup(ps_mm *data, const char *key, int rw)
return ret;
}
+static int ps_mm_key_exists(ps_mm *data, const char *key TSRMLS_DC)
+{
+ ps_sd *sd;
+
+ if (!key) {
+ return FAILURE;
+ }
+ sd = ps_sd_lookup(data, key, 0);
+ if (sd) {
+ return SUCCESS;
+ }
+ return FAILURE;
+}
+
ps_module ps_mod_mm = {
- PS_MOD(mm)
+ PS_MOD_SID(mm)
};
#define PS_MM_DATA ps_mm *data = PS_GET_MOD_DATA()
@@ -341,6 +355,24 @@ PS_READ_FUNC(mm)
mm_lock(data->mm, MM_LOCK_RD);
+ /* If there is an ID and strict mode, verify existence */
+ if (PS(use_strict_mode)
+ && ps_mm_key_exists(data, key TSRMLS_CC) == FAILURE) {
+ /* key points to PS(id), but cannot change here. */
+ if (key) {
+ efree(PS(id));
+ PS(id) = NULL;
+ }
+ PS(id) = PS(mod)->s_create_sid((void **)&data, NULL TSRMLS_CC);
+ if (!PS(id)) {
+ return FAILURE;
+ }
+ php_session_reset_id(TSRMLS_C);
+ if (PS(use_cookies)) {
+ PS(send_cookie) = 1;
+ }
+ }
+
sd = ps_sd_lookup(data, key, 0);
if (sd) {
*vallen = sd->datalen;
@@ -444,6 +476,16 @@ PS_GC_FUNC(mm)
return SUCCESS;
}
+PS_CREATE_SID_FUNC(mm)
+{
+ char *sid;
+ PS_MM_DATA;
+
+ sid = php_session_create_id((void **)&data, newlen TSRMLS_CC);
+
+ return sid;
+}
+
#endif
/*
|
CWE-264
| null | null |
5,752
|
static inline void php_rshutdown_session_globals(TSRMLS_D) /* {{{ */
{
if (PS(http_session_vars)) {
zval_ptr_dtor(&PS(http_session_vars));
PS(http_session_vars) = NULL;
}
/* Do NOT destroy PS(mod_user_names) here! */
if (PS(mod_data) || PS(mod_user_implemented)) {
zend_try {
PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
} zend_end_try();
}
if (PS(id)) {
efree(PS(id));
}
}
/* }}} */
| null | 0
|
static inline void php_rshutdown_session_globals(TSRMLS_D) /* {{{ */
{
if (PS(http_session_vars)) {
zval_ptr_dtor(&PS(http_session_vars));
PS(http_session_vars) = NULL;
}
/* Do NOT destroy PS(mod_user_names) here! */
if (PS(mod_data) || PS(mod_user_implemented)) {
zend_try {
PS(mod)->s_close(&PS(mod_data) TSRMLS_CC);
} zend_end_try();
}
if (PS(id)) {
efree(PS(id));
}
}
/* }}} */
|
@@ -86,6 +86,8 @@ zend_class_entry *php_session_id_iface_entry;
return FAILURE; \
}
+static void php_session_send_cookie(TSRMLS_D);
+
/* Dispatched by RINIT and by php_session_destroy */
static inline void php_rinit_session_globals(TSRMLS_D) /* {{{ */
{
@@ -126,7 +128,7 @@ static int php_session_destroy(TSRMLS_D) /* {{{ */
return FAILURE;
}
- if (PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
+ if (PS(id) && PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
retval = FAILURE;
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object destruction failed");
}
@@ -428,17 +430,45 @@ PHPAPI char *php_session_create_id(PS_CREATE_SID_ARGS) /* {{{ */
}
/* }}} */
-static void php_session_initialize(TSRMLS_D) /* {{{ */
+/* Default session id char validation function allowed by ps_modules.
+ * If you change the logic here, please also update the error message in
+ * ps_modules appropriately */
+PHPAPI int php_session_valid_key(const char *key) /* {{{ */
{
- char *val;
- int vallen;
+ size_t len;
+ const char *p;
+ char c;
+ int ret = SUCCESS;
+
+ for (p = key; (c = *p); p++) {
+ /* valid characters are a..z,A..Z,0..9 */
+ if (!((c >= 'a' && c <= 'z')
+ || (c >= 'A' && c <= 'Z')
+ || (c >= '0' && c <= '9')
+ || c == ','
+ || c == '-')) {
+ ret = FAILURE;
+ break;
+ }
+ }
- /* check session name for invalid characters */
- if (PS(id) && strpbrk(PS(id), "\r\n\t <>'\"\\")) {
- efree(PS(id));
- PS(id) = NULL;
+ len = p - key;
+
+ /* Somewhat arbitrary length limit here, but should be way more than
+ anyone needs and avoids file-level warnings later on if we exceed MAX_PATH */
+ if (len == 0 || len > 128) {
+ ret = FAILURE;
}
+ return ret;
+}
+/* }}} */
+
+static void php_session_initialize(TSRMLS_D) /* {{{ */
+{
+ char *val = NULL;
+ int vallen;
+
if (!PS(mod)) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "No storage module chosen - failed to initialize session");
return;
@@ -452,28 +482,38 @@ static void php_session_initialize(TSRMLS_D) /* {{{ */
/* If there is no ID, use session module to create one */
if (!PS(id)) {
-new_session:
PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
+ if (!PS(id)) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failed to create session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path));
+ return;
+ }
if (PS(use_cookies)) {
PS(send_cookie) = 1;
}
}
+ php_session_reset_id(TSRMLS_C);
+ PS(session_status) = php_session_active;
+
/* Read data */
- /* Question: if you create a SID here, should you also try to read data?
- * I'm not sure, but while not doing so will remove one session operation
- * it could prove usefull for those sites which wish to have "default"
- * session information. */
php_session_track_init(TSRMLS_C);
- PS(invalid_session_id) = 0;
- if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == SUCCESS) {
+ if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, &vallen TSRMLS_CC) == FAILURE) {
+ /* Some broken save handler implementation returns FAILURE for non-existent session ID */
+ /* It's better to rase error for this, but disabled error for better compatibility */
+ /*
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Failed to read session data: %s (path: %s)", PS(mod)->s_name, PS(save_path));
+ */
+ }
+ if (val) {
php_session_decode(val, vallen TSRMLS_CC);
efree(val);
- } else if (PS(invalid_session_id)) { /* address instances where the session read fails due to an invalid id */
- PS(invalid_session_id) = 0;
- efree(PS(id));
- PS(id) = NULL;
- goto new_session;
+ }
+
+ if (!PS(use_cookies) && PS(send_cookie)) {
+ if (PS(use_trans_sid) && !PS(use_only_cookies)) {
+ PS(apply_trans_sid) = 1;
+ }
+ PS(send_cookie) = 0;
}
}
/* }}} */
@@ -748,6 +788,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("session.cookie_httponly", "", PHP_INI_ALL, OnUpdateBool, cookie_httponly, php_ps_globals, ps_globals)
STD_PHP_INI_BOOLEAN("session.use_cookies", "1", PHP_INI_ALL, OnUpdateBool, use_cookies, php_ps_globals, ps_globals)
STD_PHP_INI_BOOLEAN("session.use_only_cookies", "1", PHP_INI_ALL, OnUpdateBool, use_only_cookies, php_ps_globals, ps_globals)
+ STD_PHP_INI_BOOLEAN("session.use_strict_mode", "0", PHP_INI_ALL, OnUpdateBool, use_strict_mode, php_ps_globals, ps_globals)
STD_PHP_INI_ENTRY("session.referer_check", "", PHP_INI_ALL, OnUpdateString, extern_referer_chk, php_ps_globals, ps_globals)
#if HAVE_DEV_URANDOM
STD_PHP_INI_ENTRY("session.entropy_file", "/dev/urandom", PHP_INI_ALL, OnUpdateString, entropy_file, php_ps_globals, ps_globals)
@@ -1297,10 +1338,15 @@ PHPAPI const ps_serializer *_php_find_ps_serializer(char *name TSRMLS_DC) /* {{{
convert_to_string((*ppid)); \
PS(id) = estrndup(Z_STRVAL_PP(ppid), Z_STRLEN_PP(ppid))
-static void php_session_reset_id(TSRMLS_D) /* {{{ */
+PHPAPI void php_session_reset_id(TSRMLS_D) /* {{{ */
{
int module_number = PS(module_number);
+ if (!PS(id)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot set session ID - session ID is not initialized");
+ return;
+ }
+
if (PS(use_cookies) && PS(send_cookie)) {
php_session_send_cookie(TSRMLS_C);
PS(send_cookie) = 0;
@@ -1447,19 +1493,14 @@ PHPAPI void php_session_start(TSRMLS_D) /* {{{ */
}
}
- php_session_initialize(TSRMLS_C);
-
- if (!PS(use_cookies) && PS(send_cookie)) {
- if (PS(use_trans_sid) && !PS(use_only_cookies)) {
- PS(apply_trans_sid) = 1;
- }
- PS(send_cookie) = 0;
+ /* Finally check session id for dangarous characters
+ * Security note: session id may be embedded in HTML pages.*/
+ if (PS(id) && strpbrk(PS(id), "\r\n\t <>'\"\\")) {
+ efree(PS(id));
+ PS(id) = NULL;
}
- php_session_reset_id(TSRMLS_C);
-
- PS(session_status) = php_session_active;
-
+ php_session_initialize(TSRMLS_C);
php_session_cache_limiter(TSRMLS_C);
if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) {
@@ -1775,9 +1816,9 @@ static PHP_FUNCTION(session_save_path)
static PHP_FUNCTION(session_id)
{
char *name = NULL;
- int name_len;
+ int name_len, argc = ZEND_NUM_ARGS();
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "|s", &name, &name_len) == FAILURE) {
return;
}
@@ -1788,6 +1829,9 @@ static PHP_FUNCTION(session_id)
}
if (name) {
+ if (PS(use_strict_mode) && argc) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Set session ID while session.use_strict_mode is enabled");
+ }
if (PS(id)) {
efree(PS(id));
}
@@ -1822,11 +1866,13 @@ static PHP_FUNCTION(session_regenerate_id)
}
PS(id) = PS(mod)->s_create_sid(&PS(mod_data), NULL TSRMLS_CC);
-
- PS(send_cookie) = 1;
- php_session_reset_id(TSRMLS_C);
-
- RETURN_TRUE;
+ if (PS(id)) {
+ PS(send_cookie) = 1;
+ php_session_reset_id(TSRMLS_C);
+ RETURN_TRUE;
+ } else {
+ PS(id) = STR_EMPTY_ALLOC();
+ }
}
RETURN_FALSE;
}
|
CWE-264
| null | null |
5,753
|
PHP_FUNCTION(apache_child_terminate) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
if (fcgi_is_fastcgi()) {
fcgi_terminate();
}
}
/* }}} */
|
Exec Code Overflow +Info
| 0
|
PHP_FUNCTION(apache_child_terminate) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
if (fcgi_is_fastcgi()) {
fcgi_terminate();
}
}
/* }}} */
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,754
|
PHP_FUNCTION(apache_request_headers) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
array_init(return_value);
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
fcgi_loadenv(request, add_request_header, return_value TSRMLS_CC);
} else {
char buf[128];
char **env, *p, *q, *var, *val, *t = buf;
size_t alloc_size = sizeof(buf);
unsigned long var_len;
for (env = environ; env != NULL && *env != NULL; env++) {
val = strchr(*env, '=');
if (!val) { /* malformed entry? */
continue;
}
var_len = val - *env;
if (var_len >= alloc_size) {
alloc_size = var_len + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
var = *env;
if (var_len > 5 &&
var[0] == 'H' &&
var[1] == 'T' &&
var[2] == 'T' &&
var[3] == 'P' &&
var[4] == '_') {
var_len -= 5;
if (var_len >= alloc_size) {
alloc_size = var_len + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
p = var + 5;
var = q = t;
/* First char keep uppercase */
*q++ = *p++;
while (*p) {
if (*p == '=') {
/* End of name */
break;
} else if (*p == '_') {
*q++ = '-';
p++;
/* First char after - keep uppercase */
if (*p && *p!='=') {
*q++ = *p++;
}
} else if (*p >= 'A' && *p <= 'Z') {
/* lowercase */
*q++ = (*p++ - 'A' + 'a');
} else {
*q++ = *p++;
}
}
*q = 0;
} else if (var_len == sizeof("CONTENT_TYPE")-1 &&
memcmp(var, "CONTENT_TYPE", sizeof("CONTENT_TYPE")-1) == 0) {
var = "Content-Type";
} else if (var_len == sizeof("CONTENT_LENGTH")-1 &&
memcmp(var, "CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1) == 0) {
var = "Content-Length";
} else {
continue;
}
val++;
add_assoc_string_ex(return_value, var, var_len+1, val, 1);
}
if (t != buf && t != NULL) {
efree(t);
}
}
}
/* }}} */
|
Exec Code Overflow +Info
| 0
|
PHP_FUNCTION(apache_request_headers) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
array_init(return_value);
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
fcgi_loadenv(request, add_request_header, return_value TSRMLS_CC);
} else {
char buf[128];
char **env, *p, *q, *var, *val, *t = buf;
size_t alloc_size = sizeof(buf);
unsigned long var_len;
for (env = environ; env != NULL && *env != NULL; env++) {
val = strchr(*env, '=');
if (!val) { /* malformed entry? */
continue;
}
var_len = val - *env;
if (var_len >= alloc_size) {
alloc_size = var_len + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
var = *env;
if (var_len > 5 &&
var[0] == 'H' &&
var[1] == 'T' &&
var[2] == 'T' &&
var[3] == 'P' &&
var[4] == '_') {
var_len -= 5;
if (var_len >= alloc_size) {
alloc_size = var_len + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
p = var + 5;
var = q = t;
/* First char keep uppercase */
*q++ = *p++;
while (*p) {
if (*p == '=') {
/* End of name */
break;
} else if (*p == '_') {
*q++ = '-';
p++;
/* First char after - keep uppercase */
if (*p && *p!='=') {
*q++ = *p++;
}
} else if (*p >= 'A' && *p <= 'Z') {
/* lowercase */
*q++ = (*p++ - 'A' + 'a');
} else {
*q++ = *p++;
}
}
*q = 0;
} else if (var_len == sizeof("CONTENT_TYPE")-1 &&
memcmp(var, "CONTENT_TYPE", sizeof("CONTENT_TYPE")-1) == 0) {
var = "Content-Type";
} else if (var_len == sizeof("CONTENT_LENGTH")-1 &&
memcmp(var, "CONTENT_LENGTH", sizeof("CONTENT_LENGTH")-1) == 0) {
var = "Content-Length";
} else {
continue;
}
val++;
add_assoc_string_ex(return_value, var, var_len+1, val, 1);
}
if (t != buf && t != NULL) {
efree(t);
}
}
}
/* }}} */
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,755
|
PHP_FUNCTION(apache_response_headers) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
if (!&SG(sapi_headers).headers) {
RETURN_FALSE;
}
array_init(return_value);
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value TSRMLS_CC);
}
/* }}} */
|
Exec Code Overflow +Info
| 0
|
PHP_FUNCTION(apache_response_headers) /* {{{ */
{
if (ZEND_NUM_ARGS() > 0) {
WRONG_PARAM_COUNT;
}
if (!&SG(sapi_headers).headers) {
RETURN_FALSE;
}
array_init(return_value);
zend_llist_apply_with_argument(&SG(sapi_headers).headers, (llist_apply_with_arg_func_t)add_response_header, return_value TSRMLS_CC);
}
/* }}} */
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,756
|
static PHP_MINIT_FUNCTION(cgi)
{
#ifdef ZTS
ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL);
#else
php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC);
#endif
REGISTER_INI_ENTRIES();
return SUCCESS;
}
|
Exec Code Overflow +Info
| 0
|
static PHP_MINIT_FUNCTION(cgi)
{
#ifdef ZTS
ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL);
#else
php_cgi_globals_ctor(&php_cgi_globals TSRMLS_CC);
#endif
REGISTER_INI_ENTRIES();
return SUCCESS;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,757
|
static PHP_MSHUTDOWN_FUNCTION(cgi)
{
zend_hash_destroy(&CGIG(user_config_cache));
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
|
Exec Code Overflow +Info
| 0
|
static PHP_MSHUTDOWN_FUNCTION(cgi)
{
zend_hash_destroy(&CGIG(user_config_cache));
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,758
|
static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */
{
char *s, *p;
int len;
ALLOCA_FLAG(use_heap)
if (h->header_len > 0) {
p = strchr(h->header, ':');
len = p - h->header;
if (p && (len > 0)) {
while (len > 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) {
len--;
}
if (len) {
s = do_alloca(len + 1, use_heap);
memcpy(s, h->header, len);
s[len] = 0;
do {
p++;
} while (*p == ' ' || *p == '\t');
add_assoc_stringl_ex(return_value, s, len+1, p, h->header_len - (p - h->header), 1);
free_alloca(s, use_heap);
}
}
}
}
/* }}} */
|
Exec Code Overflow +Info
| 0
|
static void add_response_header(sapi_header_struct *h, zval *return_value TSRMLS_DC) /* {{{ */
{
char *s, *p;
int len;
ALLOCA_FLAG(use_heap)
if (h->header_len > 0) {
p = strchr(h->header, ':');
len = p - h->header;
if (p && (len > 0)) {
while (len > 0 && (h->header[len-1] == ' ' || h->header[len-1] == '\t')) {
len--;
}
if (len) {
s = do_alloca(len + 1, use_heap);
memcpy(s, h->header, len);
s[len] = 0;
do {
p++;
} while (*p == ' ' || *p == '\t');
add_assoc_stringl_ex(return_value, s, len+1, p, h->header_len - (p - h->header), 1);
free_alloca(s, use_heap);
}
}
}
}
/* }}} */
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,759
|
static void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
{
if (PG(http_globals)[TRACK_VARS_ENV] &&
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
}
/* call php's original import as a catch-all */
php_php_import_environment_variables(array_ptr TSRMLS_CC);
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
fcgi_loadenv(request, cgi_php_load_env_var, array_ptr TSRMLS_CC);
}
}
|
Exec Code Overflow +Info
| 0
|
static void cgi_php_import_environment_variables(zval *array_ptr TSRMLS_DC)
{
if (PG(http_globals)[TRACK_VARS_ENV] &&
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
}
/* call php's original import as a catch-all */
php_php_import_environment_variables(array_ptr TSRMLS_CC);
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
fcgi_loadenv(request, cgi_php_load_env_var, array_ptr TSRMLS_CC);
}
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,760
|
static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC)
{
return strcmp( ((zend_extension *)(*f)->data)->name,
((zend_extension *)(*s)->data)->name);
}
|
Exec Code Overflow +Info
| 0
|
static int extension_name_cmp(const zend_llist_element **f, const zend_llist_element **s TSRMLS_DC)
{
return strcmp( ((zend_extension *)(*f)->data)->name,
((zend_extension *)(*s)->data)->name);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,761
|
void fastcgi_cleanup(int signal)
{
#ifdef DEBUG_FASTCGI
fprintf(stderr, "FastCGI shutdown, pid %d\n", getpid());
#endif
sigaction(SIGTERM, &old_term, 0);
/* Kill all the processes in our process group */
kill(-pgroup, SIGTERM);
if (parent && parent_waiting) {
exit_signal = 1;
} else {
exit(0);
}
}
|
Exec Code Overflow +Info
| 0
|
void fastcgi_cleanup(int signal)
{
#ifdef DEBUG_FASTCGI
fprintf(stderr, "FastCGI shutdown, pid %d\n", getpid());
#endif
sigaction(SIGTERM, &old_term, 0);
/* Kill all the processes in our process group */
kill(-pgroup, SIGTERM);
if (parent && parent_waiting) {
exit_signal = 1;
} else {
exit(0);
}
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,762
|
static void init_request_info(fcgi_request *request TSRMLS_DC)
{
char *env_script_filename = CGI_GETENV("SCRIPT_FILENAME");
char *env_path_translated = CGI_GETENV("PATH_TRANSLATED");
char *script_path_translated = env_script_filename;
/* some broken servers do not have script_filename or argv0
* an example, IIS configured in some ways. then they do more
* broken stuff and set path_translated to the cgi script location */
if (!script_path_translated && env_path_translated) {
script_path_translated = env_path_translated;
}
/* initialize the defaults */
SG(request_info).path_translated = NULL;
SG(request_info).request_method = NULL;
SG(request_info).proto_num = 1000;
SG(request_info).query_string = NULL;
SG(request_info).request_uri = NULL;
SG(request_info).content_type = NULL;
SG(request_info).content_length = 0;
SG(sapi_headers).http_response_code = 200;
/* script_path_translated being set is a good indication that
* we are running in a cgi environment, since it is always
* null otherwise. otherwise, the filename
* of the script will be retreived later via argc/argv */
if (script_path_translated) {
const char *auth;
char *content_length = CGI_GETENV("CONTENT_LENGTH");
char *content_type = CGI_GETENV("CONTENT_TYPE");
char *env_path_info = CGI_GETENV("PATH_INFO");
char *env_script_name = CGI_GETENV("SCRIPT_NAME");
#ifdef PHP_WIN32
/* Hack for buggy IIS that sets incorrect PATH_INFO */
char *env_server_software = CGI_GETENV("SERVER_SOFTWARE");
if (env_server_software &&
env_script_name &&
env_path_info &&
strncmp(env_server_software, "Microsoft-IIS", sizeof("Microsoft-IIS")-1) == 0 &&
strncmp(env_path_info, env_script_name, strlen(env_script_name)) == 0
) {
env_path_info = CGI_PUTENV("ORIG_PATH_INFO", env_path_info);
env_path_info += strlen(env_script_name);
if (*env_path_info == 0) {
env_path_info = NULL;
}
env_path_info = CGI_PUTENV("PATH_INFO", env_path_info);
}
#endif
if (CGIG(fix_pathinfo)) {
struct stat st;
char *real_path = NULL;
char *env_redirect_url = CGI_GETENV("REDIRECT_URL");
char *env_document_root = CGI_GETENV("DOCUMENT_ROOT");
char *orig_path_translated = env_path_translated;
char *orig_path_info = env_path_info;
char *orig_script_name = env_script_name;
char *orig_script_filename = env_script_filename;
int script_path_translated_len;
if (!env_document_root && PG(doc_root)) {
env_document_root = CGI_PUTENV("DOCUMENT_ROOT", PG(doc_root));
/* fix docroot */
TRANSLATE_SLASHES(env_document_root);
}
if (env_path_translated != NULL && env_redirect_url != NULL &&
env_path_translated != script_path_translated &&
strcmp(env_path_translated, script_path_translated) != 0) {
/*
* pretty much apache specific. If we have a redirect_url
* then our script_filename and script_name point to the
* php executable
*/
script_path_translated = env_path_translated;
/* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
env_script_name = env_redirect_url;
}
#ifdef __riscos__
/* Convert path to unix format*/
__riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR;
script_path_translated = __unixify(script_path_translated, 0, NULL, 1, 0);
#endif
/*
* if the file doesn't exist, try to extract PATH_INFO out
* of it by stat'ing back through the '/'
* this fixes url's like /info.php/test
*/
if (script_path_translated &&
(script_path_translated_len = strlen(script_path_translated)) > 0 &&
(script_path_translated[script_path_translated_len-1] == '/' ||
#ifdef PHP_WIN32
script_path_translated[script_path_translated_len-1] == '\\' ||
#endif
(real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)
) {
char *pt = estrndup(script_path_translated, script_path_translated_len);
int len = script_path_translated_len;
char *ptr;
while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) {
*ptr = 0;
if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) {
/*
* okay, we found the base script!
* work out how many chars we had to strip off;
* then we can modify PATH_INFO
* accordingly
*
* we now have the makings of
* PATH_INFO=/test
* SCRIPT_FILENAME=/docroot/info.php
*
* we now need to figure out what docroot is.
* if DOCUMENT_ROOT is set, this is easy, otherwise,
* we have to play the game of hide and seek to figure
* out what SCRIPT_NAME should be
*/
int slen = len - strlen(pt);
int pilen = env_path_info ? strlen(env_path_info) : 0;
char *path_info = env_path_info ? env_path_info + pilen - slen : NULL;
if (orig_path_info != path_info) {
if (orig_path_info) {
char old;
CGI_PUTENV("ORIG_PATH_INFO", orig_path_info);
old = path_info[0];
path_info[0] = 0;
if (!orig_script_name ||
strcmp(orig_script_name, env_path_info) != 0) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_path_info);
} else {
SG(request_info).request_uri = orig_script_name;
}
path_info[0] = old;
}
env_path_info = CGI_PUTENV("PATH_INFO", path_info);
}
if (!orig_script_filename ||
strcmp(orig_script_filename, pt) != 0) {
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", pt);
}
TRANSLATE_SLASHES(pt);
/* figure out docroot
* SCRIPT_FILENAME minus SCRIPT_NAME
*/
if (env_document_root) {
int l = strlen(env_document_root);
int path_translated_len = 0;
char *path_translated = NULL;
if (l && env_document_root[l - 1] == '/') {
--l;
}
/* we have docroot, so we should have:
* DOCUMENT_ROOT=/docroot
* SCRIPT_FILENAME=/docroot/info.php
*/
/* PATH_TRANSLATED = DOCUMENT_ROOT + PATH_INFO */
path_translated_len = l + (env_path_info ? strlen(env_path_info) : 0);
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, env_document_root, l);
if (env_path_info) {
memcpy(path_translated + l, env_path_info, (path_translated_len - l));
}
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
}
env_path_translated = CGI_PUTENV("PATH_TRANSLATED", path_translated);
efree(path_translated);
} else if ( env_script_name &&
strstr(pt, env_script_name)
) {
/* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */
int ptlen = strlen(pt) - strlen(env_script_name);
int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0);
char *path_translated = NULL;
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, pt, ptlen);
if (env_path_info) {
memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
}
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
}
env_path_translated = CGI_PUTENV("PATH_TRANSLATED", path_translated);
efree(path_translated);
}
break;
}
}
if (!ptr) {
/*
* if we stripped out all the '/' and still didn't find
* a valid path... we will fail, badly. of course we would
* have failed anyway... we output 'no input file' now.
*/
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", NULL);
SG(sapi_headers).http_response_code = 404;
}
if (!SG(request_info).request_uri) {
if (!orig_script_name ||
strcmp(orig_script_name, env_script_name) != 0) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_script_name);
} else {
SG(request_info).request_uri = orig_script_name;
}
}
if (pt) {
efree(pt);
}
} else {
/* make sure path_info/translated are empty */
if (!orig_script_filename ||
(script_path_translated != orig_script_filename &&
strcmp(script_path_translated, orig_script_filename) != 0)) {
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", script_path_translated);
}
if (env_redirect_url) {
if (orig_path_info) {
CGI_PUTENV("ORIG_PATH_INFO", orig_path_info);
CGI_PUTENV("PATH_INFO", NULL);
}
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
CGI_PUTENV("PATH_TRANSLATED", NULL);
}
}
if (env_script_name != orig_script_name) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_script_name);
} else {
SG(request_info).request_uri = env_script_name;
}
free(real_path);
}
} else {
/* pre 4.3 behaviour, shouldn't be used but provides BC */
if (env_path_info) {
SG(request_info).request_uri = env_path_info;
} else {
SG(request_info).request_uri = env_script_name;
}
if (!CGIG(discard_path) && env_path_translated) {
script_path_translated = env_path_translated;
}
}
if (is_valid_path(script_path_translated)) {
SG(request_info).path_translated = estrdup(script_path_translated);
}
SG(request_info).request_method = CGI_GETENV("REQUEST_METHOD");
/* FIXME - Work out proto_num here */
SG(request_info).query_string = CGI_GETENV("QUERY_STRING");
SG(request_info).content_type = (content_type ? content_type : "" );
SG(request_info).content_length = (content_length ? atol(content_length) : 0);
/* The CGI RFC allows servers to pass on unvalidated Authorization data */
auth = CGI_GETENV("HTTP_AUTHORIZATION");
php_handle_auth_data(auth TSRMLS_CC);
}
}
|
Exec Code Overflow +Info
| 0
|
static void init_request_info(fcgi_request *request TSRMLS_DC)
{
char *env_script_filename = CGI_GETENV("SCRIPT_FILENAME");
char *env_path_translated = CGI_GETENV("PATH_TRANSLATED");
char *script_path_translated = env_script_filename;
/* some broken servers do not have script_filename or argv0
* an example, IIS configured in some ways. then they do more
* broken stuff and set path_translated to the cgi script location */
if (!script_path_translated && env_path_translated) {
script_path_translated = env_path_translated;
}
/* initialize the defaults */
SG(request_info).path_translated = NULL;
SG(request_info).request_method = NULL;
SG(request_info).proto_num = 1000;
SG(request_info).query_string = NULL;
SG(request_info).request_uri = NULL;
SG(request_info).content_type = NULL;
SG(request_info).content_length = 0;
SG(sapi_headers).http_response_code = 200;
/* script_path_translated being set is a good indication that
* we are running in a cgi environment, since it is always
* null otherwise. otherwise, the filename
* of the script will be retreived later via argc/argv */
if (script_path_translated) {
const char *auth;
char *content_length = CGI_GETENV("CONTENT_LENGTH");
char *content_type = CGI_GETENV("CONTENT_TYPE");
char *env_path_info = CGI_GETENV("PATH_INFO");
char *env_script_name = CGI_GETENV("SCRIPT_NAME");
#ifdef PHP_WIN32
/* Hack for buggy IIS that sets incorrect PATH_INFO */
char *env_server_software = CGI_GETENV("SERVER_SOFTWARE");
if (env_server_software &&
env_script_name &&
env_path_info &&
strncmp(env_server_software, "Microsoft-IIS", sizeof("Microsoft-IIS")-1) == 0 &&
strncmp(env_path_info, env_script_name, strlen(env_script_name)) == 0
) {
env_path_info = CGI_PUTENV("ORIG_PATH_INFO", env_path_info);
env_path_info += strlen(env_script_name);
if (*env_path_info == 0) {
env_path_info = NULL;
}
env_path_info = CGI_PUTENV("PATH_INFO", env_path_info);
}
#endif
if (CGIG(fix_pathinfo)) {
struct stat st;
char *real_path = NULL;
char *env_redirect_url = CGI_GETENV("REDIRECT_URL");
char *env_document_root = CGI_GETENV("DOCUMENT_ROOT");
char *orig_path_translated = env_path_translated;
char *orig_path_info = env_path_info;
char *orig_script_name = env_script_name;
char *orig_script_filename = env_script_filename;
int script_path_translated_len;
if (!env_document_root && PG(doc_root)) {
env_document_root = CGI_PUTENV("DOCUMENT_ROOT", PG(doc_root));
/* fix docroot */
TRANSLATE_SLASHES(env_document_root);
}
if (env_path_translated != NULL && env_redirect_url != NULL &&
env_path_translated != script_path_translated &&
strcmp(env_path_translated, script_path_translated) != 0) {
/*
* pretty much apache specific. If we have a redirect_url
* then our script_filename and script_name point to the
* php executable
*/
script_path_translated = env_path_translated;
/* we correct SCRIPT_NAME now in case we don't have PATH_INFO */
env_script_name = env_redirect_url;
}
#ifdef __riscos__
/* Convert path to unix format*/
__riscosify_control |= __RISCOSIFY_DONT_CHECK_DIR;
script_path_translated = __unixify(script_path_translated, 0, NULL, 1, 0);
#endif
/*
* if the file doesn't exist, try to extract PATH_INFO out
* of it by stat'ing back through the '/'
* this fixes url's like /info.php/test
*/
if (script_path_translated &&
(script_path_translated_len = strlen(script_path_translated)) > 0 &&
(script_path_translated[script_path_translated_len-1] == '/' ||
#ifdef PHP_WIN32
script_path_translated[script_path_translated_len-1] == '\\' ||
#endif
(real_path = tsrm_realpath(script_path_translated, NULL TSRMLS_CC)) == NULL)
) {
char *pt = estrndup(script_path_translated, script_path_translated_len);
int len = script_path_translated_len;
char *ptr;
while ((ptr = strrchr(pt, '/')) || (ptr = strrchr(pt, '\\'))) {
*ptr = 0;
if (stat(pt, &st) == 0 && S_ISREG(st.st_mode)) {
/*
* okay, we found the base script!
* work out how many chars we had to strip off;
* then we can modify PATH_INFO
* accordingly
*
* we now have the makings of
* PATH_INFO=/test
* SCRIPT_FILENAME=/docroot/info.php
*
* we now need to figure out what docroot is.
* if DOCUMENT_ROOT is set, this is easy, otherwise,
* we have to play the game of hide and seek to figure
* out what SCRIPT_NAME should be
*/
int slen = len - strlen(pt);
int pilen = env_path_info ? strlen(env_path_info) : 0;
char *path_info = env_path_info ? env_path_info + pilen - slen : NULL;
if (orig_path_info != path_info) {
if (orig_path_info) {
char old;
CGI_PUTENV("ORIG_PATH_INFO", orig_path_info);
old = path_info[0];
path_info[0] = 0;
if (!orig_script_name ||
strcmp(orig_script_name, env_path_info) != 0) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_path_info);
} else {
SG(request_info).request_uri = orig_script_name;
}
path_info[0] = old;
}
env_path_info = CGI_PUTENV("PATH_INFO", path_info);
}
if (!orig_script_filename ||
strcmp(orig_script_filename, pt) != 0) {
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", pt);
}
TRANSLATE_SLASHES(pt);
/* figure out docroot
* SCRIPT_FILENAME minus SCRIPT_NAME
*/
if (env_document_root) {
int l = strlen(env_document_root);
int path_translated_len = 0;
char *path_translated = NULL;
if (l && env_document_root[l - 1] == '/') {
--l;
}
/* we have docroot, so we should have:
* DOCUMENT_ROOT=/docroot
* SCRIPT_FILENAME=/docroot/info.php
*/
/* PATH_TRANSLATED = DOCUMENT_ROOT + PATH_INFO */
path_translated_len = l + (env_path_info ? strlen(env_path_info) : 0);
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, env_document_root, l);
if (env_path_info) {
memcpy(path_translated + l, env_path_info, (path_translated_len - l));
}
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
}
env_path_translated = CGI_PUTENV("PATH_TRANSLATED", path_translated);
efree(path_translated);
} else if ( env_script_name &&
strstr(pt, env_script_name)
) {
/* PATH_TRANSLATED = PATH_TRANSLATED - SCRIPT_NAME + PATH_INFO */
int ptlen = strlen(pt) - strlen(env_script_name);
int path_translated_len = ptlen + (env_path_info ? strlen(env_path_info) : 0);
char *path_translated = NULL;
path_translated = (char *) emalloc(path_translated_len + 1);
memcpy(path_translated, pt, ptlen);
if (env_path_info) {
memcpy(path_translated + ptlen, env_path_info, path_translated_len - ptlen);
}
path_translated[path_translated_len] = '\0';
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
}
env_path_translated = CGI_PUTENV("PATH_TRANSLATED", path_translated);
efree(path_translated);
}
break;
}
}
if (!ptr) {
/*
* if we stripped out all the '/' and still didn't find
* a valid path... we will fail, badly. of course we would
* have failed anyway... we output 'no input file' now.
*/
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", NULL);
SG(sapi_headers).http_response_code = 404;
}
if (!SG(request_info).request_uri) {
if (!orig_script_name ||
strcmp(orig_script_name, env_script_name) != 0) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_script_name);
} else {
SG(request_info).request_uri = orig_script_name;
}
}
if (pt) {
efree(pt);
}
} else {
/* make sure path_info/translated are empty */
if (!orig_script_filename ||
(script_path_translated != orig_script_filename &&
strcmp(script_path_translated, orig_script_filename) != 0)) {
if (orig_script_filename) {
CGI_PUTENV("ORIG_SCRIPT_FILENAME", orig_script_filename);
}
script_path_translated = CGI_PUTENV("SCRIPT_FILENAME", script_path_translated);
}
if (env_redirect_url) {
if (orig_path_info) {
CGI_PUTENV("ORIG_PATH_INFO", orig_path_info);
CGI_PUTENV("PATH_INFO", NULL);
}
if (orig_path_translated) {
CGI_PUTENV("ORIG_PATH_TRANSLATED", orig_path_translated);
CGI_PUTENV("PATH_TRANSLATED", NULL);
}
}
if (env_script_name != orig_script_name) {
if (orig_script_name) {
CGI_PUTENV("ORIG_SCRIPT_NAME", orig_script_name);
}
SG(request_info).request_uri = CGI_PUTENV("SCRIPT_NAME", env_script_name);
} else {
SG(request_info).request_uri = env_script_name;
}
free(real_path);
}
} else {
/* pre 4.3 behaviour, shouldn't be used but provides BC */
if (env_path_info) {
SG(request_info).request_uri = env_path_info;
} else {
SG(request_info).request_uri = env_script_name;
}
if (!CGIG(discard_path) && env_path_translated) {
script_path_translated = env_path_translated;
}
}
if (is_valid_path(script_path_translated)) {
SG(request_info).path_translated = estrdup(script_path_translated);
}
SG(request_info).request_method = CGI_GETENV("REQUEST_METHOD");
/* FIXME - Work out proto_num here */
SG(request_info).query_string = CGI_GETENV("QUERY_STRING");
SG(request_info).content_type = (content_type ? content_type : "" );
SG(request_info).content_length = (content_length ? atol(content_length) : 0);
/* The CGI RFC allows servers to pass on unvalidated Authorization data */
auth = CGI_GETENV("HTTP_AUTHORIZATION");
php_handle_auth_data(auth TSRMLS_CC);
}
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,763
|
static int is_valid_path(const char *path)
{
const char *p = path;
if (UNEXPECTED(!p)) {
return 0;
}
if (UNEXPECTED(*p == '.') && *(p+1) == '.' && (!*(p+2) || IS_SLASH(*(p+2)))) {
return 0;
}
while (*p) {
if (IS_SLASH(*p)) {
p++;
if (UNEXPECTED(*p == '.')) {
p++;
if (UNEXPECTED(*p == '.')) {
p++;
if (UNEXPECTED(!*p) || UNEXPECTED(IS_SLASH(*p))) {
return 0;
}
}
}
}
p++;
}
return 1;
}
|
Exec Code Overflow +Info
| 0
|
static int is_valid_path(const char *path)
{
const char *p = path;
if (UNEXPECTED(!p)) {
return 0;
}
if (UNEXPECTED(*p == '.') && *(p+1) == '.' && (!*(p+2) || IS_SLASH(*(p+2)))) {
return 0;
}
while (*p) {
if (IS_SLASH(*p)) {
p++;
if (UNEXPECTED(*p == '.')) {
p++;
if (UNEXPECTED(*p == '.')) {
p++;
if (UNEXPECTED(!*p) || UNEXPECTED(IS_SLASH(*p))) {
return 0;
}
}
}
}
p++;
}
return 1;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,764
|
static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC)
{
php_cgi_globals->rfc2616_headers = 0;
php_cgi_globals->nph = 0;
php_cgi_globals->check_shebang_line = 1;
php_cgi_globals->force_redirect = 1;
php_cgi_globals->redirect_status_env = NULL;
php_cgi_globals->fix_pathinfo = 1;
php_cgi_globals->discard_path = 0;
php_cgi_globals->fcgi_logging = 1;
#ifdef PHP_WIN32
php_cgi_globals->impersonate = 0;
#endif
zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, (dtor_func_t) user_config_cache_entry_dtor, 1);
}
|
Exec Code Overflow +Info
| 0
|
static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals TSRMLS_DC)
{
php_cgi_globals->rfc2616_headers = 0;
php_cgi_globals->nph = 0;
php_cgi_globals->check_shebang_line = 1;
php_cgi_globals->force_redirect = 1;
php_cgi_globals->redirect_status_env = NULL;
php_cgi_globals->fix_pathinfo = 1;
php_cgi_globals->discard_path = 0;
php_cgi_globals->fcgi_logging = 1;
#ifdef PHP_WIN32
php_cgi_globals->impersonate = 0;
#endif
zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, (dtor_func_t) user_config_cache_entry_dtor, 1);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,765
|
static int php_cgi_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
return FAILURE;
}
return SUCCESS;
}
|
Exec Code Overflow +Info
| 0
|
static int php_cgi_startup(sapi_module_struct *sapi_module)
{
if (php_module_startup(sapi_module, &cgi_module_entry, 1) == FAILURE) {
return FAILURE;
}
return SUCCESS;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,766
|
static void php_cgi_usage(char *argv0)
{
char *prog;
prog = strrchr(argv0, '/');
if (prog) {
prog++;
} else {
prog = "php";
}
php_printf( "Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
" %s <file> [args...]\n"
" -a Run interactively\n"
" -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
" -C Do not chdir to the script's directory\n"
" -c <path>|<file> Look for php.ini file in this directory\n"
" -n No php.ini file will be used\n"
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
" -e Generate extended information for debugger/profiler\n"
" -f <file> Parse <file>. Implies `-q'\n"
" -h This help\n"
" -i PHP information\n"
" -l Syntax check only (lint)\n"
" -m Show compiled in modules\n"
" -q Quiet-mode. Suppress HTTP Header output.\n"
" -s Display colour syntax highlighted source.\n"
" -v Version number\n"
" -w Display source with stripped comments and whitespace.\n"
" -z <file> Load Zend extension <file>.\n"
" -T <count> Measure execution time of script repeated <count> times.\n",
prog, prog);
}
|
Exec Code Overflow +Info
| 0
|
static void php_cgi_usage(char *argv0)
{
char *prog;
prog = strrchr(argv0, '/');
if (prog) {
prog++;
} else {
prog = "php";
}
php_printf( "Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
" %s <file> [args...]\n"
" -a Run interactively\n"
" -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
" -C Do not chdir to the script's directory\n"
" -c <path>|<file> Look for php.ini file in this directory\n"
" -n No php.ini file will be used\n"
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
" -e Generate extended information for debugger/profiler\n"
" -f <file> Parse <file>. Implies `-q'\n"
" -h This help\n"
" -i PHP information\n"
" -l Syntax check only (lint)\n"
" -m Show compiled in modules\n"
" -q Quiet-mode. Suppress HTTP Header output.\n"
" -s Display colour syntax highlighted source.\n"
" -v Version number\n"
" -w Display source with stripped comments and whitespace.\n"
" -z <file> Load Zend extension <file>.\n"
" -T <count> Measure execution time of script repeated <count> times.\n",
prog, prog);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,767
|
static void print_extensions(TSRMLS_D)
{
zend_llist sorted_exts;
zend_llist_copy(&sorted_exts, &zend_extensions);
sorted_exts.dtor = NULL;
zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC);
zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC);
zend_llist_destroy(&sorted_exts);
}
|
Exec Code Overflow +Info
| 0
|
static void print_extensions(TSRMLS_D)
{
zend_llist sorted_exts;
zend_llist_copy(&sorted_exts, &zend_extensions);
sorted_exts.dtor = NULL;
zend_llist_sort(&sorted_exts, extension_name_cmp TSRMLS_CC);
zend_llist_apply_with_argument(&sorted_exts, (llist_apply_with_arg_func_t) print_extension_info, NULL TSRMLS_CC);
zend_llist_destroy(&sorted_exts);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,768
|
static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
{
php_printf("%s\n", module->name);
return 0;
}
|
Exec Code Overflow +Info
| 0
|
static int print_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
{
php_printf("%s\n", module->name);
return 0;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,769
|
static void print_modules(TSRMLS_D)
{
HashTable sorted_registry;
zend_module_entry tmp;
zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC);
zend_hash_destroy(&sorted_registry);
}
|
Exec Code Overflow +Info
| 0
|
static void print_modules(TSRMLS_D)
{
HashTable sorted_registry;
zend_module_entry tmp;
zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry));
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) print_module_info, NULL TSRMLS_CC);
zend_hash_destroy(&sorted_registry);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,770
|
static int sapi_cgi_activate(TSRMLS_D)
{
char *path, *doc_root, *server_name;
uint path_len, doc_root_len, server_name_len;
/* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */
if (!SG(request_info).path_translated) {
return FAILURE;
}
if (php_ini_has_per_host_config()) {
/* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
server_name = FCGI_GETENV(request, "SERVER_NAME");
} else {
server_name = getenv("SERVER_NAME");
}
/* SERVER_NAME should also be defined at this stage..but better check it anyway */
if (server_name) {
server_name_len = strlen(server_name);
server_name = estrndup(server_name, server_name_len);
zend_str_tolower(server_name, server_name_len);
php_ini_activate_per_host_config(server_name, server_name_len + 1 TSRMLS_CC);
efree(server_name);
}
}
if (php_ini_has_per_dir_config() ||
(PG(user_ini_filename) && *PG(user_ini_filename))
) {
/* Prepare search path */
path_len = strlen(SG(request_info).path_translated);
/* Make sure we have trailing slash! */
if (!IS_SLASH(SG(request_info).path_translated[path_len])) {
path = emalloc(path_len + 2);
memcpy(path, SG(request_info).path_translated, path_len + 1);
path_len = zend_dirname(path, path_len);
path[path_len++] = DEFAULT_SLASH;
} else {
path = estrndup(SG(request_info).path_translated, path_len);
path_len = zend_dirname(path, path_len);
}
path[path_len] = 0;
/* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */
/* Load and activate user ini files in path starting from DOCUMENT_ROOT */
if (PG(user_ini_filename) && *PG(user_ini_filename)) {
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
doc_root = FCGI_GETENV(request, "DOCUMENT_ROOT");
} else {
doc_root = getenv("DOCUMENT_ROOT");
}
/* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
if (doc_root) {
doc_root_len = strlen(doc_root);
if (doc_root_len > 0 && IS_SLASH(doc_root[doc_root_len - 1])) {
--doc_root_len;
}
#ifdef PHP_WIN32
/* paths on windows should be case-insensitive */
doc_root = estrndup(doc_root, doc_root_len);
zend_str_tolower(doc_root, doc_root_len);
#endif
php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, doc_root_len - 1 TSRMLS_CC);
#ifdef PHP_WIN32
efree(doc_root);
#endif
}
}
efree(path);
}
return SUCCESS;
}
|
Exec Code Overflow +Info
| 0
|
static int sapi_cgi_activate(TSRMLS_D)
{
char *path, *doc_root, *server_name;
uint path_len, doc_root_len, server_name_len;
/* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */
if (!SG(request_info).path_translated) {
return FAILURE;
}
if (php_ini_has_per_host_config()) {
/* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
server_name = FCGI_GETENV(request, "SERVER_NAME");
} else {
server_name = getenv("SERVER_NAME");
}
/* SERVER_NAME should also be defined at this stage..but better check it anyway */
if (server_name) {
server_name_len = strlen(server_name);
server_name = estrndup(server_name, server_name_len);
zend_str_tolower(server_name, server_name_len);
php_ini_activate_per_host_config(server_name, server_name_len + 1 TSRMLS_CC);
efree(server_name);
}
}
if (php_ini_has_per_dir_config() ||
(PG(user_ini_filename) && *PG(user_ini_filename))
) {
/* Prepare search path */
path_len = strlen(SG(request_info).path_translated);
/* Make sure we have trailing slash! */
if (!IS_SLASH(SG(request_info).path_translated[path_len])) {
path = emalloc(path_len + 2);
memcpy(path, SG(request_info).path_translated, path_len + 1);
path_len = zend_dirname(path, path_len);
path[path_len++] = DEFAULT_SLASH;
} else {
path = estrndup(SG(request_info).path_translated, path_len);
path_len = zend_dirname(path, path_len);
}
path[path_len] = 0;
/* Activate per-dir-system-configuration defined in php.ini and stored into configuration_hash during startup */
php_ini_activate_per_dir_config(path, path_len TSRMLS_CC); /* Note: for global settings sake we check from root to path */
/* Load and activate user ini files in path starting from DOCUMENT_ROOT */
if (PG(user_ini_filename) && *PG(user_ini_filename)) {
if (fcgi_is_fastcgi()) {
fcgi_request *request = (fcgi_request*) SG(server_context);
doc_root = FCGI_GETENV(request, "DOCUMENT_ROOT");
} else {
doc_root = getenv("DOCUMENT_ROOT");
}
/* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
if (doc_root) {
doc_root_len = strlen(doc_root);
if (doc_root_len > 0 && IS_SLASH(doc_root[doc_root_len - 1])) {
--doc_root_len;
}
#ifdef PHP_WIN32
/* paths on windows should be case-insensitive */
doc_root = estrndup(doc_root, doc_root_len);
zend_str_tolower(doc_root, doc_root_len);
#endif
php_cgi_ini_activate_user_config(path, path_len, doc_root, doc_root_len, doc_root_len - 1 TSRMLS_CC);
#ifdef PHP_WIN32
efree(doc_root);
#endif
}
}
efree(path);
}
return SUCCESS;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,771
|
static void sapi_cgi_flush(void *server_context)
{
if (fflush(stdout) == EOF) {
php_handle_aborted_connection();
}
}
|
Exec Code Overflow +Info
| 0
|
static void sapi_cgi_flush(void *server_context)
{
if (fflush(stdout) == EOF) {
php_handle_aborted_connection();
}
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,772
|
static char *sapi_cgi_getenv(char *name, size_t name_len TSRMLS_DC)
{
return getenv(name);
}
|
Exec Code Overflow +Info
| 0
|
static char *sapi_cgi_getenv(char *name, size_t name_len TSRMLS_DC)
{
return getenv(name);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,773
|
static char *sapi_cgi_read_cookies(TSRMLS_D)
{
return getenv("HTTP_COOKIE");
}
|
Exec Code Overflow +Info
| 0
|
static char *sapi_cgi_read_cookies(TSRMLS_D)
{
return getenv("HTTP_COOKIE");
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,774
|
static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
{
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
sapi_header_struct *h;
zend_llist_position pos;
zend_bool ignore_status = 0;
int response_status = SG(sapi_headers).http_response_code;
if (SG(request_info).no_headers == 1) {
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
if (CGIG(nph) || SG(sapi_headers).http_response_code != 200)
{
int len;
zend_bool has_status = 0;
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
char *s;
len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, "%s\r\n", SG(sapi_headers).http_status_line);
if ((s = strchr(SG(sapi_headers).http_status_line, ' '))) {
response_status = atoi((s + 1));
}
if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
len = SAPI_CGI_MAX_HEADER_LENGTH;
}
} else {
char *s;
if (SG(sapi_headers).http_status_line &&
(s = strchr(SG(sapi_headers).http_status_line, ' ')) != 0 &&
(s - SG(sapi_headers).http_status_line) >= 5 &&
strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0
) {
len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
response_status = atoi((s + 1));
} else {
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
if (h->header_len > sizeof("Status:")-1 &&
strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0
) {
has_status = 1;
break;
}
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
}
if (!has_status) {
http_error *err = (http_error*)http_error_codes;
while (err->code != 0) {
if (err->code == SG(sapi_headers).http_response_code) {
break;
}
err++;
}
if (err->msg) {
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
} else {
len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
}
}
}
}
if (!has_status) {
PHPWRITE_H(buf, len);
ignore_status = 1;
}
}
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
/* prevent CRLFCRLF */
if (h->header_len) {
if (h->header_len > sizeof("Status:")-1 &&
strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0
) {
if (!ignore_status) {
ignore_status = 1;
PHPWRITE_H(h->header, h->header_len);
PHPWRITE_H("\r\n", 2);
}
} else if (response_status == 304 && h->header_len > sizeof("Content-Type:")-1 &&
strncasecmp(h->header, "Content-Type:", sizeof("Content-Type:")-1) == 0
) {
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
continue;
} else {
PHPWRITE_H(h->header, h->header_len);
PHPWRITE_H("\r\n", 2);
}
}
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
}
PHPWRITE_H("\r\n", 2);
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
|
Exec Code Overflow +Info
| 0
|
static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
{
char buf[SAPI_CGI_MAX_HEADER_LENGTH];
sapi_header_struct *h;
zend_llist_position pos;
zend_bool ignore_status = 0;
int response_status = SG(sapi_headers).http_response_code;
if (SG(request_info).no_headers == 1) {
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
if (CGIG(nph) || SG(sapi_headers).http_response_code != 200)
{
int len;
zend_bool has_status = 0;
if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
char *s;
len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, "%s\r\n", SG(sapi_headers).http_status_line);
if ((s = strchr(SG(sapi_headers).http_status_line, ' '))) {
response_status = atoi((s + 1));
}
if (len > SAPI_CGI_MAX_HEADER_LENGTH) {
len = SAPI_CGI_MAX_HEADER_LENGTH;
}
} else {
char *s;
if (SG(sapi_headers).http_status_line &&
(s = strchr(SG(sapi_headers).http_status_line, ' ')) != 0 &&
(s - SG(sapi_headers).http_status_line) >= 5 &&
strncasecmp(SG(sapi_headers).http_status_line, "HTTP/", 5) == 0
) {
len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
response_status = atoi((s + 1));
} else {
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
if (h->header_len > sizeof("Status:")-1 &&
strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0
) {
has_status = 1;
break;
}
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
}
if (!has_status) {
http_error *err = (http_error*)http_error_codes;
while (err->code != 0) {
if (err->code == SG(sapi_headers).http_response_code) {
break;
}
err++;
}
if (err->msg) {
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
} else {
len = slprintf(buf, sizeof(buf), "Status: %d\r\n", SG(sapi_headers).http_response_code);
}
}
}
}
if (!has_status) {
PHPWRITE_H(buf, len);
ignore_status = 1;
}
}
h = (sapi_header_struct*)zend_llist_get_first_ex(&sapi_headers->headers, &pos);
while (h) {
/* prevent CRLFCRLF */
if (h->header_len) {
if (h->header_len > sizeof("Status:")-1 &&
strncasecmp(h->header, "Status:", sizeof("Status:")-1) == 0
) {
if (!ignore_status) {
ignore_status = 1;
PHPWRITE_H(h->header, h->header_len);
PHPWRITE_H("\r\n", 2);
}
} else if (response_status == 304 && h->header_len > sizeof("Content-Type:")-1 &&
strncasecmp(h->header, "Content-Type:", sizeof("Content-Type:")-1) == 0
) {
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
continue;
} else {
PHPWRITE_H(h->header, h->header_len);
PHPWRITE_H("\r\n", 2);
}
}
h = (sapi_header_struct*)zend_llist_get_next_ex(&sapi_headers->headers, &pos);
}
PHPWRITE_H("\r\n", 2);
return SAPI_HEADER_SENT_SUCCESSFULLY;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,775
|
static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
const char *ptr = str;
uint remaining = str_length;
size_t ret;
while (remaining > 0) {
ret = sapi_cgi_single_write(ptr, remaining TSRMLS_CC);
if (!ret) {
php_handle_aborted_connection();
return str_length - remaining;
}
ptr += ret;
remaining -= ret;
}
return str_length;
}
|
Exec Code Overflow +Info
| 0
|
static int sapi_cgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
const char *ptr = str;
uint remaining = str_length;
size_t ret;
while (remaining > 0) {
ret = sapi_cgi_single_write(ptr, remaining TSRMLS_CC);
if (!ret) {
php_handle_aborted_connection();
return str_length - remaining;
}
ptr += ret;
remaining -= ret;
}
return str_length;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,776
|
static void sapi_fcgi_flush(void *server_context)
{
fcgi_request *request = (fcgi_request*) server_context;
if (
#ifndef PHP_WIN32
!parent &&
#endif
request && !fcgi_flush(request, 0)) {
php_handle_aborted_connection();
}
}
|
Exec Code Overflow +Info
| 0
|
static void sapi_fcgi_flush(void *server_context)
{
fcgi_request *request = (fcgi_request*) server_context;
if (
#ifndef PHP_WIN32
!parent &&
#endif
request && !fcgi_flush(request, 0)) {
php_handle_aborted_connection();
}
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,777
|
static char *sapi_fcgi_getenv(char *name, size_t name_len TSRMLS_DC)
{
/* when php is started by mod_fastcgi, no regular environment
* is provided to PHP. It is always sent to PHP at the start
* of a request. So we have to do our own lookup to get env
* vars. This could probably be faster somehow. */
fcgi_request *request = (fcgi_request*) SG(server_context);
char *ret = fcgi_getenv(request, name, name_len);
if (ret) return ret;
/* if cgi, or fastcgi and not found in fcgi env
check the regular environment */
return getenv(name);
}
|
Exec Code Overflow +Info
| 0
|
static char *sapi_fcgi_getenv(char *name, size_t name_len TSRMLS_DC)
{
/* when php is started by mod_fastcgi, no regular environment
* is provided to PHP. It is always sent to PHP at the start
* of a request. So we have to do our own lookup to get env
* vars. This could probably be faster somehow. */
fcgi_request *request = (fcgi_request*) SG(server_context);
char *ret = fcgi_getenv(request, name, name_len);
if (ret) return ret;
/* if cgi, or fastcgi and not found in fcgi env
check the regular environment */
return getenv(name);
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,778
|
static int sapi_fcgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
const char *ptr = str;
uint remaining = str_length;
fcgi_request *request = (fcgi_request*) SG(server_context);
while (remaining > 0) {
long ret = fcgi_write(request, FCGI_STDOUT, ptr, remaining);
if (ret <= 0) {
php_handle_aborted_connection();
return str_length - remaining;
}
ptr += ret;
remaining -= ret;
}
return str_length;
}
|
Exec Code Overflow +Info
| 0
|
static int sapi_fcgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
const char *ptr = str;
uint remaining = str_length;
fcgi_request *request = (fcgi_request*) SG(server_context);
while (remaining > 0) {
long ret = fcgi_write(request, FCGI_STDOUT, ptr, remaining);
if (ret <= 0) {
php_handle_aborted_connection();
return str_length - remaining;
}
ptr += ret;
remaining -= ret;
}
return str_length;
}
|
@@ -2429,14 +2429,17 @@ consult the installation file that came with this distribution, or visit \n\
int i = 1;
c = file_handle.handle.stream.mmap.buf[i++];
- while (c != '\n' && c != '\r' && c != EOF) {
+ while (c != '\n' && c != '\r' && i < file_handle.handle.stream.mmap.len) {
c = file_handle.handle.stream.mmap.buf[i++];
}
if (c == '\r') {
- if (file_handle.handle.stream.mmap.buf[i] == '\n') {
+ if (i < file_handle.handle.stream.mmap.len && file_handle.handle.stream.mmap.buf[i] == '\n') {
i++;
}
}
+ if(i > file_handle.handle.stream.mmap.len) {
+ i = file_handle.handle.stream.mmap.len;
+ }
file_handle.handle.stream.mmap.buf += i;
file_handle.handle.stream.mmap.len -= i;
}
|
CWE-119
| null | null |
5,779
|
hook_add_to_infolist (struct t_infolist *infolist, const char *arguments)
{
const char *pos_arguments;
char *type;
int i, type_int;
if (!infolist)
return 0;
type = NULL;
pos_arguments = NULL;
if (arguments && arguments[0])
{
pos_arguments = strchr (arguments, ',');
if (pos_arguments)
{
type = string_strndup (arguments, pos_arguments - arguments);
pos_arguments++;
}
else
type = strdup (arguments);
}
type_int = (type) ? hook_search_type (type) : -1;
for (i = 0; i < HOOK_NUM_TYPES; i++)
{
if ((type_int < 0) || (type_int == i))
hook_add_to_infolist_type (infolist, i, pos_arguments);
}
if (type)
free (type);
return 1;
}
|
Exec Code
| 0
|
hook_add_to_infolist (struct t_infolist *infolist, const char *arguments)
{
const char *pos_arguments;
char *type;
int i, type_int;
if (!infolist)
return 0;
type = NULL;
pos_arguments = NULL;
if (arguments && arguments[0])
{
pos_arguments = strchr (arguments, ',');
if (pos_arguments)
{
type = string_strndup (arguments, pos_arguments - arguments);
pos_arguments++;
}
else
type = strdup (arguments);
}
type_int = (type) ? hook_search_type (type) : -1;
for (i = 0; i < HOOK_NUM_TYPES; i++)
{
if ((type_int < 0) || (type_int == i))
hook_add_to_infolist_type (infolist, i, pos_arguments);
}
if (type)
free (type);
return 1;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,780
|
hook_add_to_infolist_type (struct t_infolist *infolist, int type,
const char *arguments)
{
struct t_hook *ptr_hook;
struct t_infolist_item *ptr_item;
char value[64];
int match;
for (ptr_hook = weechat_hooks[type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
match = 1;
if (arguments && !ptr_hook->deleted)
{
switch (ptr_hook->type)
{
case HOOK_TYPE_COMMAND:
match = string_match (HOOK_COMMAND(ptr_hook, command), arguments, 0);
break;
default:
break;
}
}
if (!match)
continue;
ptr_item = infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!infolist_new_var_pointer (ptr_item, "pointer", ptr_hook))
return 0;
if (!infolist_new_var_pointer (ptr_item, "plugin", ptr_hook->plugin))
return 0;
if (!infolist_new_var_string (ptr_item, "plugin_name",
(ptr_hook->plugin) ?
ptr_hook->plugin->name : NULL))
return 0;
if (!infolist_new_var_string (ptr_item, "subplugin", ptr_hook->subplugin))
return 0;
if (!infolist_new_var_string (ptr_item, "type", hook_type_string[ptr_hook->type]))
return 0;
if (!infolist_new_var_integer (ptr_item, "deleted", ptr_hook->deleted))
return 0;
if (!infolist_new_var_integer (ptr_item, "running", ptr_hook->running))
return 0;
if (!infolist_new_var_integer (ptr_item, "priority", ptr_hook->priority))
return 0;
switch (ptr_hook->type)
{
case HOOK_TYPE_COMMAND:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND(ptr_hook, command)))
return 0;
if (!infolist_new_var_string (ptr_item, "description",
HOOK_COMMAND(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_COMMAND(ptr_hook, description)
&& HOOK_COMMAND(ptr_hook, description)[0]) ?
_(HOOK_COMMAND(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args",
HOOK_COMMAND(ptr_hook, args)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_nls",
(HOOK_COMMAND(ptr_hook, args)
&& HOOK_COMMAND(ptr_hook, args)[0]) ?
_(HOOK_COMMAND(ptr_hook, args)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description",
HOOK_COMMAND(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_COMMAND(ptr_hook, args_description)
&& HOOK_COMMAND(ptr_hook, args_description)[0]) ?
_(HOOK_COMMAND(ptr_hook, args_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "completion", HOOK_COMMAND(ptr_hook, completion)))
return 0;
}
break;
case HOOK_TYPE_COMMAND_RUN:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND_RUN(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND_RUN(ptr_hook, command)))
return 0;
}
break;
case HOOK_TYPE_TIMER:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_TIMER(ptr_hook, callback)))
return 0;
snprintf (value, sizeof (value), "%ld", HOOK_TIMER(ptr_hook, interval));
if (!infolist_new_var_string (ptr_item, "interval", value))
return 0;
if (!infolist_new_var_integer (ptr_item, "align_second", HOOK_TIMER(ptr_hook, align_second)))
return 0;
if (!infolist_new_var_integer (ptr_item, "remaining_calls", HOOK_TIMER(ptr_hook, remaining_calls)))
return 0;
if (!infolist_new_var_buffer (ptr_item, "last_exec",
&(HOOK_TIMER(ptr_hook, last_exec)),
sizeof (HOOK_TIMER(ptr_hook, last_exec))))
return 0;
if (!infolist_new_var_buffer (ptr_item, "next_exec",
&(HOOK_TIMER(ptr_hook, next_exec)),
sizeof (HOOK_TIMER(ptr_hook, next_exec))))
return 0;
}
break;
case HOOK_TYPE_FD:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FD(ptr_hook, callback)))
return 0;
if (!infolist_new_var_integer (ptr_item, "fd", HOOK_FD(ptr_hook, fd)))
return 0;
if (!infolist_new_var_integer (ptr_item, "flags", HOOK_FD(ptr_hook, flags)))
return 0;
if (!infolist_new_var_integer (ptr_item, "error", HOOK_FD(ptr_hook, error)))
return 0;
}
break;
case HOOK_TYPE_PROCESS:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PROCESS(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_PROCESS(ptr_hook, command)))
return 0;
if (!infolist_new_var_string (ptr_item, "options", hashtable_get_string (HOOK_PROCESS(ptr_hook, options), "keys_values")))
return 0;
if (!infolist_new_var_integer (ptr_item, "timeout", HOOK_PROCESS(ptr_hook, timeout)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read_stdout", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write_stdout", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read_stderr", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write_stderr", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_PROCESS(ptr_hook, child_pid)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd_stdout", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd_stderr", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_timer", HOOK_PROCESS(ptr_hook, hook_timer)))
return 0;
}
break;
case HOOK_TYPE_CONNECT:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONNECT(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "address", HOOK_CONNECT(ptr_hook, address)))
return 0;
if (!infolist_new_var_integer (ptr_item, "port", HOOK_CONNECT(ptr_hook, port)))
return 0;
if (!infolist_new_var_integer (ptr_item, "sock", HOOK_CONNECT(ptr_hook, sock)))
return 0;
if (!infolist_new_var_integer (ptr_item, "ipv6", HOOK_CONNECT(ptr_hook, ipv6)))
return 0;
if (!infolist_new_var_integer (ptr_item, "retry", HOOK_CONNECT(ptr_hook, retry)))
return 0;
#ifdef HAVE_GNUTLS
if (!infolist_new_var_pointer (ptr_item, "gnutls_sess", HOOK_CONNECT(ptr_hook, gnutls_sess)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "gnutls_cb", HOOK_CONNECT(ptr_hook, gnutls_cb)))
return 0;
if (!infolist_new_var_integer (ptr_item, "gnutls_dhkey_size", HOOK_CONNECT(ptr_hook, gnutls_dhkey_size)))
return 0;
#endif
if (!infolist_new_var_string (ptr_item, "local_hostname", HOOK_CONNECT(ptr_hook, local_hostname)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read", HOOK_CONNECT(ptr_hook, child_read)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write", HOOK_CONNECT(ptr_hook, child_write)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_recv", HOOK_CONNECT(ptr_hook, child_recv)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_send", HOOK_CONNECT(ptr_hook, child_send)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_CONNECT(ptr_hook, child_pid)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_child_timer", HOOK_CONNECT(ptr_hook, hook_child_timer)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd", HOOK_CONNECT(ptr_hook, hook_fd)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "handshake_hook_fd", HOOK_CONNECT(ptr_hook, handshake_hook_fd)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "handshake_hook_timer", HOOK_CONNECT(ptr_hook, handshake_hook_timer)))
return 0;
if (!infolist_new_var_integer (ptr_item, "handshake_fd_flags", HOOK_CONNECT(ptr_hook, handshake_fd_flags)))
return 0;
if (!infolist_new_var_string (ptr_item, "handshake_ip_address", HOOK_CONNECT(ptr_hook, handshake_ip_address)))
return 0;
}
break;
case HOOK_TYPE_PRINT:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PRINT(ptr_hook, callback)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "buffer", HOOK_PRINT(ptr_hook, buffer)))
return 0;
if (!infolist_new_var_integer (ptr_item, "tags_count", HOOK_PRINT(ptr_hook, tags_count)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "tags_array", HOOK_PRINT(ptr_hook, tags_array)))
return 0;
if (!infolist_new_var_string (ptr_item, "message", HOOK_PRINT(ptr_hook, message)))
return 0;
if (!infolist_new_var_integer (ptr_item, "strip_colors", HOOK_PRINT(ptr_hook, strip_colors)))
return 0;
}
break;
case HOOK_TYPE_SIGNAL:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_SIGNAL(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "signal", HOOK_SIGNAL(ptr_hook, signal)))
return 0;
}
break;
case HOOK_TYPE_HSIGNAL:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HSIGNAL(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "signal", HOOK_HSIGNAL(ptr_hook, signal)))
return 0;
}
break;
case HOOK_TYPE_CONFIG:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONFIG(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "option", HOOK_CONFIG(ptr_hook, option)))
return 0;
}
break;
case HOOK_TYPE_COMPLETION:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMPLETION(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "completion_item", HOOK_COMPLETION(ptr_hook, completion_item)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_COMPLETION(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_COMPLETION(ptr_hook, description)
&& HOOK_COMPLETION(ptr_hook, description)[0]) ?
_(HOOK_COMPLETION(ptr_hook, description)) : ""))
return 0;
}
break;
case HOOK_TYPE_MODIFIER:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_MODIFIER(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "modifier", HOOK_MODIFIER(ptr_hook, modifier)))
return 0;
}
break;
case HOOK_TYPE_INFO:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO(ptr_hook, info_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFO(ptr_hook, description)
&& HOOK_INFO(ptr_hook, description)[0]) ?
_(HOOK_INFO(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFO(ptr_hook, args_description)
&& HOOK_INFO(ptr_hook, args_description)[0]) ?
_(HOOK_INFO(ptr_hook, args_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_INFO_HASHTABLE:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO_HASHTABLE(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO_HASHTABLE(ptr_hook, info_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO_HASHTABLE(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, description)
&& HOOK_INFO_HASHTABLE(ptr_hook, description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO_HASHTABLE(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, args_description)
&& HOOK_INFO_HASHTABLE(ptr_hook, args_description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, args_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "output_description", HOOK_INFO_HASHTABLE(ptr_hook, output_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "output_description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, output_description)
&& HOOK_INFO_HASHTABLE(ptr_hook, output_description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, output_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_INFOLIST:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFOLIST(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "infolist_name", HOOK_INFOLIST(ptr_hook, infolist_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFOLIST(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFOLIST(ptr_hook, description)
&& HOOK_INFOLIST(ptr_hook, description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "pointer_description", HOOK_INFOLIST(ptr_hook, pointer_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "pointer_description_nls",
(HOOK_INFOLIST(ptr_hook, pointer_description)
&& HOOK_INFOLIST(ptr_hook, pointer_description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, pointer_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFOLIST(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFOLIST(ptr_hook, args_description)
&& HOOK_INFOLIST(ptr_hook, args_description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, args_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_HDATA:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HDATA(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "hdata_name", HOOK_HDATA(ptr_hook, hdata_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_HDATA(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_HDATA(ptr_hook, description)
&& HOOK_HDATA(ptr_hook, description)[0]) ?
_(HOOK_HDATA(ptr_hook, description)) : ""))
return 0;
}
break;
case HOOK_TYPE_FOCUS:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FOCUS(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "area", HOOK_FOCUS(ptr_hook, area)))
return 0;
}
break;
case HOOK_NUM_TYPES:
/*
* this constant is used to count types only,
* it is never used as type
*/
break;
}
}
return 1;
}
|
Exec Code
| 0
|
hook_add_to_infolist_type (struct t_infolist *infolist, int type,
const char *arguments)
{
struct t_hook *ptr_hook;
struct t_infolist_item *ptr_item;
char value[64];
int match;
for (ptr_hook = weechat_hooks[type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
match = 1;
if (arguments && !ptr_hook->deleted)
{
switch (ptr_hook->type)
{
case HOOK_TYPE_COMMAND:
match = string_match (HOOK_COMMAND(ptr_hook, command), arguments, 0);
break;
default:
break;
}
}
if (!match)
continue;
ptr_item = infolist_new_item (infolist);
if (!ptr_item)
return 0;
if (!infolist_new_var_pointer (ptr_item, "pointer", ptr_hook))
return 0;
if (!infolist_new_var_pointer (ptr_item, "plugin", ptr_hook->plugin))
return 0;
if (!infolist_new_var_string (ptr_item, "plugin_name",
(ptr_hook->plugin) ?
ptr_hook->plugin->name : NULL))
return 0;
if (!infolist_new_var_string (ptr_item, "subplugin", ptr_hook->subplugin))
return 0;
if (!infolist_new_var_string (ptr_item, "type", hook_type_string[ptr_hook->type]))
return 0;
if (!infolist_new_var_integer (ptr_item, "deleted", ptr_hook->deleted))
return 0;
if (!infolist_new_var_integer (ptr_item, "running", ptr_hook->running))
return 0;
if (!infolist_new_var_integer (ptr_item, "priority", ptr_hook->priority))
return 0;
switch (ptr_hook->type)
{
case HOOK_TYPE_COMMAND:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND(ptr_hook, command)))
return 0;
if (!infolist_new_var_string (ptr_item, "description",
HOOK_COMMAND(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_COMMAND(ptr_hook, description)
&& HOOK_COMMAND(ptr_hook, description)[0]) ?
_(HOOK_COMMAND(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args",
HOOK_COMMAND(ptr_hook, args)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_nls",
(HOOK_COMMAND(ptr_hook, args)
&& HOOK_COMMAND(ptr_hook, args)[0]) ?
_(HOOK_COMMAND(ptr_hook, args)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description",
HOOK_COMMAND(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_COMMAND(ptr_hook, args_description)
&& HOOK_COMMAND(ptr_hook, args_description)[0]) ?
_(HOOK_COMMAND(ptr_hook, args_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "completion", HOOK_COMMAND(ptr_hook, completion)))
return 0;
}
break;
case HOOK_TYPE_COMMAND_RUN:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMMAND_RUN(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_COMMAND_RUN(ptr_hook, command)))
return 0;
}
break;
case HOOK_TYPE_TIMER:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_TIMER(ptr_hook, callback)))
return 0;
snprintf (value, sizeof (value), "%ld", HOOK_TIMER(ptr_hook, interval));
if (!infolist_new_var_string (ptr_item, "interval", value))
return 0;
if (!infolist_new_var_integer (ptr_item, "align_second", HOOK_TIMER(ptr_hook, align_second)))
return 0;
if (!infolist_new_var_integer (ptr_item, "remaining_calls", HOOK_TIMER(ptr_hook, remaining_calls)))
return 0;
if (!infolist_new_var_buffer (ptr_item, "last_exec",
&(HOOK_TIMER(ptr_hook, last_exec)),
sizeof (HOOK_TIMER(ptr_hook, last_exec))))
return 0;
if (!infolist_new_var_buffer (ptr_item, "next_exec",
&(HOOK_TIMER(ptr_hook, next_exec)),
sizeof (HOOK_TIMER(ptr_hook, next_exec))))
return 0;
}
break;
case HOOK_TYPE_FD:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FD(ptr_hook, callback)))
return 0;
if (!infolist_new_var_integer (ptr_item, "fd", HOOK_FD(ptr_hook, fd)))
return 0;
if (!infolist_new_var_integer (ptr_item, "flags", HOOK_FD(ptr_hook, flags)))
return 0;
if (!infolist_new_var_integer (ptr_item, "error", HOOK_FD(ptr_hook, error)))
return 0;
}
break;
case HOOK_TYPE_PROCESS:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PROCESS(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "command", HOOK_PROCESS(ptr_hook, command)))
return 0;
if (!infolist_new_var_string (ptr_item, "options", hashtable_get_string (HOOK_PROCESS(ptr_hook, options), "keys_values")))
return 0;
if (!infolist_new_var_integer (ptr_item, "timeout", HOOK_PROCESS(ptr_hook, timeout)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read_stdout", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write_stdout", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read_stderr", HOOK_PROCESS(ptr_hook, child_read[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write_stderr", HOOK_PROCESS(ptr_hook, child_write[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_PROCESS(ptr_hook, child_pid)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd_stdout", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDOUT])))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd_stderr", HOOK_PROCESS(ptr_hook, hook_fd[HOOK_PROCESS_STDERR])))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_timer", HOOK_PROCESS(ptr_hook, hook_timer)))
return 0;
}
break;
case HOOK_TYPE_CONNECT:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONNECT(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "address", HOOK_CONNECT(ptr_hook, address)))
return 0;
if (!infolist_new_var_integer (ptr_item, "port", HOOK_CONNECT(ptr_hook, port)))
return 0;
if (!infolist_new_var_integer (ptr_item, "sock", HOOK_CONNECT(ptr_hook, sock)))
return 0;
if (!infolist_new_var_integer (ptr_item, "ipv6", HOOK_CONNECT(ptr_hook, ipv6)))
return 0;
if (!infolist_new_var_integer (ptr_item, "retry", HOOK_CONNECT(ptr_hook, retry)))
return 0;
#ifdef HAVE_GNUTLS
if (!infolist_new_var_pointer (ptr_item, "gnutls_sess", HOOK_CONNECT(ptr_hook, gnutls_sess)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "gnutls_cb", HOOK_CONNECT(ptr_hook, gnutls_cb)))
return 0;
if (!infolist_new_var_integer (ptr_item, "gnutls_dhkey_size", HOOK_CONNECT(ptr_hook, gnutls_dhkey_size)))
return 0;
#endif
if (!infolist_new_var_string (ptr_item, "local_hostname", HOOK_CONNECT(ptr_hook, local_hostname)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_read", HOOK_CONNECT(ptr_hook, child_read)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_write", HOOK_CONNECT(ptr_hook, child_write)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_recv", HOOK_CONNECT(ptr_hook, child_recv)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_send", HOOK_CONNECT(ptr_hook, child_send)))
return 0;
if (!infolist_new_var_integer (ptr_item, "child_pid", HOOK_CONNECT(ptr_hook, child_pid)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_child_timer", HOOK_CONNECT(ptr_hook, hook_child_timer)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "hook_fd", HOOK_CONNECT(ptr_hook, hook_fd)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "handshake_hook_fd", HOOK_CONNECT(ptr_hook, handshake_hook_fd)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "handshake_hook_timer", HOOK_CONNECT(ptr_hook, handshake_hook_timer)))
return 0;
if (!infolist_new_var_integer (ptr_item, "handshake_fd_flags", HOOK_CONNECT(ptr_hook, handshake_fd_flags)))
return 0;
if (!infolist_new_var_string (ptr_item, "handshake_ip_address", HOOK_CONNECT(ptr_hook, handshake_ip_address)))
return 0;
}
break;
case HOOK_TYPE_PRINT:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_PRINT(ptr_hook, callback)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "buffer", HOOK_PRINT(ptr_hook, buffer)))
return 0;
if (!infolist_new_var_integer (ptr_item, "tags_count", HOOK_PRINT(ptr_hook, tags_count)))
return 0;
if (!infolist_new_var_pointer (ptr_item, "tags_array", HOOK_PRINT(ptr_hook, tags_array)))
return 0;
if (!infolist_new_var_string (ptr_item, "message", HOOK_PRINT(ptr_hook, message)))
return 0;
if (!infolist_new_var_integer (ptr_item, "strip_colors", HOOK_PRINT(ptr_hook, strip_colors)))
return 0;
}
break;
case HOOK_TYPE_SIGNAL:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_SIGNAL(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "signal", HOOK_SIGNAL(ptr_hook, signal)))
return 0;
}
break;
case HOOK_TYPE_HSIGNAL:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HSIGNAL(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "signal", HOOK_HSIGNAL(ptr_hook, signal)))
return 0;
}
break;
case HOOK_TYPE_CONFIG:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_CONFIG(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "option", HOOK_CONFIG(ptr_hook, option)))
return 0;
}
break;
case HOOK_TYPE_COMPLETION:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_COMPLETION(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "completion_item", HOOK_COMPLETION(ptr_hook, completion_item)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_COMPLETION(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_COMPLETION(ptr_hook, description)
&& HOOK_COMPLETION(ptr_hook, description)[0]) ?
_(HOOK_COMPLETION(ptr_hook, description)) : ""))
return 0;
}
break;
case HOOK_TYPE_MODIFIER:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_MODIFIER(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "modifier", HOOK_MODIFIER(ptr_hook, modifier)))
return 0;
}
break;
case HOOK_TYPE_INFO:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO(ptr_hook, info_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFO(ptr_hook, description)
&& HOOK_INFO(ptr_hook, description)[0]) ?
_(HOOK_INFO(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFO(ptr_hook, args_description)
&& HOOK_INFO(ptr_hook, args_description)[0]) ?
_(HOOK_INFO(ptr_hook, args_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_INFO_HASHTABLE:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO_HASHTABLE(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO_HASHTABLE(ptr_hook, info_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO_HASHTABLE(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, description)
&& HOOK_INFO_HASHTABLE(ptr_hook, description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO_HASHTABLE(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, args_description)
&& HOOK_INFO_HASHTABLE(ptr_hook, args_description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, args_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "output_description", HOOK_INFO_HASHTABLE(ptr_hook, output_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "output_description_nls",
(HOOK_INFO_HASHTABLE(ptr_hook, output_description)
&& HOOK_INFO_HASHTABLE(ptr_hook, output_description)[0]) ?
_(HOOK_INFO_HASHTABLE(ptr_hook, output_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_INFOLIST:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFOLIST(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "infolist_name", HOOK_INFOLIST(ptr_hook, infolist_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_INFOLIST(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_INFOLIST(ptr_hook, description)
&& HOOK_INFOLIST(ptr_hook, description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "pointer_description", HOOK_INFOLIST(ptr_hook, pointer_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "pointer_description_nls",
(HOOK_INFOLIST(ptr_hook, pointer_description)
&& HOOK_INFOLIST(ptr_hook, pointer_description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, pointer_description)) : ""))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFOLIST(ptr_hook, args_description)))
return 0;
if (!infolist_new_var_string (ptr_item, "args_description_nls",
(HOOK_INFOLIST(ptr_hook, args_description)
&& HOOK_INFOLIST(ptr_hook, args_description)[0]) ?
_(HOOK_INFOLIST(ptr_hook, args_description)) : ""))
return 0;
}
break;
case HOOK_TYPE_HDATA:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HDATA(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "hdata_name", HOOK_HDATA(ptr_hook, hdata_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_HDATA(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_HDATA(ptr_hook, description)
&& HOOK_HDATA(ptr_hook, description)[0]) ?
_(HOOK_HDATA(ptr_hook, description)) : ""))
return 0;
}
break;
case HOOK_TYPE_FOCUS:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_FOCUS(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "area", HOOK_FOCUS(ptr_hook, area)))
return 0;
}
break;
case HOOK_NUM_TYPES:
/*
* this constant is used to count types only,
* it is never used as type
*/
break;
}
}
return 1;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,781
|
hook_command (struct t_weechat_plugin *plugin, const char *command,
const char *description,
const char *args, const char *args_description,
const char *completion,
t_hook_callback_command *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command *new_hook_command;
int priority;
const char *ptr_command;
if (!callback)
return NULL;
if (hook_search_command (plugin, command))
{
gui_chat_printf (NULL,
_("%sError: another command \"%s\" already exists "
"for plugin \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
command,
plugin_get_name (plugin));
return NULL;
}
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_command = malloc (sizeof (*new_hook_command));
if (!new_hook_command)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority,
callback_data);
new_hook->hook_data = new_hook_command;
new_hook_command->callback = callback;
new_hook_command->command = strdup ((ptr_command) ? ptr_command :
((command) ? command : ""));
new_hook_command->description = strdup ((description) ? description : "");
new_hook_command->args = strdup ((args) ? args : "");
new_hook_command->args_description = strdup ((args_description) ?
args_description : "");
new_hook_command->completion = strdup ((completion) ? completion : "");
/* build completion variables for command */
new_hook_command->cplt_num_templates = 0;
new_hook_command->cplt_templates = NULL;
new_hook_command->cplt_templates_static = NULL;
new_hook_command->cplt_template_num_args = NULL;
new_hook_command->cplt_template_args = NULL;
new_hook_command->cplt_template_num_args_concat = 0;
new_hook_command->cplt_template_args_concat = NULL;
hook_command_build_completion (new_hook_command);
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_command (struct t_weechat_plugin *plugin, const char *command,
const char *description,
const char *args, const char *args_description,
const char *completion,
t_hook_callback_command *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command *new_hook_command;
int priority;
const char *ptr_command;
if (!callback)
return NULL;
if (hook_search_command (plugin, command))
{
gui_chat_printf (NULL,
_("%sError: another command \"%s\" already exists "
"for plugin \"%s\""),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
command,
plugin_get_name (plugin));
return NULL;
}
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_command = malloc (sizeof (*new_hook_command));
if (!new_hook_command)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority,
callback_data);
new_hook->hook_data = new_hook_command;
new_hook_command->callback = callback;
new_hook_command->command = strdup ((ptr_command) ? ptr_command :
((command) ? command : ""));
new_hook_command->description = strdup ((description) ? description : "");
new_hook_command->args = strdup ((args) ? args : "");
new_hook_command->args_description = strdup ((args_description) ?
args_description : "");
new_hook_command->completion = strdup ((completion) ? completion : "");
/* build completion variables for command */
new_hook_command->cplt_num_templates = 0;
new_hook_command->cplt_templates = NULL;
new_hook_command->cplt_templates_static = NULL;
new_hook_command->cplt_template_num_args = NULL;
new_hook_command->cplt_template_args = NULL;
new_hook_command->cplt_template_num_args_concat = 0;
new_hook_command->cplt_template_args_concat = NULL;
hook_command_build_completion (new_hook_command);
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,782
|
hook_command_build_completion (struct t_hook_command *hook_command)
{
int i, j, k, length, num_items;
struct t_weelist *list;
char *pos_completion, *pos_double_pipe, *pos_start, *pos_end;
char **items, *last_space, *ptr_template;
/* split templates using "||" as separator */
hook_command->cplt_num_templates = 1;
pos_completion = hook_command->completion;
while ((pos_double_pipe = strstr (pos_completion, "||")) != NULL)
{
hook_command->cplt_num_templates++;
pos_completion = pos_double_pipe + 2;
}
hook_command->cplt_templates = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_templates));
for (i = 0; i < hook_command->cplt_num_templates; i++)
{
hook_command->cplt_templates[i] = NULL;
}
pos_completion = hook_command->completion;
i = 0;
while (pos_completion)
{
pos_double_pipe = strstr (pos_completion, "||");
if (!pos_double_pipe)
pos_double_pipe = pos_completion + strlen (pos_completion);
pos_start = pos_completion;
pos_end = pos_double_pipe - 1;
if (pos_end < pos_start)
{
hook_command->cplt_templates[i] = strdup ("");
}
else
{
while (pos_start[0] == ' ')
{
pos_start++;
}
pos_end = pos_double_pipe - 1;
while ((pos_end > pos_start) && (pos_end[0] == ' '))
{
pos_end--;
}
hook_command->cplt_templates[i] = string_strndup (pos_start,
pos_end - pos_start + 1);
}
i++;
if (!pos_double_pipe[0])
pos_completion = NULL;
else
pos_completion = pos_double_pipe + 2;
}
/* for each template, split/count args */
hook_command->cplt_templates_static = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_templates_static));
hook_command->cplt_template_num_args = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_template_num_args));
hook_command->cplt_template_args = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_template_args));
hook_command->cplt_template_num_args_concat = 0;
for (i = 0; i < hook_command->cplt_num_templates; i++)
{
/*
* build static part of template: it's first argument(s) which does not
* contain "%" or "|"
*/
last_space = NULL;
ptr_template = hook_command->cplt_templates[i];
while (ptr_template && ptr_template[0])
{
if (ptr_template[0] == ' ')
{
last_space = ptr_template;
break;
}
else if ((ptr_template[0] == '%') || (ptr_template[0] == '|'))
break;
ptr_template = utf8_next_char (ptr_template);
}
if (last_space)
{
last_space--;
while (last_space > hook_command->cplt_templates[i])
{
if (last_space[0] != ' ')
break;
}
if (last_space < hook_command->cplt_templates[i])
last_space = NULL;
else
last_space++;
}
if (last_space)
hook_command->cplt_templates_static[i] = string_strndup (hook_command->cplt_templates[i],
last_space - hook_command->cplt_templates[i]);
else
hook_command->cplt_templates_static[i] = strdup (hook_command->cplt_templates[i]);
/* build arguments for each template */
hook_command->cplt_template_args[i] = string_split (hook_command->cplt_templates[i],
" ", 0, 0,
&(hook_command->cplt_template_num_args[i]));
if (hook_command->cplt_template_num_args[i] > hook_command->cplt_template_num_args_concat)
hook_command->cplt_template_num_args_concat = hook_command->cplt_template_num_args[i];
}
/*
* build strings with concatentaion of items from different templates
* for each argument: these strings will be used when completing argument
* if we can't find which template to use (for example for first argument)
*/
if (hook_command->cplt_template_num_args_concat == 0)
hook_command->cplt_template_args_concat = NULL;
else
{
hook_command->cplt_template_args_concat = malloc (hook_command->cplt_template_num_args_concat *
sizeof (*hook_command->cplt_template_args_concat));
list = weelist_new ();
for (i = 0; i < hook_command->cplt_template_num_args_concat; i++)
{
/* first compute length */
length = 1;
for (j = 0; j < hook_command->cplt_num_templates; j++)
{
if (i < hook_command->cplt_template_num_args[j])
length += strlen (hook_command->cplt_template_args[j][i]) + 1;
}
/* alloc memory */
hook_command->cplt_template_args_concat[i] = malloc (length);
if (hook_command->cplt_template_args_concat[i])
{
/* concatene items with "|" as separator */
weelist_remove_all (list);
hook_command->cplt_template_args_concat[i][0] = '\0';
for (j = 0; j < hook_command->cplt_num_templates; j++)
{
if (i < hook_command->cplt_template_num_args[j])
{
items = string_split (hook_command->cplt_template_args[j][i],
"|", 0, 0, &num_items);
for (k = 0; k < num_items; k++)
{
if (!weelist_search (list, items[k]))
{
if (hook_command->cplt_template_args_concat[i][0])
strcat (hook_command->cplt_template_args_concat[i], "|");
strcat (hook_command->cplt_template_args_concat[i],
items[k]);
weelist_add (list, items[k], WEECHAT_LIST_POS_END,
NULL);
}
}
string_free_split (items);
}
}
}
}
weelist_free (list);
}
}
|
Exec Code
| 0
|
hook_command_build_completion (struct t_hook_command *hook_command)
{
int i, j, k, length, num_items;
struct t_weelist *list;
char *pos_completion, *pos_double_pipe, *pos_start, *pos_end;
char **items, *last_space, *ptr_template;
/* split templates using "||" as separator */
hook_command->cplt_num_templates = 1;
pos_completion = hook_command->completion;
while ((pos_double_pipe = strstr (pos_completion, "||")) != NULL)
{
hook_command->cplt_num_templates++;
pos_completion = pos_double_pipe + 2;
}
hook_command->cplt_templates = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_templates));
for (i = 0; i < hook_command->cplt_num_templates; i++)
{
hook_command->cplt_templates[i] = NULL;
}
pos_completion = hook_command->completion;
i = 0;
while (pos_completion)
{
pos_double_pipe = strstr (pos_completion, "||");
if (!pos_double_pipe)
pos_double_pipe = pos_completion + strlen (pos_completion);
pos_start = pos_completion;
pos_end = pos_double_pipe - 1;
if (pos_end < pos_start)
{
hook_command->cplt_templates[i] = strdup ("");
}
else
{
while (pos_start[0] == ' ')
{
pos_start++;
}
pos_end = pos_double_pipe - 1;
while ((pos_end > pos_start) && (pos_end[0] == ' '))
{
pos_end--;
}
hook_command->cplt_templates[i] = string_strndup (pos_start,
pos_end - pos_start + 1);
}
i++;
if (!pos_double_pipe[0])
pos_completion = NULL;
else
pos_completion = pos_double_pipe + 2;
}
/* for each template, split/count args */
hook_command->cplt_templates_static = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_templates_static));
hook_command->cplt_template_num_args = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_template_num_args));
hook_command->cplt_template_args = malloc (hook_command->cplt_num_templates *
sizeof (*hook_command->cplt_template_args));
hook_command->cplt_template_num_args_concat = 0;
for (i = 0; i < hook_command->cplt_num_templates; i++)
{
/*
* build static part of template: it's first argument(s) which does not
* contain "%" or "|"
*/
last_space = NULL;
ptr_template = hook_command->cplt_templates[i];
while (ptr_template && ptr_template[0])
{
if (ptr_template[0] == ' ')
{
last_space = ptr_template;
break;
}
else if ((ptr_template[0] == '%') || (ptr_template[0] == '|'))
break;
ptr_template = utf8_next_char (ptr_template);
}
if (last_space)
{
last_space--;
while (last_space > hook_command->cplt_templates[i])
{
if (last_space[0] != ' ')
break;
}
if (last_space < hook_command->cplt_templates[i])
last_space = NULL;
else
last_space++;
}
if (last_space)
hook_command->cplt_templates_static[i] = string_strndup (hook_command->cplt_templates[i],
last_space - hook_command->cplt_templates[i]);
else
hook_command->cplt_templates_static[i] = strdup (hook_command->cplt_templates[i]);
/* build arguments for each template */
hook_command->cplt_template_args[i] = string_split (hook_command->cplt_templates[i],
" ", 0, 0,
&(hook_command->cplt_template_num_args[i]));
if (hook_command->cplt_template_num_args[i] > hook_command->cplt_template_num_args_concat)
hook_command->cplt_template_num_args_concat = hook_command->cplt_template_num_args[i];
}
/*
* build strings with concatentaion of items from different templates
* for each argument: these strings will be used when completing argument
* if we can't find which template to use (for example for first argument)
*/
if (hook_command->cplt_template_num_args_concat == 0)
hook_command->cplt_template_args_concat = NULL;
else
{
hook_command->cplt_template_args_concat = malloc (hook_command->cplt_template_num_args_concat *
sizeof (*hook_command->cplt_template_args_concat));
list = weelist_new ();
for (i = 0; i < hook_command->cplt_template_num_args_concat; i++)
{
/* first compute length */
length = 1;
for (j = 0; j < hook_command->cplt_num_templates; j++)
{
if (i < hook_command->cplt_template_num_args[j])
length += strlen (hook_command->cplt_template_args[j][i]) + 1;
}
/* alloc memory */
hook_command->cplt_template_args_concat[i] = malloc (length);
if (hook_command->cplt_template_args_concat[i])
{
/* concatene items with "|" as separator */
weelist_remove_all (list);
hook_command->cplt_template_args_concat[i][0] = '\0';
for (j = 0; j < hook_command->cplt_num_templates; j++)
{
if (i < hook_command->cplt_template_num_args[j])
{
items = string_split (hook_command->cplt_template_args[j][i],
"|", 0, 0, &num_items);
for (k = 0; k < num_items; k++)
{
if (!weelist_search (list, items[k]))
{
if (hook_command->cplt_template_args_concat[i][0])
strcat (hook_command->cplt_template_args_concat[i], "|");
strcat (hook_command->cplt_template_args_concat[i],
items[k]);
weelist_add (list, items[k], WEECHAT_LIST_POS_END,
NULL);
}
}
string_free_split (items);
}
}
}
}
weelist_free (list);
}
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,783
|
hook_command_run (struct t_weechat_plugin *plugin, const char *command,
t_hook_callback_command_run *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command_run *new_hook_command_run;
int priority;
const char *ptr_command;
if (!callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_command_run = malloc (sizeof (*new_hook_command_run));
if (!new_hook_command_run)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority,
callback_data);
new_hook->hook_data = new_hook_command_run;
new_hook_command_run->callback = callback;
new_hook_command_run->command = strdup ((ptr_command) ? ptr_command :
((command) ? command : ""));
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_command_run (struct t_weechat_plugin *plugin, const char *command,
t_hook_callback_command_run *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_command_run *new_hook_command_run;
int priority;
const char *ptr_command;
if (!callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_command_run = malloc (sizeof (*new_hook_command_run));
if (!new_hook_command_run)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (command, &priority, &ptr_command);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority,
callback_data);
new_hook->hook_data = new_hook_command_run;
new_hook_command_run->callback = callback;
new_hook_command_run->command = strdup ((ptr_command) ? ptr_command :
((command) ? command : ""));
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,784
|
hook_completion (struct t_weechat_plugin *plugin, const char *completion_item,
const char *description,
t_hook_callback_completion *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_completion *new_hook_completion;
int priority;
const char *ptr_completion_item;
if (!completion_item || !completion_item[0]
|| strchr (completion_item, ' ') || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_completion = malloc (sizeof (*new_hook_completion));
if (!new_hook_completion)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority,
callback_data);
new_hook->hook_data = new_hook_completion;
new_hook_completion->callback = callback;
new_hook_completion->completion_item = strdup ((ptr_completion_item) ?
ptr_completion_item : completion_item);
new_hook_completion->description = strdup ((description) ?
description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_completion (struct t_weechat_plugin *plugin, const char *completion_item,
const char *description,
t_hook_callback_completion *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_completion *new_hook_completion;
int priority;
const char *ptr_completion_item;
if (!completion_item || !completion_item[0]
|| strchr (completion_item, ' ') || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_completion = malloc (sizeof (*new_hook_completion));
if (!new_hook_completion)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item);
hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority,
callback_data);
new_hook->hook_data = new_hook_completion;
new_hook_completion->callback = callback;
new_hook_completion->completion_item = strdup ((ptr_completion_item) ?
ptr_completion_item : completion_item);
new_hook_completion->description = strdup ((description) ?
description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,785
|
hook_completion_exec (struct t_weechat_plugin *plugin,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_hook *ptr_hook, *next_hook;
/* make C compiler happy */
(void) plugin;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_COMPLETION(ptr_hook, completion_item),
completion_item) == 0))
{
ptr_hook->running = 1;
(void) (HOOK_COMPLETION(ptr_hook, callback))
(ptr_hook->callback_data, completion_item, buffer, completion);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
Exec Code
| 0
|
hook_completion_exec (struct t_weechat_plugin *plugin,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
struct t_hook *ptr_hook, *next_hook;
/* make C compiler happy */
(void) plugin;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_COMPLETION(ptr_hook, completion_item),
completion_item) == 0))
{
ptr_hook->running = 1;
(void) (HOOK_COMPLETION(ptr_hook, callback))
(ptr_hook->callback_data, completion_item, buffer, completion);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,786
|
hook_config (struct t_weechat_plugin *plugin, const char *option,
t_hook_callback_config *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_config *new_hook_config;
int priority;
const char *ptr_option;
if (!callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_config = malloc (sizeof (*new_hook_config));
if (!new_hook_config)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (option, &priority, &ptr_option);
hook_init_data (new_hook, plugin, HOOK_TYPE_CONFIG, priority,
callback_data);
new_hook->hook_data = new_hook_config;
new_hook_config->callback = callback;
new_hook_config->option = strdup ((ptr_option) ? ptr_option :
((option) ? option : ""));
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_config (struct t_weechat_plugin *plugin, const char *option,
t_hook_callback_config *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_config *new_hook_config;
int priority;
const char *ptr_option;
if (!callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_config = malloc (sizeof (*new_hook_config));
if (!new_hook_config)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (option, &priority, &ptr_option);
hook_init_data (new_hook, plugin, HOOK_TYPE_CONFIG, priority,
callback_data);
new_hook->hook_data = new_hook_config;
new_hook_config->callback = callback;
new_hook_config->option = strdup ((ptr_option) ? ptr_option :
((option) ? option : ""));
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,787
|
hook_config_exec (const char *option, const char *value)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (!HOOK_CONFIG(ptr_hook, option)
|| (string_match (option, HOOK_CONFIG(ptr_hook, option), 0))))
{
ptr_hook->running = 1;
(void) (HOOK_CONFIG(ptr_hook, callback))
(ptr_hook->callback_data, option, value);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
Exec Code
| 0
|
hook_config_exec (const char *option, const char *value)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (!HOOK_CONFIG(ptr_hook, option)
|| (string_match (option, HOOK_CONFIG(ptr_hook, option), 0))))
{
ptr_hook->running = 1;
(void) (HOOK_CONFIG(ptr_hook, callback))
(ptr_hook->callback_data, option, value);
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,788
|
hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session)
{
struct t_hook *ptr_hook;
int rc;
rc = -1;
ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT];
while (ptr_hook)
{
/* looking for the right hook using to the gnutls session pointer */
if (!ptr_hook->deleted
&& HOOK_CONNECT(ptr_hook, gnutls_sess)
&& (*(HOOK_CONNECT(ptr_hook, gnutls_sess)) == tls_session))
{
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
(ptr_hook->callback_data, tls_session, NULL, 0,
NULL, 0, NULL,
WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT);
break;
}
ptr_hook = ptr_hook->next_hook;
}
return rc;
}
|
Exec Code
| 0
|
hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session)
{
struct t_hook *ptr_hook;
int rc;
rc = -1;
ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT];
while (ptr_hook)
{
/* looking for the right hook using to the gnutls session pointer */
if (!ptr_hook->deleted
&& HOOK_CONNECT(ptr_hook, gnutls_sess)
&& (*(HOOK_CONNECT(ptr_hook, gnutls_sess)) == tls_session))
{
rc = (int) (HOOK_CONNECT(ptr_hook, gnutls_cb))
(ptr_hook->callback_data, tls_session, NULL, 0,
NULL, 0, NULL,
WEECHAT_HOOK_CONNECT_GNUTLS_CB_VERIFY_CERT);
break;
}
ptr_hook = ptr_hook->next_hook;
}
return rc;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,789
|
hook_exec_end ()
{
if (hook_exec_recursion > 0)
hook_exec_recursion--;
if (hook_exec_recursion == 0)
hook_remove_deleted ();
}
|
Exec Code
| 0
|
hook_exec_end ()
{
if (hook_exec_recursion > 0)
hook_exec_recursion--;
if (hook_exec_recursion == 0)
hook_remove_deleted ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,790
|
hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
int flag_write, int flag_exception,
t_hook_callback_fd *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_fd *new_hook_fd;
if ((fd < 0) || hook_search_fd (fd) || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_fd = malloc (sizeof (*new_hook_fd));
if (!new_hook_fd)
{
free (new_hook);
return NULL;
}
hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT,
callback_data);
new_hook->hook_data = new_hook_fd;
new_hook_fd->callback = callback;
new_hook_fd->fd = fd;
new_hook_fd->flags = 0;
new_hook_fd->error = 0;
if (flag_read)
new_hook_fd->flags |= HOOK_FD_FLAG_READ;
if (flag_write)
new_hook_fd->flags |= HOOK_FD_FLAG_WRITE;
if (flag_exception)
new_hook_fd->flags |= HOOK_FD_FLAG_EXCEPTION;
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read,
int flag_write, int flag_exception,
t_hook_callback_fd *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_fd *new_hook_fd;
if ((fd < 0) || hook_search_fd (fd) || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_fd = malloc (sizeof (*new_hook_fd));
if (!new_hook_fd)
{
free (new_hook);
return NULL;
}
hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT,
callback_data);
new_hook->hook_data = new_hook_fd;
new_hook_fd->callback = callback;
new_hook_fd->fd = fd;
new_hook_fd->flags = 0;
new_hook_fd->error = 0;
if (flag_read)
new_hook_fd->flags |= HOOK_FD_FLAG_READ;
if (flag_write)
new_hook_fd->flags |= HOOK_FD_FLAG_WRITE;
if (flag_exception)
new_hook_fd->flags |= HOOK_FD_FLAG_EXCEPTION;
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,791
|
hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_FD];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), read_fds)))
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds)))
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), exception_fds)))))
{
ptr_hook->running = 1;
(void) (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data,
HOOK_FD(ptr_hook, fd));
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
Exec Code
| 0
|
hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
{
struct t_hook *ptr_hook, *next_hook;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_FD];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), read_fds)))
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds)))
|| ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION)
&& (FD_ISSET(HOOK_FD(ptr_hook, fd), exception_fds)))))
{
ptr_hook->running = 1;
(void) (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data,
HOOK_FD(ptr_hook, fd));
ptr_hook->running = 0;
}
ptr_hook = next_hook;
}
hook_exec_end ();
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,792
|
hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
{
struct t_hook *ptr_hook;
int max_fd;
max_fd = 0;
for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted)
{
/* skip invalid file descriptors */
if ((fcntl (HOOK_FD(ptr_hook,fd), F_GETFD) == -1)
&& (errno == EBADF))
{
if (HOOK_FD(ptr_hook, error) == 0)
{
HOOK_FD(ptr_hook, error) = errno;
gui_chat_printf (NULL,
_("%sError: bad file descriptor (%d) "
"used in hook_fd"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
HOOK_FD(ptr_hook, fd));
}
}
else
{
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ)
{
FD_SET (HOOK_FD(ptr_hook, fd), read_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE)
{
FD_SET (HOOK_FD(ptr_hook, fd), write_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION)
{
FD_SET (HOOK_FD(ptr_hook, fd), exception_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
}
}
}
return max_fd;
}
|
Exec Code
| 0
|
hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds)
{
struct t_hook *ptr_hook;
int max_fd;
max_fd = 0;
for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted)
{
/* skip invalid file descriptors */
if ((fcntl (HOOK_FD(ptr_hook,fd), F_GETFD) == -1)
&& (errno == EBADF))
{
if (HOOK_FD(ptr_hook, error) == 0)
{
HOOK_FD(ptr_hook, error) = errno;
gui_chat_printf (NULL,
_("%sError: bad file descriptor (%d) "
"used in hook_fd"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
HOOK_FD(ptr_hook, fd));
}
}
else
{
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ)
{
FD_SET (HOOK_FD(ptr_hook, fd), read_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE)
{
FD_SET (HOOK_FD(ptr_hook, fd), write_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION)
{
FD_SET (HOOK_FD(ptr_hook, fd), exception_fds);
if (HOOK_FD(ptr_hook, fd) > max_fd)
max_fd = HOOK_FD(ptr_hook, fd);
}
}
}
}
return max_fd;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,793
|
hook_find_pos (struct t_hook *hook)
{
struct t_hook *ptr_hook;
int rc_cmp;
if (hook->type == HOOK_TYPE_COMMAND)
{
/* for command hook, sort on command name */
for (ptr_hook = weechat_hooks[hook->type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted)
{
rc_cmp = string_strcasecmp (HOOK_COMMAND(hook, command),
HOOK_COMMAND(ptr_hook, command));
if (rc_cmp < 0)
return ptr_hook;
if ((rc_cmp == 0) && (hook->priority > ptr_hook->priority))
return ptr_hook;
}
}
}
else
{
/* for other types, sort on priority */
for (ptr_hook = weechat_hooks[hook->type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted && (hook->priority > ptr_hook->priority))
return ptr_hook;
}
}
/* position not found, add at the end */
return NULL;
}
|
Exec Code
| 0
|
hook_find_pos (struct t_hook *hook)
{
struct t_hook *ptr_hook;
int rc_cmp;
if (hook->type == HOOK_TYPE_COMMAND)
{
/* for command hook, sort on command name */
for (ptr_hook = weechat_hooks[hook->type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted)
{
rc_cmp = string_strcasecmp (HOOK_COMMAND(hook, command),
HOOK_COMMAND(ptr_hook, command));
if (rc_cmp < 0)
return ptr_hook;
if ((rc_cmp == 0) && (hook->priority > ptr_hook->priority))
return ptr_hook;
}
}
}
else
{
/* for other types, sort on priority */
for (ptr_hook = weechat_hooks[hook->type]; ptr_hook;
ptr_hook = ptr_hook->next_hook)
{
if (!ptr_hook->deleted && (hook->priority > ptr_hook->priority))
return ptr_hook;
}
}
/* position not found, add at the end */
return NULL;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,794
|
hook_focus (struct t_weechat_plugin *plugin, const char *area,
t_hook_callback_focus *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_focus *new_hook_focus;
int priority;
const char *ptr_area;
if (!area || !area[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_focus = malloc (sizeof (*new_hook_focus));
if (!new_hook_focus)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (area, &priority, &ptr_area);
hook_init_data (new_hook, plugin, HOOK_TYPE_FOCUS, priority,
callback_data);
new_hook->hook_data = new_hook_focus;
new_hook_focus->callback = callback;
new_hook_focus->area = strdup ((ptr_area) ? ptr_area : area);
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_focus (struct t_weechat_plugin *plugin, const char *area,
t_hook_callback_focus *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_focus *new_hook_focus;
int priority;
const char *ptr_area;
if (!area || !area[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_focus = malloc (sizeof (*new_hook_focus));
if (!new_hook_focus)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (area, &priority, &ptr_area);
hook_init_data (new_hook, plugin, HOOK_TYPE_FOCUS, priority,
callback_data);
new_hook->hook_data = new_hook_focus;
new_hook_focus->callback = callback;
new_hook_focus->area = strdup ((ptr_area) ? ptr_area : area);
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,795
|
hook_focus_get_data (struct t_hashtable *hashtable_focus1,
struct t_hashtable *hashtable_focus2)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hashtable *hashtable1, *hashtable2, *hashtable_ret;
const char *focus1_chat, *focus1_bar_item_name, *keys;
char **list_keys, *new_key;
int num_keys, i, length, focus1_is_chat;
if (!hashtable_focus1)
return NULL;
focus1_chat = hashtable_get (hashtable_focus1, "_chat");
focus1_is_chat = (focus1_chat && (strcmp (focus1_chat, "1") == 0));
focus1_bar_item_name = hashtable_get (hashtable_focus1, "_bar_item_name");
hashtable1 = hashtable_dup (hashtable_focus1);
if (!hashtable1)
return NULL;
hashtable2 = (hashtable_focus2) ? hashtable_dup (hashtable_focus2) : NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_FOCUS];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& ((focus1_is_chat
&& (strcmp (HOOK_FOCUS(ptr_hook, area), "chat") == 0))
|| (focus1_bar_item_name && focus1_bar_item_name[0]
&& (strcmp (HOOK_FOCUS(ptr_hook, area), focus1_bar_item_name) == 0))))
{
/* run callback for focus #1 */
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_data, hashtable1);
ptr_hook->running = 0;
if (hashtable_ret)
{
if (hashtable_ret != hashtable1)
{
/*
* add keys of hashtable_ret into hashtable1
* and destroy it
*/
hashtable_map (hashtable_ret,
&hook_focus_hashtable_map_cb,
hashtable1);
hashtable_free (hashtable_ret);
}
}
/* run callback for focus #2 */
if (hashtable2)
{
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_data, hashtable2);
ptr_hook->running = 0;
if (hashtable_ret)
{
if (hashtable_ret != hashtable2)
{
/*
* add keys of hashtable_ret into hashtable2
* and destroy it
*/
hashtable_map (hashtable_ret,
&hook_focus_hashtable_map_cb,
hashtable2);
hashtable_free (hashtable_ret);
}
}
}
}
ptr_hook = next_hook;
}
if (hashtable2)
{
hashtable_map (hashtable2, &hook_focus_hashtable_map2_cb, hashtable1);
hashtable_free (hashtable2);
}
else
{
keys = hashtable_get_string (hashtable1, "keys");
if (keys)
{
list_keys = string_split (keys, ",", 0, 0, &num_keys);
if (list_keys)
{
for (i = 0; i < num_keys; i++)
{
length = strlen (list_keys[i]) + 1 + 1;
new_key = malloc (length);
if (new_key)
{
snprintf (new_key, length, "%s2", list_keys[i]);
hashtable_set (hashtable1, new_key,
hashtable_get (hashtable1,
list_keys[i]));
free (new_key);
}
}
string_free_split (list_keys);
}
}
}
hook_exec_end ();
return hashtable1;
}
|
Exec Code
| 0
|
hook_focus_get_data (struct t_hashtable *hashtable_focus1,
struct t_hashtable *hashtable_focus2)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hashtable *hashtable1, *hashtable2, *hashtable_ret;
const char *focus1_chat, *focus1_bar_item_name, *keys;
char **list_keys, *new_key;
int num_keys, i, length, focus1_is_chat;
if (!hashtable_focus1)
return NULL;
focus1_chat = hashtable_get (hashtable_focus1, "_chat");
focus1_is_chat = (focus1_chat && (strcmp (focus1_chat, "1") == 0));
focus1_bar_item_name = hashtable_get (hashtable_focus1, "_bar_item_name");
hashtable1 = hashtable_dup (hashtable_focus1);
if (!hashtable1)
return NULL;
hashtable2 = (hashtable_focus2) ? hashtable_dup (hashtable_focus2) : NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_FOCUS];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& ((focus1_is_chat
&& (strcmp (HOOK_FOCUS(ptr_hook, area), "chat") == 0))
|| (focus1_bar_item_name && focus1_bar_item_name[0]
&& (strcmp (HOOK_FOCUS(ptr_hook, area), focus1_bar_item_name) == 0))))
{
/* run callback for focus #1 */
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_data, hashtable1);
ptr_hook->running = 0;
if (hashtable_ret)
{
if (hashtable_ret != hashtable1)
{
/*
* add keys of hashtable_ret into hashtable1
* and destroy it
*/
hashtable_map (hashtable_ret,
&hook_focus_hashtable_map_cb,
hashtable1);
hashtable_free (hashtable_ret);
}
}
/* run callback for focus #2 */
if (hashtable2)
{
ptr_hook->running = 1;
hashtable_ret = (HOOK_FOCUS(ptr_hook, callback))
(ptr_hook->callback_data, hashtable2);
ptr_hook->running = 0;
if (hashtable_ret)
{
if (hashtable_ret != hashtable2)
{
/*
* add keys of hashtable_ret into hashtable2
* and destroy it
*/
hashtable_map (hashtable_ret,
&hook_focus_hashtable_map_cb,
hashtable2);
hashtable_free (hashtable_ret);
}
}
}
}
ptr_hook = next_hook;
}
if (hashtable2)
{
hashtable_map (hashtable2, &hook_focus_hashtable_map2_cb, hashtable1);
hashtable_free (hashtable2);
}
else
{
keys = hashtable_get_string (hashtable1, "keys");
if (keys)
{
list_keys = string_split (keys, ",", 0, 0, &num_keys);
if (list_keys)
{
for (i = 0; i < num_keys; i++)
{
length = strlen (list_keys[i]) + 1 + 1;
new_key = malloc (length);
if (new_key)
{
snprintf (new_key, length, "%s2", list_keys[i]);
hashtable_set (hashtable1, new_key,
hashtable_get (hashtable1,
list_keys[i]));
free (new_key);
}
}
string_free_split (list_keys);
}
}
}
hook_exec_end ();
return hashtable1;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,796
|
hook_focus_hashtable_map2_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
int length;
char *key2;
/* make C compiler happy */
(void) hashtable;
hashtable1 = (struct t_hashtable *)data;
length = strlen ((const char *)key) + 1 + 1;
key2 = malloc (length);
if (key2)
{
snprintf (key2, length, "%s2", (const char *)key);
if (hashtable1 && key && value)
hashtable_set (hashtable1, key2, (const char *)value);
free (key2);
}
}
|
Exec Code
| 0
|
hook_focus_hashtable_map2_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
int length;
char *key2;
/* make C compiler happy */
(void) hashtable;
hashtable1 = (struct t_hashtable *)data;
length = strlen ((const char *)key) + 1 + 1;
key2 = malloc (length);
if (key2)
{
snprintf (key2, length, "%s2", (const char *)key);
if (hashtable1 && key && value)
hashtable_set (hashtable1, key2, (const char *)value);
free (key2);
}
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,797
|
hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
/* make C compiler happy */
(void) hashtable;
hashtable1 = (struct t_hashtable *)data;
if (hashtable1 && key && value)
hashtable_set (hashtable1, (const char *)key, (const char *)value);
}
|
Exec Code
| 0
|
hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_hashtable *hashtable1;
/* make C compiler happy */
(void) hashtable;
hashtable1 = (struct t_hashtable *)data;
if (hashtable1 && key && value)
hashtable_set (hashtable1, (const char *)key, (const char *)value);
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,798
|
hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name,
const char *description,
t_hook_callback_hdata *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hdata *new_hook_hdata;
int priority;
const char *ptr_hdata_name;
if (!hdata_name || !hdata_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_hdata = malloc (sizeof (*new_hook_hdata));
if (!new_hook_hdata)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (hdata_name, &priority, &ptr_hdata_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_HDATA, priority,
callback_data);
new_hook->hook_data = new_hook_hdata;
new_hook_hdata->callback = callback;
new_hook_hdata->hdata_name = strdup ((ptr_hdata_name) ?
ptr_hdata_name : hdata_name);
new_hook_hdata->description = strdup ((description) ? description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
Exec Code
| 0
|
hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name,
const char *description,
t_hook_callback_hdata *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hdata *new_hook_hdata;
int priority;
const char *ptr_hdata_name;
if (!hdata_name || !hdata_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_hdata = malloc (sizeof (*new_hook_hdata));
if (!new_hook_hdata)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (hdata_name, &priority, &ptr_hdata_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_HDATA, priority,
callback_data);
new_hook->hook_data = new_hook_hdata;
new_hook_hdata->callback = callback;
new_hook_hdata->hdata_name = strdup ((ptr_hdata_name) ?
ptr_hdata_name : hdata_name);
new_hook_hdata->description = strdup ((description) ? description : "");
hook_add_to_list (new_hook);
return new_hook;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
5,799
|
hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hdata *value;
/* make C compiler happy */
(void) plugin;
if (!hdata_name || !hdata_name[0])
return NULL;
if (weechat_hdata)
{
value = hashtable_get (weechat_hdata, hdata_name);
if (value)
return value;
}
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_HDATA];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (strcmp (HOOK_HDATA(ptr_hook, hdata_name), hdata_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_HDATA(ptr_hook, callback))
(ptr_hook->callback_data,
HOOK_HDATA(ptr_hook, hdata_name));
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* hdata not found */
return NULL;
}
|
Exec Code
| 0
|
hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hdata *value;
/* make C compiler happy */
(void) plugin;
if (!hdata_name || !hdata_name[0])
return NULL;
if (weechat_hdata)
{
value = hashtable_get (weechat_hdata, hdata_name);
if (value)
return value;
}
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_HDATA];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (strcmp (HOOK_HDATA(ptr_hook, hdata_name), hdata_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_HDATA(ptr_hook, callback))
(ptr_hook->callback_data,
HOOK_HDATA(ptr_hook, hdata_name));
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* hdata not found */
return NULL;
}
|
@@ -1388,9 +1388,9 @@ hook_process (struct t_weechat_plugin *plugin,
void
hook_process_child (struct t_hook *hook_process)
{
- char *exec_args[4] = { "sh", "-c", NULL, NULL };
+ char **exec_args;
const char *ptr_url;
- int rc;
+ int rc, i;
/*
* close stdin, so that process will fail to read stdin (process reading
@@ -1429,10 +1429,24 @@ hook_process_child (struct t_hook *hook_process)
else
{
/* launch command */
- exec_args[2] = HOOK_PROCESS(hook_process, command);
- execvp (exec_args[0], exec_args);
+ exec_args = string_split_shell (HOOK_PROCESS(hook_process, command));
+ if (exec_args)
+ {
+ if (weechat_debug_core >= 1)
+ {
+ log_printf ("hook_process, command='%s'",
+ HOOK_PROCESS(hook_process, command));
+ for (i = 0; exec_args[i]; i++)
+ {
+ log_printf (" args[%02d] == '%s'", i, exec_args[i]);
+ }
+ }
+ execvp (exec_args[0], exec_args);
+ }
/* should not be executed if execvp was ok */
+ if (exec_args)
+ string_free_split (exec_args);
fprintf (stderr, "Error with command '%s'\n",
HOOK_PROCESS(hook_process, command));
rc = EXIT_FAILURE;
|
CWE-20
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.