project
stringclasses 633
values | commit_id
stringlengths 7
81
| target
int64 0
1
| func
stringlengths 5
484k
| cwe
stringclasses 131
values | big_vul_idx
float64 0
189k
⌀ | idx
int64 0
522k
| hash
stringlengths 34
39
| size
float64 1
24k
⌀ | message
stringlengths 0
11.5k
⌀ | dataset
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|
savannah
|
7f2e4f4f553f6836be7683f66226afac3fa979b8
| 0 |
hash_lookup( const char* key,
hashtable* ht )
{
hashnode *np = hash_bucket( key, ht );
return *np;
}
|
CWE-119
| 6,528 | 14,920 |
323874323324099106171138212156594742331
| null | null | null |
savannah
|
7f2e4f4f553f6836be7683f66226afac3fa979b8
| 0 |
hash_rehash( hashtable* ht,
FT_Memory memory )
{
hashnode* obp = ht->table, *bp, *nbp;
int i, sz = ht->size;
FT_Error error = BDF_Err_Ok;
ht->size <<= 1;
ht->limit = ht->size / 3;
if ( FT_NEW_ARRAY( ht->table, ht->size ) )
goto Exit;
for ( i = 0, bp = obp; i < sz; i++, bp++ )
{
if ( *bp )
{
nbp = hash_bucket( (*bp)->key, ht );
*nbp = *bp;
}
}
FT_FREE( obp );
Exit:
return error;
}
|
CWE-119
| 6,529 | 14,921 |
32250450914333756826663830088098139552
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
clean_up_stdout (void)
{
if (! write_error_seen)
close_stdout ();
close_stdout ();
}
|
CWE-189
| 6,542 | 14,932 |
132634513834645376072011179715007958584
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
color_cap_mt_fct (void)
{
/* Our caller just set selected_match_color. */
context_match_color = selected_match_color;
}
|
CWE-189
| 6,543 | 14,933 |
253386071307148159681389339524943672070
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
color_cap_rv_fct (void)
{
/* By this point, it was 1 (or already -1). */
color_option = -1; /* That's still != 0. */
}
|
CWE-189
| 6,544 | 14,934 |
156779631654124808450717800820647791135
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
pr_sgr_end (char const *s)
{
if (*s)
print_end_colorize (sgr_end);
}
|
CWE-189
| 6,545 | 14,935 |
45027698786525798832688451892877635970
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
pr_sgr_end_if (char const *s)
{
if (color_option)
pr_sgr_end (s);
}
|
CWE-189
| 6,546 | 14,936 |
89011712709266247756241027585534168118
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
pr_sgr_start (char const *s)
{
if (*s)
print_start_colorize (sgr_start, s);
}
|
CWE-189
| 6,547 | 14,937 |
281615131643818784904765896328415923199
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
pr_sgr_start_if (char const *s)
{
if (color_option)
pr_sgr_start (s);
}
|
CWE-189
| 6,548 | 14,938 |
223712926835811215582205499791559497575
| null | null | null |
savannah
|
8fcf61523644df42e1905c81bed26838e0b04f91
| 0 |
suppressible_error (char const *mesg, int errnum)
{
if (! suppress_errors)
error (0, errnum, "%s", mesg);
errseen = 1;
}
|
CWE-189
| 6,549 | 14,939 |
138096839284279443129039427826519106910
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::addMountedShare(Smb4KShare *share)
{
Q_ASSERT(share);
bool added = false;
if (share)
{
mutex.lock();
if (!findShareByPath(share->path()))
{
p->mountedSharesList.append(share);
added = true;
p->onlyForeignShares = true;
for (Smb4KShare *s : p->mountedSharesList)
{
if (!s->isForeign())
{
p->onlyForeignShares = false;
break;
}
else
{
}
}
}
else
{
}
mutex.unlock();
}
else
{
}
return added;
}
|
CWE-20
| 6,594 | 14,974 |
93985563280098741107435424775209955248
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::addShare(Smb4KShare *share)
{
Q_ASSERT(share);
bool added = false;
if (share)
{
mutex.lock();
if (!findShare(share->unc(), share->workgroupName()))
{
p->sharesList.append(share);
added = true;
}
else
{
}
}
else
{
}
mutex.unlock();
return added;
}
|
CWE-20
| 6,595 | 14,975 |
253812826845781251339191347328080607499
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::addWorkgroup(Smb4KWorkgroup *workgroup)
{
Q_ASSERT(workgroup);
bool added = false;
mutex.lock();
if (!findWorkgroup(workgroup->workgroupName()))
{
p->workgroupsList.append(workgroup);
added = true;
}
else
{
}
mutex.unlock();
return added;
}
|
CWE-20
| 6,596 | 14,976 |
89190517553389291274302629598046681915
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
void Smb4KGlobal::clearSharesList()
{
mutex.lock();
while (!p->sharesList.isEmpty())
{
delete p->sharesList.takeFirst();
}
mutex.unlock();
}
|
CWE-20
| 6,598 | 14,977 |
71861335382434470811984203422798523934
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
QList<Smb4KShare*> Smb4KGlobal::findInaccessibleShares()
{
QList<Smb4KShare *> inaccessibleShares;
mutex.lock();
for (Smb4KShare *s : p->mountedSharesList)
{
if (s->isInaccessible())
{
inaccessibleShares += s;
}
else
{
}
}
mutex.unlock();
return inaccessibleShares;
}
|
CWE-20
| 6,600 | 14,978 |
207253593853782687182396588054555933215
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
Smb4KShare *Smb4KGlobal::findShare(const QString& unc, const QString& workgroup)
{
Smb4KShare *share = 0;
mutex.lock();
for (Smb4KShare *s : p->sharesList)
{
if (QString::compare(s->unc(), unc, Qt::CaseInsensitive) == 0 &&
(workgroup.isEmpty() || QString::compare(s->workgroupName(), workgroup, Qt::CaseInsensitive) == 0))
{
share = s;
break;
}
else
{
}
}
mutex.unlock();
return share;
}
|
CWE-20
| 6,601 | 14,979 |
125501319450043303907060087604333942077
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
Smb4KShare* Smb4KGlobal::findShareByPath(const QString &path)
{
Smb4KShare *share = 0;
mutex.lock();
if (!path.isEmpty() && !p->mountedSharesList.isEmpty())
{
for (Smb4KShare *s : p->mountedSharesList)
{
if (QString::compare(s->path(), path, Qt::CaseInsensitive) == 0 ||
QString::compare(s->canonicalPath(), path, Qt::CaseInsensitive) == 0)
{
share = s;
break;
}
else
{
}
}
}
else
{
}
mutex.unlock();
return share;
}
|
CWE-20
| 6,602 | 14,980 |
275643678662584543811398800097511073987
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
QList<Smb4KShare *> Smb4KGlobal::findShareByUNC(const QString &unc)
{
QList<Smb4KShare *> shares;
mutex.lock();
if (!unc.isEmpty() && !p->mountedSharesList.isEmpty())
{
for (Smb4KShare *s : p->mountedSharesList)
{
if (QString::compare(s->unc(), unc, Qt::CaseInsensitive) == 0)
{
shares += s;
}
else
{
}
}
}
else
{
}
mutex.unlock();
return shares;
}
|
CWE-20
| 6,603 | 14,981 |
117356764085892492568135768599970129549
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
void Smb4KGlobal::openShare(Smb4KShare *share, OpenWith openWith)
{
if (!share || share->isInaccessible())
{
return;
}
switch (openWith)
{
case FileManager:
{
QUrl url = QUrl::fromLocalFile(share->canonicalPath());
(void) new KRun(url, 0);
break;
}
case Konsole:
{
QString konsole = QStandardPaths::findExecutable("konsole");
if (konsole.isEmpty())
{
Smb4KNotification::commandNotFound("konsole");
}
else
{
KRun::runCommand(konsole+" --workdir "+KShell::quoteArg(share->canonicalPath()), 0);
}
break;
}
default:
{
break;
}
}
}
|
CWE-20
| 6,605 | 14,982 |
35369758559161974259002334061398447768
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::removeMountedShare(Smb4KShare *share)
{
Q_ASSERT(share);
bool removed = false;
if (share)
{
mutex.lock();
QMutableListIterator<Smb4KShare *> it(p->mountedSharesList);
while (it.hasNext())
{
Smb4KShare *s = it.next();
if (QString::compare(s->path(), share->path(), Qt::CaseInsensitive) == 0 ||
QString::compare(s->canonicalPath(), share->canonicalPath(), Qt::CaseInsensitive) == 0)
{
it.remove();
removed = true;
break;
}
else
{
}
}
for (Smb4KShare *s : p->mountedSharesList)
{
if (!s->isForeign())
{
p->onlyForeignShares = false;
break;
}
else
{
}
}
delete share;
mutex.unlock();
}
else
{
}
return removed;
}
|
CWE-20
| 6,607 | 14,983 |
264058344729509780117237445305560578667
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::removeShare(Smb4KShare *share)
{
Q_ASSERT(share);
bool removed = false;
if (share)
{
mutex.lock();
int index = p->sharesList.indexOf(share);
if (index != -1)
{
delete p->sharesList.takeAt(index);
removed = true;
}
else
{
Smb4KShare *s = findShare(share->unc(), share->workgroupName());
if (s)
{
index = p->sharesList.indexOf(s);
if (index != -1)
{
delete p->sharesList.takeAt(index);
removed = true;
}
else
{
}
}
else
{
}
delete share;
}
mutex.unlock();
}
else
{
}
return removed;
}
|
CWE-20
| 6,608 | 14,984 |
196118442381516003289353399447415675274
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
bool Smb4KGlobal::removeWorkgroup(Smb4KWorkgroup *workgroup)
{
Q_ASSERT(workgroup);
bool removed = false;
mutex.lock();
int index = p->workgroupsList.indexOf(workgroup);
if (index != -1)
{
delete p->workgroupsList.takeAt(index);
removed = true;
}
else
{
Smb4KWorkgroup *wg = findWorkgroup(workgroup->workgroupName());
if (wg)
{
index = p->workgroupsList.indexOf(wg);
if (index != -1)
{
delete p->workgroupsList.takeAt(index);
removed = true;
}
else
{
}
}
else
{
}
delete workgroup;
}
mutex.unlock();
return removed;
}
|
CWE-20
| 6,609 | 14,985 |
171659747544462616340879021034141822129
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
QList<Smb4KShare *> Smb4KGlobal::sharedResources(Smb4KHost *host)
{
QList<Smb4KShare *> shares;
mutex.lock();
for (Smb4KShare *s : p->sharesList)
{
if (QString::compare(s->hostName(), host->hostName(), Qt::CaseInsensitive) == 0 &&
QString::compare(s->workgroupName(), host->workgroupName(), Qt::CaseInsensitive) == 0)
{
shares += s;
}
else
{
}
}
mutex.unlock();
return shares;
}
|
CWE-20
| 6,610 | 14,986 |
186421230871593185725636897937930895371
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
QList<Smb4KHost *> Smb4KGlobal::workgroupMembers(Smb4KWorkgroup *workgroup)
{
QList<Smb4KHost *> hosts;
mutex.lock();
for (Smb4KHost *h : p->hostsList)
{
if (QString::compare(h->workgroupName(), workgroup->workgroupName(), Qt::CaseInsensitive) == 0)
{
hosts += h;
}
else
{
}
}
mutex.unlock();
return hosts;
}
|
CWE-20
| 6,613 | 14,987 |
46044036347644588173747175197409346598
| null | null | null |
kde
|
a90289b0962663bc1d247bbbd31b9e65b2ca000e
| 0 |
void Smb4KMounter::abortAll()
{
if (!QCoreApplication::closingDown())
{
QListIterator<KJob *> it(subjobs());
while (it.hasNext())
{
it.next()->kill(KJob::EmitResult);
}
}
else
{
}
}
|
CWE-20
| 6,614 | 14,988 |
242019033904363078630836617073607928005
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
T1_Done_Blend( T1_Face face )
{
FT_Memory memory = face->root.memory;
PS_Blend blend = face->blend;
if ( blend )
{
FT_UInt num_designs = blend->num_designs;
FT_UInt num_axis = blend->num_axis;
FT_UInt n;
/* release design pos table */
FT_FREE( blend->design_pos[0] );
for ( n = 1; n < num_designs; n++ )
blend->design_pos[n] = NULL;
/* release blend `private' and `font info' dictionaries */
FT_FREE( blend->privates[1] );
FT_FREE( blend->font_infos[1] );
FT_FREE( blend->bboxes[1] );
for ( n = 0; n < num_designs; n++ )
{
blend->privates [n] = NULL;
blend->font_infos[n] = NULL;
blend->bboxes [n] = NULL;
}
/* release weight vectors */
FT_FREE( blend->weight_vector );
blend->default_weight_vector = NULL;
/* release axis names */
for ( n = 0; n < num_axis; n++ )
FT_FREE( blend->axis_names[n] );
/* release design map */
for ( n = 0; n < num_axis; n++ )
{
PS_DesignMap dmap = blend->design_map + n;
FT_FREE( dmap->design_points );
dmap->num_points = 0;
}
FT_FREE( face->blend );
}
}
|
CWE-399
| 6,652 | 15,021 |
21490475045498911402035575249381967762
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
T1_Get_MM_Var( T1_Face face,
FT_MM_Var* *master )
{
FT_Memory memory = face->root.memory;
FT_MM_Var *mmvar = NULL;
FT_Multi_Master mmaster;
FT_Error error;
FT_UInt i;
FT_Fixed axiscoords[T1_MAX_MM_AXIS];
PS_Blend blend = face->blend;
error = T1_Get_Multi_Master( face, &mmaster );
if ( error )
goto Exit;
if ( FT_ALLOC( mmvar,
sizeof ( FT_MM_Var ) +
mmaster.num_axis * sizeof ( FT_Var_Axis ) ) )
goto Exit;
mmvar->num_axis = mmaster.num_axis;
mmvar->num_designs = mmaster.num_designs;
mmvar->num_namedstyles = ~0U; /* Does not apply */
mmvar->axis = (FT_Var_Axis*)&mmvar[1];
/* Point to axes after MM_Var struct */
mmvar->namedstyle = NULL;
for ( i = 0 ; i < mmaster.num_axis; ++i )
{
mmvar->axis[i].name = mmaster.axis[i].name;
mmvar->axis[i].minimum = INT_TO_FIXED( mmaster.axis[i].minimum);
mmvar->axis[i].maximum = INT_TO_FIXED( mmaster.axis[i].maximum);
mmvar->axis[i].def = ( mmvar->axis[i].minimum +
mmvar->axis[i].maximum ) / 2;
/* Does not apply. But this value is in range */
mmvar->axis[i].strid = ~0U; /* Does not apply */
mmvar->axis[i].tag = ~0U; /* Does not apply */
if ( ft_strcmp( mmvar->axis[i].name, "Weight" ) == 0 )
mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'g', 'h', 't' );
else if ( ft_strcmp( mmvar->axis[i].name, "Width" ) == 0 )
mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'd', 't', 'h' );
else if ( ft_strcmp( mmvar->axis[i].name, "OpticalSize" ) == 0 )
mmvar->axis[i].tag = FT_MAKE_TAG( 'o', 'p', 's', 'z' );
}
if ( blend->num_designs == ( 1U << blend->num_axis ) )
{
mm_weights_unmap( blend->default_weight_vector,
axiscoords,
blend->num_axis );
for ( i = 0; i < mmaster.num_axis; ++i )
mmvar->axis[i].def = mm_axis_unmap( &blend->design_map[i],
axiscoords[i] );
}
*master = mmvar;
Exit:
return error;
}
|
CWE-399
| 6,653 | 15,022 |
2842027867262882488065124806036206809
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
T1_Get_Multi_Master( T1_Face face,
FT_Multi_Master* master )
{
PS_Blend blend = face->blend;
FT_UInt n;
FT_Error error;
error = FT_THROW( Invalid_Argument );
if ( blend )
{
master->num_axis = blend->num_axis;
master->num_designs = blend->num_designs;
for ( n = 0; n < blend->num_axis; n++ )
{
FT_MM_Axis* axis = master->axis + n;
PS_DesignMap map = blend->design_map + n;
axis->name = blend->axis_names[n];
axis->minimum = map->design_points[0];
axis->maximum = map->design_points[map->num_points - 1];
}
error = FT_Err_Ok;
}
return error;
}
|
CWE-399
| 6,654 | 15,023 |
270069423638040678365502463480273262528
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
T1_Set_Var_Design( T1_Face face,
FT_UInt num_coords,
FT_Fixed* coords )
{
FT_Long lcoords[4]; /* maximum axis count is 4 */
FT_UInt i;
FT_Error error;
error = FT_ERR( Invalid_Argument );
if ( num_coords <= 4 && num_coords > 0 )
{
for ( i = 0; i < num_coords; ++i )
lcoords[i] = FIXED_TO_INT( coords[i] );
error = T1_Set_MM_Design( face, num_coords, lcoords );
}
return error;
}
|
CWE-399
| 6,656 | 15,024 |
128665001610397296317591827193932120387
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
mm_weights_unmap( FT_Fixed* weights,
FT_Fixed* axiscoords,
FT_UInt axis_count )
{
FT_ASSERT( axis_count <= T1_MAX_MM_AXIS );
if ( axis_count == 1 )
axiscoords[0] = weights[1];
else if ( axis_count == 2 )
{
axiscoords[0] = weights[3] + weights[1];
axiscoords[1] = weights[3] + weights[2];
}
else if ( axis_count == 3 )
{
axiscoords[0] = weights[7] + weights[5] + weights[3] + weights[1];
axiscoords[1] = weights[7] + weights[6] + weights[3] + weights[2];
axiscoords[2] = weights[7] + weights[6] + weights[5] + weights[4];
}
else
{
axiscoords[0] = weights[15] + weights[13] + weights[11] + weights[9] +
weights[7] + weights[5] + weights[3] + weights[1];
axiscoords[1] = weights[15] + weights[14] + weights[11] + weights[10] +
weights[7] + weights[6] + weights[3] + weights[2];
axiscoords[2] = weights[15] + weights[14] + weights[13] + weights[12] +
weights[7] + weights[6] + weights[5] + weights[4];
axiscoords[3] = weights[15] + weights[14] + weights[13] + weights[12] +
weights[11] + weights[10] + weights[9] + weights[8];
}
}
|
CWE-399
| 6,658 | 15,025 |
121263882194033947249243729723191553440
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_blend_axis_types( T1_Face face,
T1_Loader loader )
{
T1_TokenRec axis_tokens[T1_MAX_MM_AXIS];
FT_Int n, num_axis;
FT_Error error = FT_Err_Ok;
PS_Blend blend;
FT_Memory memory;
/* take an array of objects */
T1_ToTokenArray( &loader->parser, axis_tokens,
T1_MAX_MM_AXIS, &num_axis );
if ( num_axis < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS )
{
FT_ERROR(( "parse_blend_axis_types: incorrect number of axes: %d\n",
num_axis ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* allocate blend if necessary */
error = t1_allocate_blend( face, 0, (FT_UInt)num_axis );
if ( error )
goto Exit;
blend = face->blend;
memory = face->root.memory;
/* each token is an immediate containing the name of the axis */
for ( n = 0; n < num_axis; n++ )
{
T1_Token token = axis_tokens + n;
FT_Byte* name;
FT_PtrDist len;
/* skip first slash, if any */
if ( token->start[0] == '/' )
token->start++;
len = token->limit - token->start;
if ( len == 0 )
{
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
if ( FT_ALLOC( blend->axis_names[n], (FT_Long)( len + 1 ) ) )
goto Exit;
name = (FT_Byte*)blend->axis_names[n];
FT_MEM_COPY( name, token->start, len );
name[len] = '\0';
}
Exit:
loader->parser.root.error = error;
}
|
CWE-399
| 6,659 | 15,026 |
239593505326708246812079722208938407842
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_blend_design_map( T1_Face face,
T1_Loader loader )
{
FT_Error error = FT_Err_Ok;
T1_Parser parser = &loader->parser;
PS_Blend blend;
T1_TokenRec axis_tokens[T1_MAX_MM_AXIS];
FT_Int n, num_axis;
FT_Byte* old_cursor;
FT_Byte* old_limit;
FT_Memory memory = face->root.memory;
T1_ToTokenArray( parser, axis_tokens,
T1_MAX_MM_AXIS, &num_axis );
if ( num_axis < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS )
{
FT_ERROR(( "parse_blend_design_map: incorrect number of axes: %d\n",
num_axis ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
old_cursor = parser->root.cursor;
old_limit = parser->root.limit;
error = t1_allocate_blend( face, 0, num_axis );
if ( error )
goto Exit;
blend = face->blend;
/* now read each axis design map */
for ( n = 0; n < num_axis; n++ )
{
PS_DesignMap map = blend->design_map + n;
T1_Token axis_token;
T1_TokenRec point_tokens[T1_MAX_MM_MAP_POINTS];
FT_Int p, num_points;
axis_token = axis_tokens + n;
parser->root.cursor = axis_token->start;
parser->root.limit = axis_token->limit;
T1_ToTokenArray( parser, point_tokens,
T1_MAX_MM_MAP_POINTS, &num_points );
if ( num_points <= 0 || num_points > T1_MAX_MM_MAP_POINTS )
{
FT_ERROR(( "parse_blend_design_map: incorrect table\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* allocate design map data */
if ( FT_NEW_ARRAY( map->design_points, num_points * 2 ) )
goto Exit;
map->blend_points = map->design_points + num_points;
map->num_points = (FT_Byte)num_points;
for ( p = 0; p < num_points; p++ )
{
T1_Token point_token;
point_token = point_tokens + p;
/* don't include delimiting brackets */
parser->root.cursor = point_token->start + 1;
parser->root.limit = point_token->limit - 1;
map->design_points[p] = T1_ToInt( parser );
map->blend_points [p] = T1_ToFixed( parser, 0 );
}
}
parser->root.cursor = old_cursor;
parser->root.limit = old_limit;
Exit:
parser->root.error = error;
}
|
CWE-399
| 6,660 | 15,027 |
242351288979242556879373375680522128040
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_blend_design_positions( T1_Face face,
T1_Loader loader )
{
T1_TokenRec design_tokens[T1_MAX_MM_DESIGNS];
FT_Int num_designs;
FT_Int num_axis;
T1_Parser parser = &loader->parser;
FT_Error error = FT_Err_Ok;
PS_Blend blend;
/* get the array of design tokens -- compute number of designs */
T1_ToTokenArray( parser, design_tokens,
T1_MAX_MM_DESIGNS, &num_designs );
if ( num_designs < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS )
{
FT_ERROR(( "parse_blend_design_positions:"
" incorrect number of designs: %d\n",
num_designs ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
{
FT_Byte* old_cursor = parser->root.cursor;
FT_Byte* old_limit = parser->root.limit;
FT_Int n;
blend = face->blend;
num_axis = 0; /* make compiler happy */
for ( n = 0; n < num_designs; n++ )
{
T1_TokenRec axis_tokens[T1_MAX_MM_AXIS];
T1_Token token;
FT_Int axis, n_axis;
/* read axis/coordinates tokens */
token = design_tokens + n;
parser->root.cursor = token->start;
parser->root.limit = token->limit;
T1_ToTokenArray( parser, axis_tokens, T1_MAX_MM_AXIS, &n_axis );
if ( n == 0 )
{
if ( n_axis <= 0 || n_axis > T1_MAX_MM_AXIS )
{
FT_ERROR(( "parse_blend_design_positions:"
" invalid number of axes: %d\n",
n_axis ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
num_axis = n_axis;
error = t1_allocate_blend( face, num_designs, num_axis );
if ( error )
goto Exit;
blend = face->blend;
}
else if ( n_axis != num_axis )
{
FT_ERROR(( "parse_blend_design_positions: incorrect table\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
/* now read each axis token into the design position */
for ( axis = 0; axis < n_axis; axis++ )
{
T1_Token token2 = axis_tokens + axis;
parser->root.cursor = token2->start;
parser->root.limit = token2->limit;
blend->design_pos[n][axis] = T1_ToFixed( parser, 0 );
}
}
loader->parser.root.cursor = old_cursor;
loader->parser.root.limit = old_limit;
}
Exit:
loader->parser.root.error = error;
}
|
CWE-399
| 6,661 | 15,028 |
257776473922649469560358026782511543979
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_buildchar( T1_Face face,
T1_Loader loader )
{
face->len_buildchar = T1_ToFixedArray( &loader->parser, 0, NULL, 0 );
return;
}
|
CWE-399
| 6,662 | 15,029 |
178303617151332483787661229716235571062
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_private( T1_Face face,
T1_Loader loader )
{
FT_UNUSED( face );
loader->keywords_encountered |= T1_PRIVATE;
}
|
CWE-399
| 6,663 | 15,030 |
126864828796635235308005013725712797830
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
parse_weight_vector( T1_Face face,
T1_Loader loader )
{
T1_TokenRec design_tokens[T1_MAX_MM_DESIGNS];
FT_Int num_designs;
FT_Error error = FT_Err_Ok;
T1_Parser parser = &loader->parser;
PS_Blend blend = face->blend;
T1_Token token;
FT_Int n;
FT_Byte* old_cursor;
FT_Byte* old_limit;
T1_ToTokenArray( parser, design_tokens,
T1_MAX_MM_DESIGNS, &num_designs );
if ( num_designs < 0 )
{
error = FT_ERR( Ignore );
goto Exit;
}
if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS )
{
FT_ERROR(( "parse_weight_vector:"
" incorrect number of designs: %d\n",
num_designs ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
if ( !blend || !blend->num_designs )
{
error = t1_allocate_blend( face, num_designs, 0 );
if ( error )
goto Exit;
blend = face->blend;
}
else if ( blend->num_designs != (FT_UInt)num_designs )
{
FT_ERROR(( "parse_weight_vector:"
" /BlendDesignPosition and /WeightVector have\n"
" "
" different number of elements\n" ));
error = FT_THROW( Invalid_File_Format );
goto Exit;
}
old_cursor = parser->root.cursor;
old_limit = parser->root.limit;
for ( n = 0; n < num_designs; n++ )
{
token = design_tokens + n;
parser->root.cursor = token->start;
parser->root.limit = token->limit;
blend->default_weight_vector[n] =
blend->weight_vector[n] = T1_ToFixed( parser, 0 );
}
parser->root.cursor = old_cursor;
parser->root.limit = old_limit;
Exit:
parser->root.error = error;
}
|
CWE-399
| 6,664 | 15,031 |
117070451376203479073708529957988723024
| null | null | null |
savannah
|
df14e6c0b9592cbb24d5381dfc6106b14f915e75
| 0 |
read_binary_data( T1_Parser parser,
FT_Long* size,
FT_Byte** base,
FT_Bool incremental )
{
FT_Byte* cur;
FT_Byte* limit = parser->root.limit;
/* the binary data has one of the following formats */
/* */
/* `size' [white*] RD white ....... ND */
/* `size' [white*] -| white ....... |- */
/* */
T1_Skip_Spaces( parser );
cur = parser->root.cursor;
if ( cur < limit && ft_isdigit( *cur ) )
{
FT_Long s = T1_ToInt( parser );
T1_Skip_PS_Token( parser ); /* `RD' or `-|' or something else */
/* there is only one whitespace char after the */
/* `RD' or `-|' token */
*base = parser->root.cursor + 1;
if ( s >= 0 && s < limit - *base )
{
parser->root.cursor += s + 1;
*size = s;
return !parser->root.error;
}
}
if( !incremental )
{
FT_ERROR(( "read_binary_data: invalid size field\n" ));
parser->root.error = FT_THROW( Invalid_File_Format );
}
return 0;
}
|
CWE-399
| 6,665 | 15,032 |
139237799842348402455525824859718712490
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static void __http_protocol_init(void)
{
acl_register_keywords(&acl_kws);
sample_register_fetches(&sample_fetch_keywords);
sample_register_convs(&sample_conv_kws);
http_req_keywords_register(&http_req_actions);
http_res_keywords_register(&http_res_actions);
cli_register_kw(&cli_kws);
}
|
CWE-200
| 6,781 | 15,034 |
195241065913255870827256315893871458108
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
struct action_kw *action_http_req_custom(const char *kw)
{
return action_lookup(&http_req_keywords.list, kw);
}
|
CWE-200
| 6,782 | 15,035 |
328699117525423813869474526499731185652
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
struct action_kw *action_http_res_custom(const char *kw)
{
return action_lookup(&http_res_keywords.list, kw);
}
|
CWE-200
| 6,783 | 15,036 |
156535480136449732248918330863327749454
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return action_http_set_status(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
http_set_status(rule->arg.status.code, rule->arg.status.reason, s);
return ACT_RET_CONT;
}
|
CWE-200
| 6,784 | 15,037 |
44457810946535052635496859516042005159
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int apply_filter_to_req_line(struct stream *s, struct channel *req, struct hdr_exp *exp)
{
char *cur_ptr, *cur_end;
int done;
struct http_txn *txn = s->txn;
int delta;
if (unlikely(txn->flags & (TX_CLDENY | TX_CLTARPIT)))
return 1;
else if (unlikely(txn->flags & TX_CLALLOW) &&
(exp->action == ACT_ALLOW ||
exp->action == ACT_DENY ||
exp->action == ACT_TARPIT))
return 0;
else if (exp->action == ACT_REMOVE)
return 0;
done = 0;
cur_ptr = req->buf->p;
cur_end = cur_ptr + txn->req.sl.rq.l;
/* Now we have the request line between cur_ptr and cur_end */
if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_ALLOW:
txn->flags |= TX_CLALLOW;
done = 1;
break;
case ACT_DENY:
txn->flags |= TX_CLDENY;
done = 1;
break;
case ACT_TARPIT:
txn->flags |= TX_CLTARPIT;
done = 1;
break;
case ACT_REPLACE:
trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch);
if (trash.len < 0)
return -1;
delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash.str, trash.len);
/* FIXME: if the user adds a newline in the replacement, the
* index will not be recalculated for now, and the new line
* will not be counted as a new header.
*/
http_msg_move_end(&txn->req, delta);
cur_end += delta;
cur_end = (char *)http_parse_reqline(&txn->req,
HTTP_MSG_RQMETH,
cur_ptr, cur_end + 1,
NULL, NULL);
if (unlikely(!cur_end))
return -1;
/* we have a full request and we know that we have either a CR
* or an LF at <ptr>.
*/
txn->meth = find_http_meth(cur_ptr, txn->req.sl.rq.m_l);
hdr_idx_set_start(&txn->hdr_idx, txn->req.sl.rq.l, *cur_end == '\r');
/* there is no point trying this regex on headers */
return 1;
}
}
return done;
}
|
CWE-200
| 6,785 | 15,038 |
138269546679631227671093500140459784799
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int apply_filter_to_resp_headers(struct stream *s, struct channel *rtr, struct hdr_exp *exp)
{
char *cur_ptr, *cur_end, *cur_next;
int cur_idx, old_idx, last_hdr;
struct http_txn *txn = s->txn;
struct hdr_idx_elem *cur_hdr;
int delta;
last_hdr = 0;
cur_next = rtr->buf->p + hdr_idx_first_pos(&txn->hdr_idx);
old_idx = 0;
while (!last_hdr) {
if (unlikely(txn->flags & TX_SVDENY))
return 1;
else if (unlikely(txn->flags & TX_SVALLOW) &&
(exp->action == ACT_ALLOW ||
exp->action == ACT_DENY))
return 0;
cur_idx = txn->hdr_idx.v[old_idx].next;
if (!cur_idx)
break;
cur_hdr = &txn->hdr_idx.v[cur_idx];
cur_ptr = cur_next;
cur_end = cur_ptr + cur_hdr->len;
cur_next = cur_end + cur_hdr->cr + 1;
/* Now we have one header between cur_ptr and cur_end,
* and the next header starts at cur_next.
*/
if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_ALLOW:
txn->flags |= TX_SVALLOW;
last_hdr = 1;
break;
case ACT_DENY:
txn->flags |= TX_SVDENY;
last_hdr = 1;
break;
case ACT_REPLACE:
trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch);
if (trash.len < 0)
return -1;
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len);
/* FIXME: if the user adds a newline in the replacement, the
* index will not be recalculated for now, and the new line
* will not be counted as a new header.
*/
cur_end += delta;
cur_next += delta;
cur_hdr->len += delta;
http_msg_move_end(&txn->rsp, delta);
break;
case ACT_REMOVE:
delta = buffer_replace2(rtr->buf, cur_ptr, cur_next, NULL, 0);
cur_next += delta;
http_msg_move_end(&txn->rsp, delta);
txn->hdr_idx.v[old_idx].next = cur_hdr->next;
txn->hdr_idx.used--;
cur_hdr->len = 0;
cur_end = NULL; /* null-term has been rewritten */
cur_idx = old_idx;
break;
}
}
/* keep the link from this header to next one in case of later
* removal of next header.
*/
old_idx = cur_idx;
}
return 0;
}
|
CWE-200
| 6,786 | 15,039 |
180776059794866583329872063798139814305
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int apply_filter_to_sts_line(struct stream *s, struct channel *rtr, struct hdr_exp *exp)
{
char *cur_ptr, *cur_end;
int done;
struct http_txn *txn = s->txn;
int delta;
if (unlikely(txn->flags & TX_SVDENY))
return 1;
else if (unlikely(txn->flags & TX_SVALLOW) &&
(exp->action == ACT_ALLOW ||
exp->action == ACT_DENY))
return 0;
else if (exp->action == ACT_REMOVE)
return 0;
done = 0;
cur_ptr = rtr->buf->p;
cur_end = cur_ptr + txn->rsp.sl.st.l;
/* Now we have the status line between cur_ptr and cur_end */
if (regex_exec_match2(exp->preg, cur_ptr, cur_end-cur_ptr, MAX_MATCH, pmatch, 0)) {
switch (exp->action) {
case ACT_ALLOW:
txn->flags |= TX_SVALLOW;
done = 1;
break;
case ACT_DENY:
txn->flags |= TX_SVDENY;
done = 1;
break;
case ACT_REPLACE:
trash.len = exp_replace(trash.str, trash.size, cur_ptr, exp->replace, pmatch);
if (trash.len < 0)
return -1;
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len);
/* FIXME: if the user adds a newline in the replacement, the
* index will not be recalculated for now, and the new line
* will not be counted as a new header.
*/
http_msg_move_end(&txn->rsp, delta);
cur_end += delta;
cur_end = (char *)http_parse_stsline(&txn->rsp,
HTTP_MSG_RPVER,
cur_ptr, cur_end + 1,
NULL, NULL);
if (unlikely(!cur_end))
return -1;
/* we have a full respnse and we know that we have either a CR
* or an LF at <ptr>.
*/
txn->status = strl2ui(rtr->buf->p + txn->rsp.sl.st.c, txn->rsp.sl.st.c_l);
hdr_idx_set_start(&txn->hdr_idx, txn->rsp.sl.st.l, *cur_end == '\r');
/* there is no point trying this regex on headers */
return 1;
}
}
return done;
}
|
CWE-200
| 6,787 | 15,040 |
325999339057921434238757458300076381973
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int apply_filters_to_request(struct stream *s, struct channel *req, struct proxy *px)
{
struct session *sess = s->sess;
struct http_txn *txn = s->txn;
struct hdr_exp *exp;
for (exp = px->req_exp; exp; exp = exp->next) {
int ret;
/*
* The interleaving of transformations and verdicts
* makes it difficult to decide to continue or stop
* the evaluation.
*/
if (txn->flags & (TX_CLDENY|TX_CLTARPIT))
break;
if ((txn->flags & TX_CLALLOW) &&
(exp->action == ACT_ALLOW || exp->action == ACT_DENY ||
exp->action == ACT_TARPIT || exp->action == ACT_PASS))
continue;
/* if this filter had a condition, evaluate it now and skip to
* next filter if the condition does not match.
*/
if (exp->cond) {
ret = acl_exec_cond(exp->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (((struct acl_cond *)exp->cond)->pol == ACL_COND_UNLESS)
ret = !ret;
if (!ret)
continue;
}
/* Apply the filter to the request line. */
ret = apply_filter_to_req_line(s, req, exp);
if (unlikely(ret < 0))
return -1;
if (likely(ret == 0)) {
/* The filter did not match the request, it can be
* iterated through all headers.
*/
if (unlikely(apply_filter_to_req_headers(s, req, exp) < 0))
return -1;
}
}
return 0;
}
|
CWE-200
| 6,788 | 15,041 |
211163005605842483434594929149399495885
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int apply_filters_to_response(struct stream *s, struct channel *rtr, struct proxy *px)
{
struct session *sess = s->sess;
struct http_txn *txn = s->txn;
struct hdr_exp *exp;
for (exp = px->rsp_exp; exp; exp = exp->next) {
int ret;
/*
* The interleaving of transformations and verdicts
* makes it difficult to decide to continue or stop
* the evaluation.
*/
if (txn->flags & TX_SVDENY)
break;
if ((txn->flags & TX_SVALLOW) &&
(exp->action == ACT_ALLOW || exp->action == ACT_DENY ||
exp->action == ACT_PASS)) {
exp = exp->next;
continue;
}
/* if this filter had a condition, evaluate it now and skip to
* next filter if the condition does not match.
*/
if (exp->cond) {
ret = acl_exec_cond(exp->cond, px, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (((struct acl_cond *)exp->cond)->pol == ACL_COND_UNLESS)
ret = !ret;
if (!ret)
continue;
}
/* Apply the filter to the status line. */
ret = apply_filter_to_sts_line(s, rtr, exp);
if (unlikely(ret < 0))
return -1;
if (likely(ret == 0)) {
/* The filter did not match the response, it can be
* iterated through all headers.
*/
if (unlikely(apply_filter_to_resp_headers(s, rtr, exp) < 0))
return -1;
}
}
return 0;
}
|
CWE-200
| 6,789 | 15,042 |
81131791987331702965138244745700397392
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void capture_headers(char *som, struct hdr_idx *idx,
char **cap, struct cap_hdr *cap_hdr)
{
char *eol, *sol, *col, *sov;
int cur_idx;
struct cap_hdr *h;
int len;
sol = som + hdr_idx_first_pos(idx);
cur_idx = hdr_idx_first_idx(idx);
while (cur_idx) {
eol = sol + idx->v[cur_idx].len;
col = sol;
while (col < eol && *col != ':')
col++;
sov = col + 1;
while (sov < eol && HTTP_IS_LWS(*sov))
sov++;
for (h = cap_hdr; h; h = h->next) {
if (h->namelen && (h->namelen == col - sol) &&
(strncasecmp(sol, h->name, h->namelen) == 0)) {
if (cap[h->index] == NULL)
cap[h->index] =
pool_alloc(h->pool);
if (cap[h->index] == NULL) {
ha_alert("HTTP capture : out of memory.\n");
continue;
}
len = eol - sov;
if (len > h->len)
len = h->len;
memcpy(cap[h->index], sov, len);
cap[h->index][len]=0;
}
}
sol = eol + idx->v[cur_idx].cr + 1;
cur_idx = idx->v[cur_idx].next;
}
}
|
CWE-200
| 6,790 | 15,043 |
182795259851491491994597835098525674939
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int check_http_res_capture(struct act_rule *rule, struct proxy *px, char **err)
{
if (rule->action_ptr != http_action_res_capture_by_id)
return 1;
if (rule->arg.capid.idx >= px->nb_rsp_cap) {
memprintf(err, "unable to find capture id '%d' referenced by http-response capture rule",
rule->arg.capid.idx);
return 0;
}
return 1;
}
|
CWE-200
| 6,792 | 15,044 |
167199778828526765186039441994114889216
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void check_response_for_cacheability(struct stream *s, struct channel *rtr)
{
struct http_txn *txn = s->txn;
char *p1, *p2;
char *cur_ptr, *cur_end, *cur_next;
int cur_idx;
if (txn->status < 200) {
/* do not try to cache interim responses! */
txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK;
return;
}
/* Iterate through the headers.
* we start with the start line.
*/
cur_idx = 0;
cur_next = rtr->buf->p + hdr_idx_first_pos(&txn->hdr_idx);
while ((cur_idx = txn->hdr_idx.v[cur_idx].next)) {
struct hdr_idx_elem *cur_hdr;
int val;
cur_hdr = &txn->hdr_idx.v[cur_idx];
cur_ptr = cur_next;
cur_end = cur_ptr + cur_hdr->len;
cur_next = cur_end + cur_hdr->cr + 1;
/* We have one full header between cur_ptr and cur_end, and the
* next header starts at cur_next.
*/
val = http_header_match2(cur_ptr, cur_end, "Pragma", 6);
if (val) {
if ((cur_end - (cur_ptr + val) >= 8) &&
strncasecmp(cur_ptr + val, "no-cache", 8) == 0) {
txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK;
return;
}
}
val = http_header_match2(cur_ptr, cur_end, "Cache-control", 13);
if (!val)
continue;
/* OK, right now we know we have a cache-control header at cur_ptr */
p1 = cur_ptr + val; /* first non-space char after 'cache-control:' */
if (p1 >= cur_end) /* no more info */
continue;
/* p1 is at the beginning of the value */
p2 = p1;
while (p2 < cur_end && *p2 != '=' && *p2 != ',' && !isspace((unsigned char)*p2))
p2++;
/* we have a complete value between p1 and p2 */
if (p2 < cur_end && *p2 == '=') {
if (((cur_end - p2) > 1 && (p2 - p1 == 7) && strncasecmp(p1, "max-age=0", 9) == 0) ||
((cur_end - p2) > 1 && (p2 - p1 == 8) && strncasecmp(p1, "s-maxage=0", 10) == 0)) {
txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK;
continue;
}
/* we have something of the form no-cache="set-cookie" */
if ((cur_end - p1 >= 21) &&
strncasecmp(p1, "no-cache=\"set-cookie", 20) == 0
&& (p1[20] == '"' || p1[20] == ','))
txn->flags &= ~TX_CACHE_COOK;
continue;
}
/* OK, so we know that either p2 points to the end of string or to a comma */
if (((p2 - p1 == 7) && strncasecmp(p1, "private", 7) == 0) ||
((p2 - p1 == 8) && strncasecmp(p1, "no-cache", 8) == 0) ||
((p2 - p1 == 8) && strncasecmp(p1, "no-store", 8) == 0)) {
txn->flags &= ~TX_CACHEABLE & ~TX_CACHE_COOK;
return;
}
if ((p2 - p1 == 6) && strncasecmp(p1, "public", 6) == 0) {
txn->flags |= TX_CACHEABLE | TX_CACHE_COOK;
continue;
}
}
}
|
CWE-200
| 6,793 | 15,045 |
92332580689782971354345383057314114377
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static int cli_io_handler_show_errors(struct appctx *appctx)
{
struct stream_interface *si = appctx->owner;
extern const char *monthname[12];
if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
return 1;
chunk_reset(&trash);
if (!appctx->ctx.errors.px) {
/* the function had not been called yet, let's prepare the
* buffer for a response.
*/
struct tm tm;
get_localtime(date.tv_sec, &tm);
chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n",
tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000),
error_snapshot_id);
if (ci_putchk(si_ic(si), &trash) == -1) {
/* Socket buffer full. Let's try again later from the same point */
si_applet_cant_put(si);
return 0;
}
appctx->ctx.errors.px = proxies_list;
appctx->ctx.errors.bol = 0;
appctx->ctx.errors.ptr = -1;
}
/* we have two inner loops here, one for the proxy, the other one for
* the buffer.
*/
while (appctx->ctx.errors.px) {
struct error_snapshot *es;
if ((appctx->ctx.errors.flag & 1) == 0) {
es = &appctx->ctx.errors.px->invalid_req;
if (appctx->ctx.errors.flag & 2) // skip req
goto next;
}
else {
es = &appctx->ctx.errors.px->invalid_rep;
if (appctx->ctx.errors.flag & 4) // skip resp
goto next;
}
if (!es->when.tv_sec)
goto next;
if (appctx->ctx.errors.iid >= 0 &&
appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid &&
es->oe->uuid != appctx->ctx.errors.iid)
goto next;
if (appctx->ctx.errors.ptr < 0) {
/* just print headers now */
char pn[INET6_ADDRSTRLEN];
struct tm tm;
int port;
get_localtime(es->when.tv_sec, &tm);
chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]",
tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900,
tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000));
switch (addr_to_str(&es->src, pn, sizeof(pn))) {
case AF_INET:
case AF_INET6:
port = get_host_port(&es->src);
break;
default:
port = 0;
}
switch (appctx->ctx.errors.flag & 1) {
case 0:
chunk_appendf(&trash,
" frontend %s (#%d): invalid request\n"
" backend %s (#%d)",
appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
(es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>",
(es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1);
break;
case 1:
chunk_appendf(&trash,
" backend %s (#%d): invalid response\n"
" frontend %s (#%d)",
appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid,
es->oe->id, es->oe->uuid);
break;
}
chunk_appendf(&trash,
", server %s (#%d), event #%u\n"
" src %s:%d, session #%d, session flags 0x%08x\n"
" HTTP msg state %s(%d), msg flags 0x%08x, tx flags 0x%08x\n"
" HTTP chunk len %lld bytes, HTTP body len %lld bytes\n"
" buffer flags 0x%08x, out %d bytes, total %lld bytes\n"
" pending %d bytes, wrapping at %d, error at position %d:\n \n",
es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1,
es->ev_id,
pn, port, es->sid, es->s_flags,
h1_msg_state_str(es->state), es->state, es->m_flags, es->t_flags,
es->m_clen, es->m_blen,
es->b_flags, es->b_out, es->b_tot,
es->len, es->b_wrap, es->pos);
if (ci_putchk(si_ic(si), &trash) == -1) {
/* Socket buffer full. Let's try again later from the same point */
si_applet_cant_put(si);
return 0;
}
appctx->ctx.errors.ptr = 0;
appctx->ctx.errors.sid = es->sid;
}
if (appctx->ctx.errors.sid != es->sid) {
/* the snapshot changed while we were dumping it */
chunk_appendf(&trash,
" WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n");
if (ci_putchk(si_ic(si), &trash) == -1) {
si_applet_cant_put(si);
return 0;
}
goto next;
}
/* OK, ptr >= 0, so we have to dump the current line */
while (es->buf && appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < global.tune.bufsize) {
int newptr;
int newline;
newline = appctx->ctx.errors.bol;
newptr = dump_text_line(&trash, es->buf, global.tune.bufsize, es->len, &newline, appctx->ctx.errors.ptr);
if (newptr == appctx->ctx.errors.ptr)
return 0;
if (ci_putchk(si_ic(si), &trash) == -1) {
/* Socket buffer full. Let's try again later from the same point */
si_applet_cant_put(si);
return 0;
}
appctx->ctx.errors.ptr = newptr;
appctx->ctx.errors.bol = newline;
};
next:
appctx->ctx.errors.bol = 0;
appctx->ctx.errors.ptr = -1;
appctx->ctx.errors.flag ^= 1;
if (!(appctx->ctx.errors.flag & 1))
appctx->ctx.errors.px = appctx->ctx.errors.px->next;
}
/* dump complete */
return 1;
}
|
CWE-200
| 6,794 | 15,046 |
150388449049083704844128407993700359813
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static int cli_parse_show_errors(char **args, struct appctx *appctx, void *private)
{
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
return 1;
if (*args[2]) {
struct proxy *px;
px = proxy_find_by_name(args[2], 0, 0);
if (px)
appctx->ctx.errors.iid = px->uuid;
else
appctx->ctx.errors.iid = atoi(args[2]);
if (!appctx->ctx.errors.iid) {
appctx->ctx.cli.severity = LOG_ERR;
appctx->ctx.cli.msg = "No such proxy.\n";
appctx->st0 = CLI_ST_PRINT;
return 1;
}
}
else
appctx->ctx.errors.iid = -1; // dump all proxies
appctx->ctx.errors.flag = 0;
if (strcmp(args[3], "request") == 0)
appctx->ctx.errors.flag |= 4; // ignore response
else if (strcmp(args[3], "response") == 0)
appctx->ctx.errors.flag |= 2; // ignore request
appctx->ctx.errors.px = NULL;
return 0;
}
|
CWE-200
| 6,795 | 15,047 |
170853061042486193858842479800867654125
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void debug_hdr(const char *dir, struct stream *s, const char *start, const char *end)
{
struct session *sess = strm_sess(s);
int max;
chunk_printf(&trash, "%08x:%s.%s[%04x:%04x]: ", s->uniq_id, s->be->id,
dir,
objt_conn(sess->origin) ? (unsigned short)objt_conn(sess->origin)->handle.fd : -1,
objt_cs(s->si[1].end) ? (unsigned short)objt_cs(s->si[1].end)->conn->handle.fd : -1);
for (max = 0; start + max < end; max++)
if (start[max] == '\r' || start[max] == '\n')
break;
UBOUND(max, trash.size - trash.len - 3);
trash.len += strlcpy2(trash.str + trash.len, start, max + 1);
trash.str[trash.len++] = '\n';
shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
}
|
CWE-200
| 6,796 | 15,048 |
333837843425412243681955379566108292720
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int del_hdr_value(struct buffer *buf, char **from, char *next)
{
char *prev = *from;
if (*prev == ':') {
/* We're removing the first value, preserve the colon and add a
* space if possible.
*/
if (!HTTP_IS_CRLF(*next))
next++;
prev++;
if (prev < next)
*prev++ = ' ';
while (HTTP_IS_SPHT(*next))
next++;
} else {
/* Remove useless spaces before the old delimiter. */
while (HTTP_IS_SPHT(*(prev-1)))
prev--;
*from = prev;
/* copy the delimiter and if possible a space if we're
* not at the end of the line.
*/
if (!HTTP_IS_CRLF(*next)) {
*prev++ = *next++;
if (prev + 1 < next)
*prev++ = ' ';
while (HTTP_IS_SPHT(*next))
next++;
}
}
return buffer_replace2(buf, prev, next, NULL, 0);
}
|
CWE-200
| 6,797 | 15,049 |
162268723669375738399329353481262339462
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
extract_cookie_value(char *hdr, const char *hdr_end,
char *cookie_name, size_t cookie_name_l, int list,
char **value, int *value_l)
{
char *equal, *att_end, *att_beg, *val_beg, *val_end;
char *next;
/* we search at least a cookie name followed by an equal, and more
* generally something like this :
* Cookie: NAME1 = VALUE 1 ; NAME2 = VALUE2 ; NAME3 = VALUE3\r\n
*/
for (att_beg = hdr; att_beg + cookie_name_l + 1 < hdr_end; att_beg = next + 1) {
/* Iterate through all cookies on this line */
while (att_beg < hdr_end && HTTP_IS_SPHT(*att_beg))
att_beg++;
/* find att_end : this is the first character after the last non
* space before the equal. It may be equal to hdr_end.
*/
equal = att_end = att_beg;
while (equal < hdr_end) {
if (*equal == '=' || *equal == ';' || (list && *equal == ','))
break;
if (HTTP_IS_SPHT(*equal++))
continue;
att_end = equal;
}
/* here, <equal> points to '=', a delimitor or the end. <att_end>
* is between <att_beg> and <equal>, both may be identical.
*/
/* look for end of cookie if there is an equal sign */
if (equal < hdr_end && *equal == '=') {
/* look for the beginning of the value */
val_beg = equal + 1;
while (val_beg < hdr_end && HTTP_IS_SPHT(*val_beg))
val_beg++;
/* find the end of the value, respecting quotes */
next = find_cookie_value_end(val_beg, hdr_end);
/* make val_end point to the first white space or delimitor after the value */
val_end = next;
while (val_end > val_beg && HTTP_IS_SPHT(*(val_end - 1)))
val_end--;
} else {
val_beg = val_end = next = equal;
}
/* We have nothing to do with attributes beginning with '$'. However,
* they will automatically be removed if a header before them is removed,
* since they're supposed to be linked together.
*/
if (*att_beg == '$')
continue;
/* Ignore cookies with no equal sign */
if (equal == next)
continue;
/* Now we have the cookie name between att_beg and att_end, and
* its value between val_beg and val_end.
*/
if (att_end - att_beg == cookie_name_l &&
memcmp(att_beg, cookie_name, cookie_name_l) == 0) {
/* let's return this value and indicate where to go on from */
*value = val_beg;
*value_l = val_end - val_beg;
return next + 1;
}
/* Set-Cookie headers only have the name in the first attr=value part */
if (!list)
break;
}
return NULL;
}
|
CWE-200
| 6,798 | 15,050 |
295798792550227717295986041301396520912
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
char *find_hdr_value_end(char *s, const char *e)
{
int quoted, qdpair;
quoted = qdpair = 0;
#if defined(__x86_64__) || \
defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || \
defined(__ARM_ARCH_7A__)
/* speedup: skip everything not a comma nor a double quote */
for (; s <= e - sizeof(int); s += sizeof(int)) {
unsigned int c = *(int *)s; // comma
unsigned int q = c; // quote
c ^= 0x2c2c2c2c; // contains one zero on a comma
q ^= 0x22222222; // contains one zero on a quote
c = (c - 0x01010101) & ~c; // contains 0x80 below a comma
q = (q - 0x01010101) & ~q; // contains 0x80 below a quote
if ((c | q) & 0x80808080)
break; // found a comma or a quote
}
#endif
for (; s < e; s++) {
if (qdpair) qdpair = 0;
else if (quoted) {
if (*s == '\\') qdpair = 1;
else if (*s == '"') quoted = 0;
}
else if (*s == '"') quoted = 1;
else if (*s == ',') return s;
}
return s;
}
|
CWE-200
| 6,800 | 15,051 |
12597157124595966564932862985742043623
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum http_meth_t find_http_meth(const char *str, const int len)
{
unsigned char m;
const struct http_method_desc *h;
m = ((unsigned)*str - 'A');
if (m < 26) {
for (h = http_methods[m]; h->len > 0; h++) {
if (unlikely(h->len != len))
continue;
if (likely(memcmp(str, h->text, h->len) == 0))
return h->meth;
};
}
return HTTP_METH_OTHER;
}
|
CWE-200
| 6,801 | 15,052 |
10182886481391847482721806772071140587
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static inline char *find_param_list(char *path, size_t path_l, char delim)
{
char *p;
p = memchr(path, delim, path_l);
return p ? p + 1 : NULL;
}
|
CWE-200
| 6,802 | 15,053 |
255767243097592141384608603388638339260
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
find_url_param_pos(const char **chunks,
const char* url_param_name, size_t url_param_name_l,
char delim)
{
const char *pos, *last, *equal;
const char **bufs = chunks;
int l1, l2;
pos = bufs[0];
last = bufs[1];
while (pos < last) {
/* Check the equal. */
equal = pos + url_param_name_l;
if (fix_pointer_if_wrap(chunks, &equal)) {
if (equal >= chunks[3])
return NULL;
} else {
if (equal >= chunks[1])
return NULL;
}
if (*equal == '=') {
if (pos + url_param_name_l > last) {
/* process wrap case, we detect a wrap. In this case, the
* comparison is performed in two parts.
*/
/* This is the end, we dont have any other chunk. */
if (bufs != chunks || !bufs[2])
return NULL;
/* Compute the length of each part of the comparison. */
l1 = last - pos;
l2 = url_param_name_l - l1;
/* The second buffer is too short to contain the compared string. */
if (bufs[2] + l2 > bufs[3])
return NULL;
if (memcmp(pos, url_param_name, l1) == 0 &&
memcmp(bufs[2], url_param_name+l1, l2) == 0)
return pos;
/* Perform wrapping and jump the string who fail the comparison. */
bufs += 2;
pos = bufs[0] + l2;
last = bufs[1];
} else {
/* process a simple comparison. */
if (memcmp(pos, url_param_name, url_param_name_l) == 0)
return pos;
pos += url_param_name_l + 1;
if (fix_pointer_if_wrap(chunks, &pos))
last = bufs[2];
}
}
while (1) {
/* Look for the next delimiter. */
while (pos < last && !is_param_delimiter(*pos, delim))
pos++;
if (pos < last)
break;
/* process buffer wrapping. */
if (bufs != chunks || !bufs[2])
return NULL;
bufs += 2;
pos = bufs[0];
last = bufs[1];
}
pos++;
}
return NULL;
}
|
CWE-200
| 6,803 | 15,054 |
270302425006512677273869902499695797653
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static inline int fix_pointer_if_wrap(const char **chunks, const char **ptr)
{
if (*ptr < chunks[1])
return 0;
if (!chunks[2])
return 0;
*ptr = chunks[2] + ( *ptr - chunks[1] );
return 1;
}
|
CWE-200
| 6,804 | 15,055 |
169647373589215025438113236009967038607
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void free_http_req_rules(struct list *r)
{
struct act_rule *tr, *pr;
list_for_each_entry_safe(pr, tr, r, list) {
LIST_DEL(&pr->list);
if (pr->action == ACT_HTTP_REQ_AUTH)
free(pr->arg.auth.realm);
regex_free(&pr->arg.hdr_add.re);
free(pr);
}
}
|
CWE-200
| 6,805 | 15,056 |
173910951655223738867594875256403592341
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void free_http_res_rules(struct list *r)
{
struct act_rule *tr, *pr;
list_for_each_entry_safe(pr, tr, r, list) {
LIST_DEL(&pr->list);
regex_free(&pr->arg.hdr_add.re);
free(pr);
}
}
|
CWE-200
| 6,806 | 15,057 |
46502125898370785117414687882132217764
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
const char *get_reason(unsigned int status)
{
switch (status) {
case 100: return "Continue";
case 101: return "Switching Protocols";
case 102: return "Processing";
case 200: return "OK";
case 201: return "Created";
case 202: return "Accepted";
case 203: return "Non-Authoritative Information";
case 204: return "No Content";
case 205: return "Reset Content";
case 206: return "Partial Content";
case 207: return "Multi-Status";
case 210: return "Content Different";
case 226: return "IM Used";
case 300: return "Multiple Choices";
case 301: return "Moved Permanently";
case 302: return "Moved Temporarily";
case 303: return "See Other";
case 304: return "Not Modified";
case 305: return "Use Proxy";
case 307: return "Temporary Redirect";
case 308: return "Permanent Redirect";
case 310: return "Too many Redirects";
case 400: return "Bad Request";
case 401: return "Unauthorized";
case 402: return "Payment Required";
case 403: return "Forbidden";
case 404: return "Not Found";
case 405: return "Method Not Allowed";
case 406: return "Not Acceptable";
case 407: return "Proxy Authentication Required";
case 408: return "Request Time-out";
case 409: return "Conflict";
case 410: return "Gone";
case 411: return "Length Required";
case 412: return "Precondition Failed";
case 413: return "Request Entity Too Large";
case 414: return "Request-URI Too Long";
case 415: return "Unsupported Media Type";
case 416: return "Requested range unsatisfiable";
case 417: return "Expectation failed";
case 418: return "I'm a teapot";
case 422: return "Unprocessable entity";
case 423: return "Locked";
case 424: return "Method failure";
case 425: return "Too Early";
case 426: return "Upgrade Required";
case 428: return "Precondition Required";
case 429: return "Too Many Requests";
case 431: return "Request Header Fields Too Large";
case 449: return "Retry With";
case 450: return "Blocked by Windows Parental Controls";
case 451: return "Unavailable For Legal Reasons";
case 456: return "Unrecoverable Error";
case 499: return "client has closed connection";
case 500: return "Internal Server Error";
case 501: return "Not Implemented";
case 502: return "Bad Gateway or Proxy Error";
case 503: return "Service Unavailable";
case 504: return "Gateway Time-out";
case 505: return "HTTP Version not supported";
case 506: return "Variant also negociate";
case 507: return "Insufficient storage";
case 508: return "Loop detected";
case 509: return "Bandwidth Limit Exceeded";
case 510: return "Not extended";
case 511: return "Network authentication required";
case 520: return "Web server is returning an unknown error";
default:
switch (status) {
case 100 ... 199: return "Informational";
case 200 ... 299: return "Success";
case 300 ... 399: return "Redirection";
case 400 ... 499: return "Client Error";
case 500 ... 599: return "Server Error";
default: return "Other";
}
}
}
|
CWE-200
| 6,807 | 15,058 |
39780823657068319438142789584084017911
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return http_action_reject(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
channel_abort(&s->req);
channel_abort(&s->res);
s->req.analysers = 0;
s->res.analysers = 0;
HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
if (sess->listener && sess->listener->counters)
HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_PRXCOND;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
return ACT_RET_CONT;
}
|
CWE-200
| 6,808 | 15,059 |
322037278619453702651812165476711140953
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return http_action_req_capture(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
struct sample *key;
struct cap_hdr *h = rule->arg.cap.hdr;
char **cap = s->req_cap;
int len;
key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.cap.expr, SMP_T_STR);
if (!key)
return ACT_RET_CONT;
if (cap[h->index] == NULL)
cap[h->index] = pool_alloc(h->pool);
if (cap[h->index] == NULL) /* no more capture memory */
return ACT_RET_CONT;
len = key->data.u.str.len;
if (len > h->len)
len = h->len;
memcpy(cap[h->index], key->data.u.str.str, len);
cap[h->index][len] = 0;
return ACT_RET_CONT;
}
|
CWE-200
| 6,809 | 15,060 |
32396962920387455100978519902236706860
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
struct sample *key;
struct cap_hdr *h;
char **cap = s->req_cap;
struct proxy *fe = strm_fe(s);
int len;
int i;
/* Look for the original configuration. */
for (h = fe->req_cap, i = fe->nb_req_cap - 1;
h != NULL && i != rule->arg.capid.idx ;
i--, h = h->next);
if (!h)
return ACT_RET_CONT;
key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
if (!key)
return ACT_RET_CONT;
if (cap[h->index] == NULL)
cap[h->index] = pool_alloc(h->pool);
if (cap[h->index] == NULL) /* no more capture memory */
return ACT_RET_CONT;
len = key->data.u.str.len;
if (len > h->len)
len = h->len;
memcpy(cap[h->index], key->data.u.str.str, len);
cap[h->index][len] = 0;
return ACT_RET_CONT;
}
|
CWE-200
| 6,810 | 15,061 |
146140563482517868263879147199691451033
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
struct sample *key;
struct cap_hdr *h;
char **cap = s->res_cap;
struct proxy *fe = strm_fe(s);
int len;
int i;
/* Look for the original configuration. */
for (h = fe->rsp_cap, i = fe->nb_rsp_cap - 1;
h != NULL && i != rule->arg.capid.idx ;
i--, h = h->next);
if (!h)
return ACT_RET_CONT;
key = sample_fetch_as_type(s->be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->arg.capid.expr, SMP_T_STR);
if (!key)
return ACT_RET_CONT;
if (cap[h->index] == NULL)
cap[h->index] = pool_alloc(h->pool);
if (cap[h->index] == NULL) /* no more capture memory */
return ACT_RET_CONT;
len = key->data.u.str.len;
if (len > h->len)
len = h->len;
memcpy(cap[h->index], key->data.u.str.str, len);
cap[h->index][len] = 0;
return ACT_RET_CONT;
}
|
CWE-200
| 6,811 | 15,062 |
197847233984926853109325247428440448595
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
enum act_return http_action_set_req_line(struct act_rule *rule, struct proxy *px,
struct session *sess, struct stream *s, int flags)
{
struct chunk *replace;
enum act_return ret = ACT_RET_ERR;
replace = alloc_trash_chunk();
if (!replace)
goto leave;
/* If we have to create a query string, prepare a '?'. */
if (rule->arg.http.action == 2)
replace->str[replace->len++] = '?';
replace->len += build_logline(s, replace->str + replace->len, replace->size - replace->len,
&rule->arg.http.logfmt);
http_replace_req_line(rule->arg.http.action, replace->str, replace->len, px, s);
ret = ACT_RET_CONT;
leave:
free_trash_chunk(replace);
return ret;
}
|
CWE-200
| 6,812 | 15,063 |
9503962735727991686856718941733418448
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_adjust_conn_mode(struct stream *s, struct http_txn *txn, struct http_msg *msg)
{
struct proxy *fe = strm_fe(s);
int tmp = TX_CON_WANT_KAL;
if (!((fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
tmp = TX_CON_WANT_TUN;
if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
tmp = TX_CON_WANT_TUN;
}
if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) {
/* option httpclose + server_close => forceclose */
if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
tmp = TX_CON_WANT_CLO;
else
tmp = TX_CON_WANT_SCL;
}
if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
tmp = TX_CON_WANT_CLO;
if ((txn->flags & TX_CON_WANT_MSK) < tmp)
txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | tmp;
if (!(txn->flags & TX_HDR_CONN_PRS) &&
(txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) {
/* parse the Connection header and possibly clean it */
int to_del = 0;
if ((msg->flags & HTTP_MSGF_VER_11) ||
((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL &&
!((fe->options2|s->be->options2) & PR_O2_FAKE_KA)))
to_del |= 2; /* remove "keep-alive" */
if (!(msg->flags & HTTP_MSGF_VER_11))
to_del |= 1; /* remove "close" */
http_parse_connection_header(txn, msg, to_del);
}
/* check if client or config asks for explicit close in KAL/SCL */
if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL ||
(txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL) &&
((txn->flags & TX_HDR_CONN_CLO) || /* "connection: close" */
(!(msg->flags & HTTP_MSGF_VER_11) && !(txn->flags & TX_HDR_CONN_KAL)) || /* no "connection: k-a" in 1.0 */
!(msg->flags & HTTP_MSGF_XFER_LEN) || /* no length known => close */
fe->state == PR_STSTOPPED)) /* frontend is stopping */
txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
}
|
CWE-200
| 6,813 | 15,064 |
301478221094158653266073399717947420612
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
struct http_txn *http_alloc_txn(struct stream *s)
{
struct http_txn *txn = s->txn;
if (txn)
return txn;
txn = pool_alloc(pool_head_http_txn);
if (!txn)
return txn;
txn->hdr_idx.size = global.tune.max_http_hdr;
txn->hdr_idx.v = pool_alloc(pool_head_hdr_idx);
if (!txn->hdr_idx.v) {
pool_free(pool_head_http_txn, txn);
return NULL;
}
s->txn = txn;
return txn;
}
|
CWE-200
| 6,814 | 15,065 |
183309505891001589675569923609961905772
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct http_txn *txn)
{
struct http_msg *req = &txn->req;
struct http_msg *res = &txn->rsp;
const char *msg_fmt;
struct chunk *chunk;
int ret = 0;
chunk = alloc_trash_chunk();
if (!chunk)
goto leave;
/* build redirect message */
switch(rule->code) {
case 308:
msg_fmt = HTTP_308;
break;
case 307:
msg_fmt = HTTP_307;
break;
case 303:
msg_fmt = HTTP_303;
break;
case 301:
msg_fmt = HTTP_301;
break;
case 302:
default:
msg_fmt = HTTP_302;
break;
}
if (unlikely(!chunk_strcpy(chunk, msg_fmt)))
goto leave;
switch(rule->type) {
case REDIRECT_TYPE_SCHEME: {
const char *path;
const char *host;
struct hdr_ctx ctx;
int pathlen;
int hostlen;
host = "";
hostlen = 0;
ctx.idx = 0;
if (http_find_header2("Host", 4, req->chn->buf->p, &txn->hdr_idx, &ctx)) {
host = ctx.line + ctx.val;
hostlen = ctx.vlen;
}
path = http_get_path(txn);
/* build message using path */
if (path) {
pathlen = req->sl.rq.u_l + (req->chn->buf->p + req->sl.rq.u) - path;
if (rule->flags & REDIRECT_FLAG_DROP_QS) {
int qs = 0;
while (qs < pathlen) {
if (path[qs] == '?') {
pathlen = qs;
break;
}
qs++;
}
}
} else {
path = "/";
pathlen = 1;
}
if (rule->rdr_str) { /* this is an old "redirect" rule */
/* check if we can add scheme + "://" + host + path */
if (chunk->len + rule->rdr_len + 3 + hostlen + pathlen > chunk->size - 4)
goto leave;
/* add scheme */
memcpy(chunk->str + chunk->len, rule->rdr_str, rule->rdr_len);
chunk->len += rule->rdr_len;
}
else {
/* add scheme with executing log format */
chunk->len += build_logline(s, chunk->str + chunk->len, chunk->size - chunk->len, &rule->rdr_fmt);
/* check if we can add scheme + "://" + host + path */
if (chunk->len + 3 + hostlen + pathlen > chunk->size - 4)
goto leave;
}
/* add "://" */
memcpy(chunk->str + chunk->len, "://", 3);
chunk->len += 3;
/* add host */
memcpy(chunk->str + chunk->len, host, hostlen);
chunk->len += hostlen;
/* add path */
memcpy(chunk->str + chunk->len, path, pathlen);
chunk->len += pathlen;
/* append a slash at the end of the location if needed and missing */
if (chunk->len && chunk->str[chunk->len - 1] != '/' &&
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
if (chunk->len > chunk->size - 5)
goto leave;
chunk->str[chunk->len] = '/';
chunk->len++;
}
break;
}
case REDIRECT_TYPE_PREFIX: {
const char *path;
int pathlen;
path = http_get_path(txn);
/* build message using path */
if (path) {
pathlen = req->sl.rq.u_l + (req->chn->buf->p + req->sl.rq.u) - path;
if (rule->flags & REDIRECT_FLAG_DROP_QS) {
int qs = 0;
while (qs < pathlen) {
if (path[qs] == '?') {
pathlen = qs;
break;
}
qs++;
}
}
} else {
path = "/";
pathlen = 1;
}
if (rule->rdr_str) { /* this is an old "redirect" rule */
if (chunk->len + rule->rdr_len + pathlen > chunk->size - 4)
goto leave;
/* add prefix. Note that if prefix == "/", we don't want to
* add anything, otherwise it makes it hard for the user to
* configure a self-redirection.
*/
if (rule->rdr_len != 1 || *rule->rdr_str != '/') {
memcpy(chunk->str + chunk->len, rule->rdr_str, rule->rdr_len);
chunk->len += rule->rdr_len;
}
}
else {
/* add prefix with executing log format */
chunk->len += build_logline(s, chunk->str + chunk->len, chunk->size - chunk->len, &rule->rdr_fmt);
/* Check length */
if (chunk->len + pathlen > chunk->size - 4)
goto leave;
}
/* add path */
memcpy(chunk->str + chunk->len, path, pathlen);
chunk->len += pathlen;
/* append a slash at the end of the location if needed and missing */
if (chunk->len && chunk->str[chunk->len - 1] != '/' &&
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
if (chunk->len > chunk->size - 5)
goto leave;
chunk->str[chunk->len] = '/';
chunk->len++;
}
break;
}
case REDIRECT_TYPE_LOCATION:
default:
if (rule->rdr_str) { /* this is an old "redirect" rule */
if (chunk->len + rule->rdr_len > chunk->size - 4)
goto leave;
/* add location */
memcpy(chunk->str + chunk->len, rule->rdr_str, rule->rdr_len);
chunk->len += rule->rdr_len;
}
else {
/* add location with executing log format */
chunk->len += build_logline(s, chunk->str + chunk->len, chunk->size - chunk->len, &rule->rdr_fmt);
/* Check left length */
if (chunk->len > chunk->size - 4)
goto leave;
}
break;
}
if (rule->cookie_len) {
memcpy(chunk->str + chunk->len, "\r\nSet-Cookie: ", 14);
chunk->len += 14;
memcpy(chunk->str + chunk->len, rule->cookie_str, rule->cookie_len);
chunk->len += rule->cookie_len;
}
/* add end of headers and the keep-alive/close status. */
txn->status = rule->code;
/* let's log the request time */
s->logs.tv_request = now;
if (((!(req->flags & HTTP_MSGF_TE_CHNK) && !req->body_len) || (req->msg_state == HTTP_MSG_DONE)) &&
((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL ||
(txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL)) {
/* keep-alive possible */
if (!(req->flags & HTTP_MSGF_VER_11)) {
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
memcpy(chunk->str + chunk->len, "\r\nProxy-Connection: keep-alive", 30);
chunk->len += 30;
} else {
memcpy(chunk->str + chunk->len, "\r\nConnection: keep-alive", 24);
chunk->len += 24;
}
}
memcpy(chunk->str + chunk->len, "\r\n\r\n", 4);
chunk->len += 4;
FLT_STRM_CB(s, flt_http_reply(s, txn->status, chunk));
co_inject(res->chn, chunk->str, chunk->len);
/* "eat" the request */
bi_fast_delete(req->chn->buf, req->sov);
req->next -= req->sov;
req->sov = 0;
s->req.analysers = AN_REQ_HTTP_XFER_BODY | (s->req.analysers & AN_REQ_FLT_END);
s->res.analysers = AN_RES_HTTP_XFER_BODY | (s->res.analysers & AN_RES_FLT_END);
req->msg_state = HTTP_MSG_CLOSED;
res->msg_state = HTTP_MSG_DONE;
/* Trim any possible response */
res->chn->buf->i = 0;
res->next = res->sov = 0;
/* let the server side turn to SI_ST_CLO */
channel_shutw_now(req->chn);
} else {
/* keep-alive not possible */
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
memcpy(chunk->str + chunk->len, "\r\nProxy-Connection: close\r\n\r\n", 29);
chunk->len += 29;
} else {
memcpy(chunk->str + chunk->len, "\r\nConnection: close\r\n\r\n", 23);
chunk->len += 23;
}
http_reply_and_close(s, txn->status, chunk);
req->chn->analysers &= AN_REQ_FLT_END;
}
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_LOCAL;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
ret = 1;
leave:
free_trash_chunk(chunk);
return ret;
}
|
CWE-200
| 6,815 | 15,066 |
104480225191529071161763117780783184746
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_capture_bad_message(struct proxy *proxy, struct error_snapshot *es, struct stream *s,
struct http_msg *msg,
enum h1_state state, struct proxy *other_end)
{
struct session *sess = strm_sess(s);
struct channel *chn = msg->chn;
int len1, len2;
HA_SPIN_LOCK(PROXY_LOCK, &proxy->lock);
es->len = MIN(chn->buf->i, global.tune.bufsize);
len1 = chn->buf->data + chn->buf->size - chn->buf->p;
len1 = MIN(len1, es->len);
len2 = es->len - len1; /* remaining data if buffer wraps */
if (!es->buf)
es->buf = malloc(global.tune.bufsize);
if (es->buf) {
memcpy(es->buf, chn->buf->p, len1);
if (len2)
memcpy(es->buf + len1, chn->buf->data, len2);
}
if (msg->err_pos >= 0)
es->pos = msg->err_pos;
else
es->pos = msg->next;
es->when = date; // user-visible date
es->sid = s->uniq_id;
es->srv = objt_server(s->target);
es->oe = other_end;
if (objt_conn(sess->origin))
es->src = __objt_conn(sess->origin)->addr.from;
else
memset(&es->src, 0, sizeof(es->src));
es->state = state;
es->ev_id = error_snapshot_id++;
es->b_flags = chn->flags;
es->s_flags = s->flags;
es->t_flags = s->txn->flags;
es->m_flags = msg->flags;
es->b_out = chn->buf->o;
es->b_wrap = chn->buf->data + chn->buf->size - chn->buf->p;
es->b_tot = chn->total;
es->m_clen = msg->chunk_len;
es->m_blen = msg->body_len;
HA_SPIN_UNLOCK(PROXY_LOCK, &proxy->lock);
}
|
CWE-200
| 6,816 | 15,067 |
5947119158805256697786044323307034965
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_change_connection_header(struct http_txn *txn, struct http_msg *msg, int wanted)
{
struct hdr_ctx ctx;
const char *hdr_val = "Connection";
int hdr_len = 10;
ctx.idx = 0;
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
hdr_val = "Proxy-Connection";
hdr_len = 16;
}
txn->flags &= ~(TX_CON_CLO_SET | TX_CON_KAL_SET);
while (http_find_header2(hdr_val, hdr_len, msg->chn->buf->p, &txn->hdr_idx, &ctx)) {
if (ctx.vlen >= 10 && word_match(ctx.line + ctx.val, ctx.vlen, "keep-alive", 10)) {
if (wanted & TX_CON_KAL_SET)
txn->flags |= TX_CON_KAL_SET;
else
http_remove_header2(msg, &txn->hdr_idx, &ctx);
}
else if (ctx.vlen >= 5 && word_match(ctx.line + ctx.val, ctx.vlen, "close", 5)) {
if (wanted & TX_CON_CLO_SET)
txn->flags |= TX_CON_CLO_SET;
else
http_remove_header2(msg, &txn->hdr_idx, &ctx);
}
}
if (wanted == (txn->flags & (TX_CON_CLO_SET|TX_CON_KAL_SET)))
return;
if ((wanted & TX_CON_CLO_SET) && !(txn->flags & TX_CON_CLO_SET)) {
txn->flags |= TX_CON_CLO_SET;
hdr_val = "Connection: close";
hdr_len = 17;
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
hdr_val = "Proxy-Connection: close";
hdr_len = 23;
}
http_header_add_tail2(msg, &txn->hdr_idx, hdr_val, hdr_len);
}
if ((wanted & TX_CON_KAL_SET) && !(txn->flags & TX_CON_KAL_SET)) {
txn->flags |= TX_CON_KAL_SET;
hdr_val = "Connection: keep-alive";
hdr_len = 22;
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
hdr_val = "Proxy-Connection: keep-alive";
hdr_len = 28;
}
http_header_add_tail2(msg, &txn->hdr_idx, hdr_val, hdr_len);
}
return;
}
|
CWE-200
| 6,817 | 15,068 |
225612205013002399353684159489645405926
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_end_txn(struct stream *s)
{
struct http_txn *txn = s->txn;
struct proxy *fe = strm_fe(s);
/* these ones will have been dynamically allocated */
pool_free(pool_head_requri, txn->uri);
pool_free(pool_head_capture, txn->cli_cookie);
pool_free(pool_head_capture, txn->srv_cookie);
pool_free(pool_head_uniqueid, s->unique_id);
s->unique_id = NULL;
txn->uri = NULL;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;
if (s->req_cap) {
struct cap_hdr *h;
for (h = fe->req_cap; h; h = h->next)
pool_free(h->pool, s->req_cap[h->index]);
memset(s->req_cap, 0, fe->nb_req_cap * sizeof(void *));
}
if (s->res_cap) {
struct cap_hdr *h;
for (h = fe->rsp_cap; h; h = h->next)
pool_free(h->pool, s->res_cap[h->index]);
memset(s->res_cap, 0, fe->nb_rsp_cap * sizeof(void *));
}
vars_prune(&s->vars_txn, s->sess, s);
vars_prune(&s->vars_reqres, s->sess, s);
}
|
CWE-200
| 6,818 | 15,069 |
131585145308538404400847476859811978548
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_end_txn_clean_session(struct stream *s)
{
int prev_status = s->txn->status;
struct proxy *fe = strm_fe(s);
struct proxy *be = s->be;
struct conn_stream *cs;
struct connection *srv_conn;
struct server *srv;
unsigned int prev_flags = s->txn->flags;
/* FIXME: We need a more portable way of releasing a backend's and a
* server's connections. We need a safer way to reinitialize buffer
* flags. We also need a more accurate method for computing per-request
* data.
*/
/*
* XXX cognet: This is probably wrong, this is killing a whole
* connection, in the new world order, we probably want to just kill
* the stream, this is to be revisited the day we handle multiple
* streams in one server connection.
*/
cs = objt_cs(s->si[1].end);
srv_conn = cs_conn(cs);
/* unless we're doing keep-alive, we want to quickly close the connection
* to the server.
*/
if (((s->txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_KAL) ||
!si_conn_ready(&s->si[1])) {
s->si[1].flags |= SI_FL_NOLINGER | SI_FL_NOHALF;
si_shutr(&s->si[1]);
si_shutw(&s->si[1]);
}
if (s->flags & SF_BE_ASSIGNED) {
HA_ATOMIC_SUB(&be->beconn, 1);
if (unlikely(s->srv_conn))
sess_change_server(s, NULL);
}
s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
stream_process_counters(s);
if (s->txn->status) {
int n;
n = s->txn->status / 100;
if (n < 1 || n > 5)
n = 0;
if (fe->mode == PR_MODE_HTTP) {
HA_ATOMIC_ADD(&fe->fe_counters.p.http.rsp[n], 1);
}
if ((s->flags & SF_BE_ASSIGNED) &&
(be->mode == PR_MODE_HTTP)) {
HA_ATOMIC_ADD(&be->be_counters.p.http.rsp[n], 1);
HA_ATOMIC_ADD(&be->be_counters.p.http.cum_req, 1);
}
}
/* don't count other requests' data */
s->logs.bytes_in -= s->req.buf->i;
s->logs.bytes_out -= s->res.buf->i;
/* let's do a final log if we need it */
if (!LIST_ISEMPTY(&fe->logformat) && s->logs.logwait &&
!(s->flags & SF_MONITOR) &&
(!(fe->options & PR_O_NULLNOLOG) || s->req.total)) {
s->do_log(s);
}
/* stop tracking content-based counters */
stream_stop_content_counters(s);
stream_update_time_stats(s);
s->logs.accept_date = date; /* user-visible date for logging */
s->logs.tv_accept = now; /* corrected date for internal use */
s->logs.t_handshake = 0; /* There are no handshake in keep alive connection. */
s->logs.t_idle = -1;
tv_zero(&s->logs.tv_request);
s->logs.t_queue = -1;
s->logs.t_connect = -1;
s->logs.t_data = -1;
s->logs.t_close = 0;
s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
s->logs.srv_queue_size = 0; /* we will get this number soon */
s->logs.bytes_in = s->req.total = s->req.buf->i;
s->logs.bytes_out = s->res.total = s->res.buf->i;
if (s->pend_pos)
pendconn_free(s->pend_pos);
if (objt_server(s->target)) {
if (s->flags & SF_CURR_SESS) {
s->flags &= ~SF_CURR_SESS;
HA_ATOMIC_SUB(&objt_server(s->target)->cur_sess, 1);
}
if (may_dequeue_tasks(objt_server(s->target), be))
process_srv_queue(objt_server(s->target));
}
s->target = NULL;
/* only release our endpoint if we don't intend to reuse the
* connection.
*/
if (((s->txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_KAL) ||
!si_conn_ready(&s->si[1])) {
si_release_endpoint(&s->si[1]);
srv_conn = NULL;
}
s->si[1].state = s->si[1].prev_state = SI_ST_INI;
s->si[1].err_type = SI_ET_NONE;
s->si[1].conn_retries = 0; /* used for logging too */
s->si[1].exp = TICK_ETERNITY;
s->si[1].flags &= SI_FL_ISBACK | SI_FL_DONT_WAKE; /* we're in the context of process_stream */
s->req.flags &= ~(CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CONNECT|CF_WRITE_ERROR|CF_STREAMER|CF_STREAMER_FAST|CF_NEVER_WAIT|CF_WAKE_CONNECT|CF_WROTE_DATA);
s->res.flags &= ~(CF_SHUTR|CF_SHUTR_NOW|CF_READ_ATTACHED|CF_READ_ERROR|CF_READ_NOEXP|CF_STREAMER|CF_STREAMER_FAST|CF_WRITE_PARTIAL|CF_NEVER_WAIT|CF_WROTE_DATA|CF_WRITE_EVENT);
s->flags &= ~(SF_DIRECT|SF_ASSIGNED|SF_ADDR_SET|SF_BE_ASSIGNED|SF_FORCE_PRST|SF_IGNORE_PRST);
s->flags &= ~(SF_CURR_SESS|SF_REDIRECTABLE|SF_SRV_REUSED);
s->flags &= ~(SF_ERR_MASK|SF_FINST_MASK|SF_REDISP);
s->txn->meth = 0;
http_reset_txn(s);
s->txn->flags |= TX_NOT_FIRST | TX_WAIT_NEXT_RQ;
if (prev_status == 401 || prev_status == 407) {
/* In HTTP keep-alive mode, if we receive a 401, we still have
* a chance of being able to send the visitor again to the same
* server over the same connection. This is required by some
* broken protocols such as NTLM, and anyway whenever there is
* an opportunity for sending the challenge to the proper place,
* it's better to do it (at least it helps with debugging).
*/
s->txn->flags |= TX_PREFER_LAST;
if (srv_conn)
srv_conn->flags |= CO_FL_PRIVATE;
}
/* Never ever allow to reuse a connection from a non-reuse backend */
if (srv_conn && (be->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR)
srv_conn->flags |= CO_FL_PRIVATE;
if (fe->options2 & PR_O2_INDEPSTR)
s->si[1].flags |= SI_FL_INDEP_STR;
if (fe->options2 & PR_O2_NODELAY) {
s->req.flags |= CF_NEVER_WAIT;
s->res.flags |= CF_NEVER_WAIT;
}
/* we're removing the analysers, we MUST re-enable events detection.
* We don't enable close on the response channel since it's either
* already closed, or in keep-alive with an idle connection handler.
*/
channel_auto_read(&s->req);
channel_auto_close(&s->req);
channel_auto_read(&s->res);
/* we're in keep-alive with an idle connection, monitor it if not already done */
if (srv_conn && LIST_ISEMPTY(&srv_conn->list)) {
srv = objt_server(srv_conn->target);
if (!srv)
si_idle_cs(&s->si[1], NULL);
else if (srv_conn->flags & CO_FL_PRIVATE)
si_idle_cs(&s->si[1], (srv->priv_conns ? &srv->priv_conns[tid] : NULL));
else if (prev_flags & TX_NOT_FIRST)
/* note: we check the request, not the connection, but
* this is valid for strategies SAFE and AGGR, and in
* case of ALWS, we don't care anyway.
*/
si_idle_cs(&s->si[1], (srv->safe_conns ? &srv->safe_conns[tid] : NULL));
else
si_idle_cs(&s->si[1], (srv->idle_conns ? &srv->idle_conns[tid] : NULL));
}
s->req.analysers = strm_li(s) ? strm_li(s)->analysers : 0;
s->res.analysers = 0;
}
|
CWE-200
| 6,819 | 15,070 |
11244401457962763908263010975931803850
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_find_full_header2(const char *name, int len,
char *sol, struct hdr_idx *idx,
struct hdr_ctx *ctx)
{
char *eol, *sov;
int cur_idx, old_idx;
cur_idx = ctx->idx;
if (cur_idx) {
/* We have previously returned a header, let's search another one */
sol = ctx->line;
eol = sol + idx->v[cur_idx].len;
goto next_hdr;
}
/* first request for this header */
sol += hdr_idx_first_pos(idx);
old_idx = 0;
cur_idx = hdr_idx_first_idx(idx);
while (cur_idx) {
eol = sol + idx->v[cur_idx].len;
if (len == 0) {
/* No argument was passed, we want any header.
* To achieve this, we simply build a fake request. */
while (sol + len < eol && sol[len] != ':')
len++;
name = sol;
}
if ((len < eol - sol) &&
(sol[len] == ':') &&
(strncasecmp(sol, name, len) == 0)) {
ctx->del = len;
sov = sol + len + 1;
while (sov < eol && HTTP_IS_LWS(*sov))
sov++;
ctx->line = sol;
ctx->prev = old_idx;
ctx->idx = cur_idx;
ctx->val = sov - sol;
ctx->tws = 0;
while (eol > sov && HTTP_IS_LWS(*(eol - 1))) {
eol--;
ctx->tws++;
}
ctx->vlen = eol - sov;
return 1;
}
next_hdr:
sol = eol + idx->v[cur_idx].cr + 1;
old_idx = cur_idx;
cur_idx = idx->v[cur_idx].next;
}
return 0;
}
|
CWE-200
| 6,821 | 15,071 |
201693680599081957202338800252710503838
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_find_header(const char *name,
char *sol, struct hdr_idx *idx,
struct hdr_ctx *ctx)
{
return http_find_header2(name, strlen(name), sol, idx, ctx);
}
|
CWE-200
| 6,822 | 15,072 |
20222144593902206934181707277334313497
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_find_header2(const char *name, int len,
char *sol, struct hdr_idx *idx,
struct hdr_ctx *ctx)
{
char *eol, *sov;
int cur_idx, old_idx;
cur_idx = ctx->idx;
if (cur_idx) {
/* We have previously returned a value, let's search
* another one on the same line.
*/
sol = ctx->line;
ctx->del = ctx->val + ctx->vlen + ctx->tws;
sov = sol + ctx->del;
eol = sol + idx->v[cur_idx].len;
if (sov >= eol)
/* no more values in this header */
goto next_hdr;
/* values remaining for this header, skip the comma but save it
* for later use (eg: for header deletion).
*/
sov++;
while (sov < eol && HTTP_IS_LWS((*sov)))
sov++;
goto return_hdr;
}
/* first request for this header */
sol += hdr_idx_first_pos(idx);
old_idx = 0;
cur_idx = hdr_idx_first_idx(idx);
while (cur_idx) {
eol = sol + idx->v[cur_idx].len;
if (len == 0) {
/* No argument was passed, we want any header.
* To achieve this, we simply build a fake request. */
while (sol + len < eol && sol[len] != ':')
len++;
name = sol;
}
if ((len < eol - sol) &&
(sol[len] == ':') &&
(strncasecmp(sol, name, len) == 0)) {
ctx->del = len;
sov = sol + len + 1;
while (sov < eol && HTTP_IS_LWS(*sov))
sov++;
ctx->line = sol;
ctx->prev = old_idx;
return_hdr:
ctx->idx = cur_idx;
ctx->val = sov - sol;
eol = find_hdr_value_end(sov, eol);
ctx->tws = 0;
while (eol > sov && HTTP_IS_LWS(*(eol - 1))) {
eol--;
ctx->tws++;
}
ctx->vlen = eol - sov;
return 1;
}
next_hdr:
sol = eol + idx->v[cur_idx].cr + 1;
old_idx = cur_idx;
cur_idx = idx->v[cur_idx].next;
}
return 0;
}
|
CWE-200
| 6,823 | 15,073 |
90203286400939450454656655795826690337
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_find_next_header(char *sol, struct hdr_idx *idx, struct hdr_ctx *ctx)
{
char *eol, *sov;
int cur_idx, old_idx;
int len;
cur_idx = ctx->idx;
if (cur_idx) {
/* We have previously returned a header, let's search another one */
sol = ctx->line;
eol = sol + idx->v[cur_idx].len;
goto next_hdr;
}
/* first request for this header */
sol += hdr_idx_first_pos(idx);
old_idx = 0;
cur_idx = hdr_idx_first_idx(idx);
while (cur_idx) {
eol = sol + idx->v[cur_idx].len;
len = 0;
while (1) {
if (len >= eol - sol)
goto next_hdr;
if (sol[len] == ':')
break;
len++;
}
ctx->del = len;
sov = sol + len + 1;
while (sov < eol && HTTP_IS_LWS(*sov))
sov++;
ctx->line = sol;
ctx->prev = old_idx;
ctx->idx = cur_idx;
ctx->val = sov - sol;
ctx->tws = 0;
while (eol > sov && HTTP_IS_LWS(*(eol - 1))) {
eol--;
ctx->tws++;
}
ctx->vlen = eol - sov;
return 1;
next_hdr:
sol = eol + idx->v[cur_idx].cr + 1;
old_idx = cur_idx;
cur_idx = idx->v[cur_idx].next;
}
return 0;
}
|
CWE-200
| 6,824 | 15,074 |
3387830111791831508751559914661684402
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
unsigned int http_get_fhdr(const struct http_msg *msg, const char *hname, int hlen,
struct hdr_idx *idx, int occ,
struct hdr_ctx *ctx, char **vptr, int *vlen)
{
struct hdr_ctx local_ctx;
char *ptr_hist[MAX_HDR_HISTORY];
int len_hist[MAX_HDR_HISTORY];
unsigned int hist_ptr;
int found;
if (!ctx) {
local_ctx.idx = 0;
ctx = &local_ctx;
}
if (occ >= 0) {
/* search from the beginning */
while (http_find_full_header2(hname, hlen, msg->chn->buf->p, idx, ctx)) {
occ--;
if (occ <= 0) {
*vptr = ctx->line + ctx->val;
*vlen = ctx->vlen;
return 1;
}
}
return 0;
}
/* negative occurrence, we scan all the list then walk back */
if (-occ > MAX_HDR_HISTORY)
return 0;
found = hist_ptr = 0;
while (http_find_full_header2(hname, hlen, msg->chn->buf->p, idx, ctx)) {
ptr_hist[hist_ptr] = ctx->line + ctx->val;
len_hist[hist_ptr] = ctx->vlen;
if (++hist_ptr >= MAX_HDR_HISTORY)
hist_ptr = 0;
found++;
}
if (-occ > found)
return 0;
/* OK now we have the last occurrence in [hist_ptr-1], and we need to
* find occurrence -occ. 0 <= hist_ptr < MAX_HDR_HISTORY, and we have
* -10 <= occ <= -1. So we have to check [hist_ptr%MAX_HDR_HISTORY+occ]
* to remain in the 0..9 range.
*/
hist_ptr += occ + MAX_HDR_HISTORY;
if (hist_ptr >= MAX_HDR_HISTORY)
hist_ptr -= MAX_HDR_HISTORY;
*vptr = ptr_hist[hist_ptr];
*vlen = len_hist[hist_ptr];
return 1;
}
|
CWE-200
| 6,825 | 15,075 |
39618821478038053986502937777190380239
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
unsigned int http_get_hdr(const struct http_msg *msg, const char *hname, int hlen,
struct hdr_idx *idx, int occ,
struct hdr_ctx *ctx, char **vptr, int *vlen)
{
struct hdr_ctx local_ctx;
char *ptr_hist[MAX_HDR_HISTORY];
int len_hist[MAX_HDR_HISTORY];
unsigned int hist_ptr;
int found;
if (!ctx) {
local_ctx.idx = 0;
ctx = &local_ctx;
}
if (occ >= 0) {
/* search from the beginning */
while (http_find_header2(hname, hlen, msg->chn->buf->p, idx, ctx)) {
occ--;
if (occ <= 0) {
*vptr = ctx->line + ctx->val;
*vlen = ctx->vlen;
return 1;
}
}
return 0;
}
/* negative occurrence, we scan all the list then walk back */
if (-occ > MAX_HDR_HISTORY)
return 0;
found = hist_ptr = 0;
while (http_find_header2(hname, hlen, msg->chn->buf->p, idx, ctx)) {
ptr_hist[hist_ptr] = ctx->line + ctx->val;
len_hist[hist_ptr] = ctx->vlen;
if (++hist_ptr >= MAX_HDR_HISTORY)
hist_ptr = 0;
found++;
}
if (-occ > found)
return 0;
/* OK now we have the last occurrence in [hist_ptr-1], and we need to
* find occurrence -occ. 0 <= hist_ptr < MAX_HDR_HISTORY, and we have
* -10 <= occ <= -1. So we have to check [hist_ptr%MAX_HDR_HISTORY+occ]
* to remain in the 0..9 range.
*/
hist_ptr += occ + MAX_HDR_HISTORY;
if (hist_ptr >= MAX_HDR_HISTORY)
hist_ptr -= MAX_HDR_HISTORY;
*vptr = ptr_hist[hist_ptr];
*vlen = len_hist[hist_ptr];
return 1;
}
|
CWE-200
| 6,826 | 15,076 |
94449097079872291674707768535224131500
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
char *http_get_path(struct http_txn *txn)
{
char *ptr, *end;
ptr = txn->req.chn->buf->p + txn->req.sl.rq.u;
end = ptr + txn->req.sl.rq.u_l;
if (ptr >= end)
return NULL;
/* RFC7230, par. 2.7 :
* Request-URI = "*" | absuri | abspath | authority
*/
if (*ptr == '*')
return NULL;
if (isalpha((unsigned char)*ptr)) {
/* this is a scheme as described by RFC3986, par. 3.1 */
ptr++;
while (ptr < end &&
(isalnum((unsigned char)*ptr) || *ptr == '+' || *ptr == '-' || *ptr == '.'))
ptr++;
/* skip '://' */
if (ptr == end || *ptr++ != ':')
return NULL;
if (ptr == end || *ptr++ != '/')
return NULL;
if (ptr == end || *ptr++ != '/')
return NULL;
}
/* skip [user[:passwd]@]host[:[port]] */
while (ptr < end && *ptr != '/')
ptr++;
if (ptr == end)
return NULL;
/* OK, we got the '/' ! */
return ptr;
}
|
CWE-200
| 6,827 | 15,077 |
196652537585071668651682723868436950429
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
http_get_path_from_string(char *str)
{
char *ptr = str;
/* RFC2616, par. 5.1.2 :
* Request-URI = "*" | absuri | abspath | authority
*/
if (*ptr == '*')
return NULL;
if (isalpha((unsigned char)*ptr)) {
/* this is a scheme as described by RFC3986, par. 3.1 */
ptr++;
while (isalnum((unsigned char)*ptr) || *ptr == '+' || *ptr == '-' || *ptr == '.')
ptr++;
/* skip '://' */
if (*ptr == '\0' || *ptr++ != ':')
return NULL;
if (*ptr == '\0' || *ptr++ != '/')
return NULL;
if (*ptr == '\0' || *ptr++ != '/')
return NULL;
}
/* skip [user[:passwd]@]host[:[port]] */
while (*ptr != '\0' && *ptr != ' ' && *ptr != '/')
ptr++;
if (*ptr == '\0' || *ptr == ' ')
return NULL;
/* OK, we got the '/' ! */
return ptr;
}
|
CWE-200
| 6,828 | 15,078 |
229444230795946847470424572348092201411
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
static const int http_get_status_idx(unsigned int status)
{
switch (status) {
case 200: return HTTP_ERR_200;
case 400: return HTTP_ERR_400;
case 403: return HTTP_ERR_403;
case 405: return HTTP_ERR_405;
case 408: return HTTP_ERR_408;
case 425: return HTTP_ERR_425;
case 429: return HTTP_ERR_429;
case 500: return HTTP_ERR_500;
case 502: return HTTP_ERR_502;
case 503: return HTTP_ERR_503;
case 504: return HTTP_ERR_504;
default: return HTTP_ERR_500;
}
}
|
CWE-200
| 6,829 | 15,079 |
10831206232386119654325030618578214112
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_handle_stats(struct stream *s, struct channel *req)
{
struct stats_admin_rule *stats_admin_rule;
struct stream_interface *si = &s->si[1];
struct session *sess = s->sess;
struct http_txn *txn = s->txn;
struct http_msg *msg = &txn->req;
struct uri_auth *uri_auth = s->be->uri_auth;
const char *uri, *h, *lookup;
struct appctx *appctx;
appctx = si_appctx(si);
memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats));
appctx->st1 = appctx->st2 = 0;
appctx->ctx.stats.st_code = STAT_STATUS_INIT;
appctx->ctx.stats.flags |= STAT_FMT_HTML; /* assume HTML mode by default */
if ((msg->flags & HTTP_MSGF_VER_11) && (s->txn->meth != HTTP_METH_HEAD))
appctx->ctx.stats.flags |= STAT_CHUNKED;
uri = msg->chn->buf->p + msg->sl.rq.u;
lookup = uri + uri_auth->uri_len;
for (h = lookup; h <= uri + msg->sl.rq.u_l - 3; h++) {
if (memcmp(h, ";up", 3) == 0) {
appctx->ctx.stats.flags |= STAT_HIDE_DOWN;
break;
}
}
if (uri_auth->refresh) {
for (h = lookup; h <= uri + msg->sl.rq.u_l - 10; h++) {
if (memcmp(h, ";norefresh", 10) == 0) {
appctx->ctx.stats.flags |= STAT_NO_REFRESH;
break;
}
}
}
for (h = lookup; h <= uri + msg->sl.rq.u_l - 4; h++) {
if (memcmp(h, ";csv", 4) == 0) {
appctx->ctx.stats.flags &= ~STAT_FMT_HTML;
break;
}
}
for (h = lookup; h <= uri + msg->sl.rq.u_l - 6; h++) {
if (memcmp(h, ";typed", 6) == 0) {
appctx->ctx.stats.flags &= ~STAT_FMT_HTML;
appctx->ctx.stats.flags |= STAT_FMT_TYPED;
break;
}
}
for (h = lookup; h <= uri + msg->sl.rq.u_l - 8; h++) {
if (memcmp(h, ";st=", 4) == 0) {
int i;
h += 4;
appctx->ctx.stats.st_code = STAT_STATUS_UNKN;
for (i = STAT_STATUS_INIT + 1; i < STAT_STATUS_SIZE; i++) {
if (strncmp(stat_status_codes[i], h, 4) == 0) {
appctx->ctx.stats.st_code = i;
break;
}
}
break;
}
}
appctx->ctx.stats.scope_str = 0;
appctx->ctx.stats.scope_len = 0;
for (h = lookup; h <= uri + msg->sl.rq.u_l - 8; h++) {
if (memcmp(h, STAT_SCOPE_INPUT_NAME "=", strlen(STAT_SCOPE_INPUT_NAME) + 1) == 0) {
int itx = 0;
const char *h2;
char scope_txt[STAT_SCOPE_TXT_MAXLEN + 1];
const char *err;
h += strlen(STAT_SCOPE_INPUT_NAME) + 1;
h2 = h;
appctx->ctx.stats.scope_str = h2 - msg->chn->buf->p;
while (*h != ';' && *h != '\0' && *h != '&' && *h != ' ' && *h != '\n') {
itx++;
h++;
}
if (itx > STAT_SCOPE_TXT_MAXLEN)
itx = STAT_SCOPE_TXT_MAXLEN;
appctx->ctx.stats.scope_len = itx;
/* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
memcpy(scope_txt, h2, itx);
scope_txt[itx] = '\0';
err = invalid_char(scope_txt);
if (err) {
/* bad char in search text => clear scope */
appctx->ctx.stats.scope_str = 0;
appctx->ctx.stats.scope_len = 0;
}
break;
}
}
/* now check whether we have some admin rules for this request */
list_for_each_entry(stats_admin_rule, &uri_auth->admin_rules, list) {
int ret = 1;
if (stats_admin_rule->cond) {
ret = acl_exec_cond(stats_admin_rule->cond, s->be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (stats_admin_rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
}
if (ret) {
/* no rule, or the rule matches */
appctx->ctx.stats.flags |= STAT_ADMIN;
break;
}
}
/* Was the status page requested with a POST ? */
if (unlikely(txn->meth == HTTP_METH_POST && txn->req.body_len > 0)) {
if (appctx->ctx.stats.flags & STAT_ADMIN) {
/* we'll need the request body, possibly after sending 100-continue */
if (msg->msg_state < HTTP_MSG_CHUNK_SIZE)
req->analysers |= AN_REQ_HTTP_BODY;
appctx->st0 = STAT_HTTP_POST;
}
else {
appctx->ctx.stats.st_code = STAT_STATUS_DENY;
appctx->st0 = STAT_HTTP_LAST;
}
}
else {
/* So it was another method (GET/HEAD) */
appctx->st0 = STAT_HTTP_HEAD;
}
s->task->nice = -32; /* small boost for HTTP statistics */
return 1;
}
|
CWE-200
| 6,830 | 15,080 |
19462455139814291631228416497001240921
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_header_add_tail(struct http_msg *msg, struct hdr_idx *hdr_idx, const char *text)
{
int bytes, len;
len = strlen(text);
bytes = buffer_insert_line2(msg->chn->buf, msg->chn->buf->p + msg->eoh, text, len);
if (!bytes)
return -1;
http_msg_move_end(msg, bytes);
return hdr_idx_add(len, 1, hdr_idx, hdr_idx->tail);
}
|
CWE-200
| 6,831 | 15,081 |
146120320198028967903806457886213690490
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_header_add_tail2(struct http_msg *msg,
struct hdr_idx *hdr_idx, const char *text, int len)
{
int bytes;
bytes = buffer_insert_line2(msg->chn->buf, msg->chn->buf->p + msg->eoh, text, len);
if (!bytes)
return -1;
http_msg_move_end(msg, bytes);
return hdr_idx_add(len, 1, hdr_idx, hdr_idx->tail);
}
|
CWE-200
| 6,832 | 15,082 |
102463366260821745112324309579715156510
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_header_match2(const char *hdr, const char *end,
const char *name, int len)
{
const char *val;
if (hdr + len >= end)
return 0;
if (hdr[len] != ':')
return 0;
if (strncasecmp(hdr, name, len) != 0)
return 0;
val = hdr + len + 1;
while (val < end && HTTP_IS_SPHT(*val))
val++;
if ((val >= end) && (len + 2 <= end - hdr))
return len + 2; /* we may replace starting from second space */
return val - hdr;
}
|
CWE-200
| 6,833 | 15,083 |
15322567793324407769234772892379456688
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_init_txn(struct stream *s)
{
struct http_txn *txn = s->txn;
struct proxy *fe = strm_fe(s);
txn->flags = 0;
txn->status = -1;
txn->cookie_first_date = 0;
txn->cookie_last_date = 0;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;
txn->uri = NULL;
http_txn_reset_req(txn);
http_txn_reset_res(txn);
txn->req.chn = &s->req;
txn->rsp.chn = &s->res;
txn->auth.method = HTTP_AUTH_UNKNOWN;
txn->req.err_pos = txn->rsp.err_pos = -2; /* block buggy requests/responses */
if (fe->options2 & PR_O2_REQBUG_OK)
txn->req.err_pos = -1; /* let buggy requests pass */
if (txn->hdr_idx.v)
hdr_idx_init(&txn->hdr_idx);
vars_init(&s->vars_txn, SCOPE_TXN);
vars_init(&s->vars_reqres, SCOPE_REQ);
}
|
CWE-200
| 6,834 | 15,084 |
34551921403332550605655914918477912689
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
http_msg_forward_body(struct stream *s, struct http_msg *msg)
{
struct channel *chn = msg->chn;
int ret;
/* Here we have the guarantee to be in HTTP_MSG_DATA or HTTP_MSG_ENDING state */
if (msg->msg_state == HTTP_MSG_ENDING)
goto ending;
/* Neither content-length, nor transfer-encoding was found, so we must
* read the body until the server connection is closed. In that case, we
* eat data as they come. Of course, this happens for response only. */
if (!(msg->flags & HTTP_MSGF_XFER_LEN)) {
unsigned long long len = (chn->buf->i - msg->next);
msg->chunk_len += len;
msg->body_len += len;
}
ret = FLT_STRM_DATA_CB(s, chn, flt_http_data(s, msg),
/* default_ret */ MIN(msg->chunk_len, chn->buf->i - msg->next),
/* on_error */ goto error);
msg->next += ret;
msg->chunk_len -= ret;
if (msg->chunk_len) {
/* input empty or output full */
if (chn->buf->i > msg->next)
chn->flags |= CF_WAKE_WRITE;
goto missing_data_or_waiting;
}
/* This check can only be true for a response. HTTP_MSGF_XFER_LEN is
* always set for a request. */
if (!(msg->flags & HTTP_MSGF_XFER_LEN)) {
/* The server still sending data that should be filtered */
if (!(chn->flags & CF_SHUTR) && HAS_DATA_FILTERS(s, chn))
goto missing_data_or_waiting;
msg->msg_state = HTTP_MSG_TUNNEL;
goto ending;
}
msg->msg_state = HTTP_MSG_ENDING;
ending:
/* we may have some pending data starting at res->buf->p such as a last
* chunk of data or trailers. */
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
msg->next -= ret;
if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
msg->sov -= ret;
if (msg->next)
goto waiting;
FLT_STRM_DATA_CB(s, chn, flt_http_end(s, msg),
/* default_ret */ 1,
/* on_error */ goto error,
/* on_wait */ goto waiting);
if (msg->msg_state == HTTP_MSG_ENDING)
msg->msg_state = HTTP_MSG_DONE;
return 1;
missing_data_or_waiting:
/* we may have some pending data starting at chn->buf->p */
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
msg->next -= ret;
if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
msg->sov -= ret;
if (!HAS_DATA_FILTERS(s, chn))
msg->chunk_len -= channel_forward(chn, msg->chunk_len);
waiting:
return 0;
error:
return -1;
}
|
CWE-200
| 6,835 | 15,085 |
265708003994415523879617271696471573868
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
http_msg_forward_chunked_body(struct stream *s, struct http_msg *msg)
{
struct channel *chn = msg->chn;
unsigned int chunk;
int ret;
/* Here we have the guarantee to be in one of the following state:
* HTTP_MSG_DATA, HTTP_MSG_CHUNK_SIZE, HTTP_MSG_CHUNK_CRLF,
* HTTP_MSG_TRAILERS or HTTP_MSG_ENDING. */
switch_states:
switch (msg->msg_state) {
case HTTP_MSG_DATA:
ret = FLT_STRM_DATA_CB(s, chn, flt_http_data(s, msg),
/* default_ret */ MIN(msg->chunk_len, chn->buf->i - msg->next),
/* on_error */ goto error);
msg->next += ret;
msg->chunk_len -= ret;
if (msg->chunk_len) {
/* input empty or output full */
if (chn->buf->i > msg->next)
chn->flags |= CF_WAKE_WRITE;
goto missing_data_or_waiting;
}
/* nothing left to forward for this chunk*/
msg->msg_state = HTTP_MSG_CHUNK_CRLF;
/* fall through for HTTP_MSG_CHUNK_CRLF */
case HTTP_MSG_CHUNK_CRLF:
/* we want the CRLF after the data */
ret = h1_skip_chunk_crlf(chn->buf, msg->next, chn->buf->i);
if (ret == 0)
goto missing_data_or_waiting;
if (ret < 0) {
msg->err_pos = chn->buf->i + ret;
if (msg->err_pos < 0)
msg->err_pos += chn->buf->size;
goto chunk_parsing_error;
}
msg->next += ret;
msg->msg_state = HTTP_MSG_CHUNK_SIZE;
/* fall through for HTTP_MSG_CHUNK_SIZE */
case HTTP_MSG_CHUNK_SIZE:
/* read the chunk size and assign it to ->chunk_len,
* then set ->next to point to the body and switch to
* DATA or TRAILERS state.
*/
ret = h1_parse_chunk_size(chn->buf, msg->next, chn->buf->i, &chunk);
if (ret == 0)
goto missing_data_or_waiting;
if (ret < 0) {
msg->err_pos = chn->buf->i + ret;
if (msg->err_pos < 0)
msg->err_pos += chn->buf->size;
goto chunk_parsing_error;
}
msg->sol = ret;
msg->next += ret;
msg->chunk_len = chunk;
msg->body_len += chunk;
if (msg->chunk_len) {
msg->msg_state = HTTP_MSG_DATA;
goto switch_states;
}
msg->msg_state = HTTP_MSG_TRAILERS;
/* fall through for HTTP_MSG_TRAILERS */
case HTTP_MSG_TRAILERS:
ret = http_forward_trailers(msg);
if (ret < 0)
goto chunk_parsing_error;
FLT_STRM_DATA_CB(s, chn, flt_http_chunk_trailers(s, msg),
/* default_ret */ 1,
/* on_error */ goto error);
msg->next += msg->sol;
if (!ret)
goto missing_data_or_waiting;
break;
case HTTP_MSG_ENDING:
goto ending;
default:
/* This should no happen in this function */
goto error;
}
msg->msg_state = HTTP_MSG_ENDING;
ending:
/* we may have some pending data starting at res->buf->p such as a last
* chunk of data or trailers. */
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
msg->next -= ret;
if (unlikely(!(chn->flags & CF_WROTE_DATA) || msg->sov > 0))
msg->sov -= ret;
if (msg->next)
goto waiting;
FLT_STRM_DATA_CB(s, chn, flt_http_end(s, msg),
/* default_ret */ 1,
/* on_error */ goto error,
/* on_wait */ goto waiting);
msg->msg_state = HTTP_MSG_DONE;
return 1;
missing_data_or_waiting:
/* we may have some pending data starting at chn->buf->p */
ret = FLT_STRM_DATA_CB(s, chn, flt_http_forward_data(s, msg, msg->next),
/* default_ret */ msg->next,
/* on_error */ goto error);
b_adv(chn->buf, ret);
msg->next -= ret;
if (!(chn->flags & CF_WROTE_DATA) || msg->sov > 0)
msg->sov -= ret;
if (!HAS_DATA_FILTERS(s, chn))
msg->chunk_len -= channel_forward(chn, msg->chunk_len);
waiting:
return 0;
chunk_parsing_error:
if (msg->err_pos >= 0) {
if (chn->flags & CF_ISRESP)
http_capture_bad_message(s->be, &s->be->invalid_rep, s, msg,
msg->msg_state, strm_fe(s));
else
http_capture_bad_message(strm_fe(s), &strm_fe(s)->invalid_req, s,
msg, msg->msg_state, s->be);
}
error:
return -1;
}
|
CWE-200
| 6,836 | 15,086 |
203920141053787010451098574343055464545
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_parse_connection_header(struct http_txn *txn, struct http_msg *msg, int to_del)
{
struct hdr_ctx ctx;
const char *hdr_val = "Connection";
int hdr_len = 10;
if (txn->flags & TX_HDR_CONN_PRS)
return;
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
hdr_val = "Proxy-Connection";
hdr_len = 16;
}
ctx.idx = 0;
txn->flags &= ~(TX_CON_KAL_SET|TX_CON_CLO_SET);
while (http_find_header2(hdr_val, hdr_len, msg->chn->buf->p, &txn->hdr_idx, &ctx)) {
if (ctx.vlen >= 10 && word_match(ctx.line + ctx.val, ctx.vlen, "keep-alive", 10)) {
txn->flags |= TX_HDR_CONN_KAL;
if (to_del & 2)
http_remove_header2(msg, &txn->hdr_idx, &ctx);
else
txn->flags |= TX_CON_KAL_SET;
}
else if (ctx.vlen >= 5 && word_match(ctx.line + ctx.val, ctx.vlen, "close", 5)) {
txn->flags |= TX_HDR_CONN_CLO;
if (to_del & 1)
http_remove_header2(msg, &txn->hdr_idx, &ctx);
else
txn->flags |= TX_CON_CLO_SET;
}
else if (ctx.vlen >= 7 && word_match(ctx.line + ctx.val, ctx.vlen, "upgrade", 7)) {
txn->flags |= TX_HDR_CONN_UPG;
}
}
txn->flags |= TX_HDR_CONN_PRS;
return;
}
|
CWE-200
| 6,837 | 15,087 |
112942969931713937681675038269282243895
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, struct proxy *curproxy,
const char **args, char **errmsg, int use_fmt, int dir)
{
struct redirect_rule *rule;
int cur_arg;
int type = REDIRECT_TYPE_NONE;
int code = 302;
const char *destination = NULL;
const char *cookie = NULL;
int cookie_set = 0;
unsigned int flags = REDIRECT_FLAG_NONE;
struct acl_cond *cond = NULL;
cur_arg = 0;
while (*(args[cur_arg])) {
if (strcmp(args[cur_arg], "location") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
type = REDIRECT_TYPE_LOCATION;
cur_arg++;
destination = args[cur_arg];
}
else if (strcmp(args[cur_arg], "prefix") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
type = REDIRECT_TYPE_PREFIX;
cur_arg++;
destination = args[cur_arg];
}
else if (strcmp(args[cur_arg], "scheme") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
type = REDIRECT_TYPE_SCHEME;
cur_arg++;
destination = args[cur_arg];
}
else if (strcmp(args[cur_arg], "set-cookie") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
cur_arg++;
cookie = args[cur_arg];
cookie_set = 1;
}
else if (strcmp(args[cur_arg], "clear-cookie") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
cur_arg++;
cookie = args[cur_arg];
cookie_set = 0;
}
else if (strcmp(args[cur_arg], "code") == 0) {
if (!*args[cur_arg + 1])
goto missing_arg;
cur_arg++;
code = atol(args[cur_arg]);
if (code < 301 || code > 308 || (code > 303 && code < 307)) {
memprintf(errmsg,
"'%s': unsupported HTTP code '%s' (must be one of 301, 302, 303, 307 or 308)",
args[cur_arg - 1], args[cur_arg]);
return NULL;
}
}
else if (!strcmp(args[cur_arg],"drop-query")) {
flags |= REDIRECT_FLAG_DROP_QS;
}
else if (!strcmp(args[cur_arg],"append-slash")) {
flags |= REDIRECT_FLAG_APPEND_SLASH;
}
else if (strcmp(args[cur_arg], "if") == 0 ||
strcmp(args[cur_arg], "unless") == 0) {
cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + cur_arg, errmsg);
if (!cond) {
memprintf(errmsg, "error in condition: %s", *errmsg);
return NULL;
}
break;
}
else {
memprintf(errmsg,
"expects 'code', 'prefix', 'location', 'scheme', 'set-cookie', 'clear-cookie', 'drop-query' or 'append-slash' (was '%s')",
args[cur_arg]);
return NULL;
}
cur_arg++;
}
if (type == REDIRECT_TYPE_NONE) {
memprintf(errmsg, "redirection type expected ('prefix', 'location', or 'scheme')");
return NULL;
}
if (dir && type != REDIRECT_TYPE_LOCATION) {
memprintf(errmsg, "response only supports redirect type 'location'");
return NULL;
}
rule = calloc(1, sizeof(*rule));
rule->cond = cond;
LIST_INIT(&rule->rdr_fmt);
if (!use_fmt) {
/* old-style static redirect rule */
rule->rdr_str = strdup(destination);
rule->rdr_len = strlen(destination);
}
else {
/* log-format based redirect rule */
/* Parse destination. Note that in the REDIRECT_TYPE_PREFIX case,
* if prefix == "/", we don't want to add anything, otherwise it
* makes it hard for the user to configure a self-redirection.
*/
curproxy->conf.args.ctx = ARGC_RDR;
if (!(type == REDIRECT_TYPE_PREFIX && destination[0] == '/' && destination[1] == '\0')) {
if (!parse_logformat_string(destination, curproxy, &rule->rdr_fmt, LOG_OPT_HTTP,
dir ? (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRS_HDR : SMP_VAL_BE_HRS_HDR
: (curproxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR,
errmsg)) {
return NULL;
}
free(curproxy->conf.lfs_file);
curproxy->conf.lfs_file = strdup(curproxy->conf.args.file);
curproxy->conf.lfs_line = curproxy->conf.args.line;
}
}
if (cookie) {
/* depending on cookie_set, either we want to set the cookie, or to clear it.
* a clear consists in appending "; path=/; Max-Age=0;" at the end.
*/
rule->cookie_len = strlen(cookie);
if (cookie_set) {
rule->cookie_str = malloc(rule->cookie_len + 10);
memcpy(rule->cookie_str, cookie, rule->cookie_len);
memcpy(rule->cookie_str + rule->cookie_len, "; path=/;", 10);
rule->cookie_len += 9;
} else {
rule->cookie_str = malloc(rule->cookie_len + 21);
memcpy(rule->cookie_str, cookie, rule->cookie_len);
memcpy(rule->cookie_str + rule->cookie_len, "; path=/; Max-Age=0;", 21);
rule->cookie_len += 20;
}
}
rule->type = type;
rule->code = code;
rule->flags = flags;
LIST_INIT(&rule->list);
return rule;
missing_arg:
memprintf(errmsg, "missing argument for '%s'", args[cur_arg]);
return NULL;
}
|
CWE-200
| 6,838 | 15,088 |
18474157574149824647483747772137508201
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
void http_perform_server_redirect(struct stream *s, struct stream_interface *si)
{
struct http_txn *txn;
struct server *srv;
char *path;
int len, rewind;
/* 1: create the response header */
trash.len = strlen(HTTP_302);
memcpy(trash.str, HTTP_302, trash.len);
srv = objt_server(s->target);
/* 2: add the server's prefix */
if (trash.len + srv->rdr_len > trash.size)
return;
/* special prefix "/" means don't change URL */
if (srv->rdr_len != 1 || *srv->rdr_pfx != '/') {
memcpy(trash.str + trash.len, srv->rdr_pfx, srv->rdr_len);
trash.len += srv->rdr_len;
}
/* 3: add the request URI. Since it was already forwarded, we need
* to temporarily rewind the buffer.
*/
txn = s->txn;
b_rew(s->req.buf, rewind = http_hdr_rewind(&txn->req));
path = http_get_path(txn);
len = buffer_count(s->req.buf, path, b_ptr(s->req.buf, txn->req.sl.rq.u + txn->req.sl.rq.u_l));
b_adv(s->req.buf, rewind);
if (!path)
return;
if (trash.len + len > trash.size - 4) /* 4 for CRLF-CRLF */
return;
memcpy(trash.str + trash.len, path, len);
trash.len += len;
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
memcpy(trash.str + trash.len, "\r\nProxy-Connection: close\r\n\r\n", 29);
trash.len += 29;
} else {
memcpy(trash.str + trash.len, "\r\nConnection: close\r\n\r\n", 23);
trash.len += 23;
}
/* prepare to return without error. */
si_shutr(si);
si_shutw(si);
si->err_type = SI_ET_NONE;
si->state = SI_ST_CLO;
/* send the message */
txn->status = 302;
http_server_error(s, si, SF_ERR_LOCAL, SF_FINST_C, &trash);
/* FIXME: we should increase a counter of redirects per server and per backend. */
srv_inc_sess_ctr(srv);
srv_set_sess_last(srv);
}
|
CWE-200
| 6,839 | 15,089 |
77693981790331082682333229817457137349
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_process_req_common(struct stream *s, struct channel *req, int an_bit, struct proxy *px)
{
struct session *sess = s->sess;
struct http_txn *txn = s->txn;
struct http_msg *msg = &txn->req;
struct redirect_rule *rule;
struct cond_wordlist *wl;
enum rule_result verdict;
int deny_status = HTTP_ERR_403;
struct connection *conn = objt_conn(sess->origin);
if (unlikely(msg->msg_state < HTTP_MSG_BODY)) {
/* we need more data */
goto return_prx_yield;
}
DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
now_ms, __FUNCTION__,
s,
req,
req->rex, req->wex,
req->flags,
req->buf->i,
req->analysers);
/* just in case we have some per-backend tracking */
stream_inc_be_http_req_ctr(s);
/* evaluate http-request rules */
if (!LIST_ISEMPTY(&px->http_req_rules)) {
verdict = http_req_get_intercept_rule(px, &px->http_req_rules, s, &deny_status);
switch (verdict) {
case HTTP_RULE_RES_YIELD: /* some data miss, call the function later. */
goto return_prx_yield;
case HTTP_RULE_RES_CONT:
case HTTP_RULE_RES_STOP: /* nothing to do */
break;
case HTTP_RULE_RES_DENY: /* deny or tarpit */
if (txn->flags & TX_CLTARPIT)
goto tarpit;
goto deny;
case HTTP_RULE_RES_ABRT: /* abort request, response already sent. Eg: auth */
goto return_prx_cond;
case HTTP_RULE_RES_DONE: /* OK, but terminate request processing (eg: redirect) */
goto done;
case HTTP_RULE_RES_BADREQ: /* failed with a bad request */
goto return_bad_req;
}
}
if (conn && conn->flags & CO_FL_EARLY_DATA) {
struct hdr_ctx ctx;
ctx.idx = 0;
if (!http_find_header2("Early-Data", strlen("Early-Data"),
s->req.buf->p, &txn->hdr_idx, &ctx)) {
if (unlikely(http_header_add_tail2(&txn->req,
&txn->hdr_idx, "Early-Data: 1",
strlen("Early-Data: 1"))) < 0) {
goto return_bad_req;
}
}
}
/* OK at this stage, we know that the request was accepted according to
* the http-request rules, we can check for the stats. Note that the
* URI is detected *before* the req* rules in order not to be affected
* by a possible reqrep, while they are processed *after* so that a
* reqdeny can still block them. This clearly needs to change in 1.6!
*/
if (stats_check_uri(&s->si[1], txn, px)) {
s->target = &http_stats_applet.obj_type;
if (unlikely(!stream_int_register_handler(&s->si[1], objt_applet(s->target)))) {
txn->status = 500;
s->logs.tv_request = now;
http_reply_and_close(s, txn->status, http_error_message(s));
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;
goto return_prx_cond;
}
/* parse the whole stats request and extract the relevant information */
http_handle_stats(s, req);
verdict = http_req_get_intercept_rule(px, &px->uri_auth->http_req_rules, s, &deny_status);
/* not all actions implemented: deny, allow, auth */
if (verdict == HTTP_RULE_RES_DENY) /* stats http-request deny */
goto deny;
if (verdict == HTTP_RULE_RES_ABRT) /* stats auth / stats http-request auth */
goto return_prx_cond;
}
/* evaluate the req* rules except reqadd */
if (px->req_exp != NULL) {
if (apply_filters_to_request(s, req, px) < 0)
goto return_bad_req;
if (txn->flags & TX_CLDENY)
goto deny;
if (txn->flags & TX_CLTARPIT) {
deny_status = HTTP_ERR_500;
goto tarpit;
}
}
/* add request headers from the rule sets in the same order */
list_for_each_entry(wl, &px->req_add, list) {
if (wl->cond) {
int ret = acl_exec_cond(wl->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (((struct acl_cond *)wl->cond)->pol == ACL_COND_UNLESS)
ret = !ret;
if (!ret)
continue;
}
if (unlikely(http_header_add_tail(&txn->req, &txn->hdr_idx, wl->s) < 0))
goto return_bad_req;
}
/* Proceed with the stats now. */
if (unlikely(objt_applet(s->target) == &http_stats_applet) ||
unlikely(objt_applet(s->target) == &http_cache_applet)) {
/* process the stats request now */
if (sess->fe == s->be) /* report it if the request was intercepted by the frontend */
HA_ATOMIC_ADD(&sess->fe->fe_counters.intercepted_req, 1);
if (!(s->flags & SF_ERR_MASK)) // this is not really an error but it is
s->flags |= SF_ERR_LOCAL; // to mark that it comes from the proxy
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
/* enable the minimally required analyzers to handle keep-alive and compression on the HTTP response */
req->analysers &= (AN_REQ_HTTP_BODY | AN_REQ_FLT_HTTP_HDRS | AN_REQ_FLT_END);
req->analysers &= ~AN_REQ_FLT_XFER_DATA;
req->analysers |= AN_REQ_HTTP_XFER_BODY;
goto done;
}
/* check whether we have some ACLs set to redirect this request */
list_for_each_entry(rule, &px->redirect_rules, list) {
if (rule->cond) {
int ret;
ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
if (!ret)
continue;
}
if (!http_apply_redirect_rule(rule, s, txn))
goto return_bad_req;
goto done;
}
/* POST requests may be accompanied with an "Expect: 100-Continue" header.
* If this happens, then the data will not come immediately, so we must
* send all what we have without waiting. Note that due to the small gain
* in waiting for the body of the request, it's easier to simply put the
* CF_SEND_DONTWAIT flag any time. It's a one-shot flag so it will remove
* itself once used.
*/
req->flags |= CF_SEND_DONTWAIT;
done: /* done with this analyser, continue with next ones that the calling
* points will have set, if any.
*/
req->analyse_exp = TICK_ETERNITY;
done_without_exp: /* done with this analyser, but dont reset the analyse_exp. */
req->analysers &= ~an_bit;
return 1;
tarpit:
/* Allow cookie logging
*/
if (s->be->cookie_name || sess->fe->capture_name)
manage_client_side_cookies(s, req);
/* When a connection is tarpitted, we use the tarpit timeout,
* which may be the same as the connect timeout if unspecified.
* If unset, then set it to zero because we really want it to
* eventually expire. We build the tarpit as an analyser.
*/
channel_erase(&s->req);
/* wipe the request out so that we can drop the connection early
* if the client closes first.
*/
channel_dont_connect(req);
txn->status = http_err_codes[deny_status];
req->analysers &= AN_REQ_FLT_END; /* remove switching rules etc... */
req->analysers |= AN_REQ_HTTP_TARPIT;
req->analyse_exp = tick_add_ifset(now_ms, s->be->timeout.tarpit);
if (!req->analyse_exp)
req->analyse_exp = tick_add(now_ms, 0);
stream_inc_http_err_ctr(s);
HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
if (sess->fe != s->be)
HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
if (sess->listener->counters)
HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
goto done_without_exp;
deny: /* this request was blocked (denied) */
/* Allow cookie logging
*/
if (s->be->cookie_name || sess->fe->capture_name)
manage_client_side_cookies(s, req);
txn->flags |= TX_CLDENY;
txn->status = http_err_codes[deny_status];
s->logs.tv_request = now;
http_reply_and_close(s, txn->status, http_error_message(s));
stream_inc_http_err_ctr(s);
HA_ATOMIC_ADD(&sess->fe->fe_counters.denied_req, 1);
if (sess->fe != s->be)
HA_ATOMIC_ADD(&s->be->be_counters.denied_req, 1);
if (sess->listener->counters)
HA_ATOMIC_ADD(&sess->listener->counters->denied_req, 1);
goto return_prx_cond;
return_bad_req:
/* We centralize bad requests processing here */
if (unlikely(msg->msg_state == HTTP_MSG_ERROR) || msg->err_pos >= 0) {
/* we detected a parsing error. We want to archive this request
* in the dedicated proxy area for later troubleshooting.
*/
http_capture_bad_message(sess->fe, &sess->fe->invalid_req, s, msg, msg->err_state, sess->fe);
}
txn->req.err_state = txn->req.msg_state;
txn->req.msg_state = HTTP_MSG_ERROR;
txn->status = 400;
http_reply_and_close(s, txn->status, http_error_message(s));
HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_req, 1);
if (sess->listener->counters)
HA_ATOMIC_ADD(&sess->listener->counters->failed_req, 1);
return_prx_cond:
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_PRXCOND;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
req->analysers &= AN_REQ_FLT_END;
req->analyse_exp = TICK_ETERNITY;
return 0;
return_prx_yield:
channel_dont_connect(req);
return 0;
}
|
CWE-200
| 6,840 | 15,090 |
172997613743901798885522909303385510002
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_process_request(struct stream *s, struct channel *req, int an_bit)
{
struct session *sess = s->sess;
struct http_txn *txn = s->txn;
struct http_msg *msg = &txn->req;
struct connection *cli_conn = objt_conn(strm_sess(s)->origin);
if (unlikely(msg->msg_state < HTTP_MSG_BODY)) {
/* we need more data */
channel_dont_connect(req);
return 0;
}
DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
now_ms, __FUNCTION__,
s,
req,
req->rex, req->wex,
req->flags,
req->buf->i,
req->analysers);
/*
* Right now, we know that we have processed the entire headers
* and that unwanted requests have been filtered out. We can do
* whatever we want with the remaining request. Also, now we
* may have separate values for ->fe, ->be.
*/
/*
* If HTTP PROXY is set we simply get remote server address parsing
* incoming request. Note that this requires that a connection is
* allocated on the server side.
*/
if ((s->be->options & PR_O_HTTP_PROXY) && !(s->flags & SF_ADDR_SET)) {
struct connection *conn;
char *path;
/* Note that for now we don't reuse existing proxy connections */
if (unlikely((conn = cs_conn(si_alloc_cs(&s->si[1], NULL))) == NULL)) {
txn->req.err_state = txn->req.msg_state;
txn->req.msg_state = HTTP_MSG_ERROR;
txn->status = 500;
req->analysers &= AN_REQ_FLT_END;
http_reply_and_close(s, txn->status, http_error_message(s));
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
return 0;
}
path = http_get_path(txn);
if (url2sa(req->buf->p + msg->sl.rq.u,
path ? path - (req->buf->p + msg->sl.rq.u) : msg->sl.rq.u_l,
&conn->addr.to, NULL) == -1)
goto return_bad_req;
/* if the path was found, we have to remove everything between
* req->buf->p + msg->sl.rq.u and path (excluded). If it was not
* found, we need to replace from req->buf->p + msg->sl.rq.u for
* u_l characters by a single "/".
*/
if (path) {
char *cur_ptr = req->buf->p;
char *cur_end = cur_ptr + txn->req.sl.rq.l;
int delta;
delta = buffer_replace2(req->buf, req->buf->p + msg->sl.rq.u, path, NULL, 0);
http_msg_move_end(&txn->req, delta);
cur_end += delta;
if (http_parse_reqline(&txn->req, HTTP_MSG_RQMETH, cur_ptr, cur_end + 1, NULL, NULL) == NULL)
goto return_bad_req;
}
else {
char *cur_ptr = req->buf->p;
char *cur_end = cur_ptr + txn->req.sl.rq.l;
int delta;
delta = buffer_replace2(req->buf, req->buf->p + msg->sl.rq.u,
req->buf->p + msg->sl.rq.u + msg->sl.rq.u_l, "/", 1);
http_msg_move_end(&txn->req, delta);
cur_end += delta;
if (http_parse_reqline(&txn->req, HTTP_MSG_RQMETH, cur_ptr, cur_end + 1, NULL, NULL) == NULL)
goto return_bad_req;
}
}
/*
* 7: Now we can work with the cookies.
* Note that doing so might move headers in the request, but
* the fields will stay coherent and the URI will not move.
* This should only be performed in the backend.
*/
if (s->be->cookie_name || sess->fe->capture_name)
manage_client_side_cookies(s, req);
/* add unique-id if "header-unique-id" is specified */
if (!LIST_ISEMPTY(&sess->fe->format_unique_id) && !s->unique_id) {
if ((s->unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
goto return_bad_req;
s->unique_id[0] = '\0';
build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id);
}
if (sess->fe->header_unique_id && s->unique_id) {
chunk_printf(&trash, "%s: %s", sess->fe->header_unique_id, s->unique_id);
if (trash.len < 0)
goto return_bad_req;
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, trash.len) < 0))
goto return_bad_req;
}
/*
* 9: add X-Forwarded-For if either the frontend or the backend
* asks for it.
*/
if ((sess->fe->options | s->be->options) & PR_O_FWDFOR) {
struct hdr_ctx ctx = { .idx = 0 };
if (!((sess->fe->options | s->be->options) & PR_O_FF_ALWAYS) &&
http_find_header2(s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_name : sess->fe->fwdfor_hdr_name,
s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_len : sess->fe->fwdfor_hdr_len,
req->buf->p, &txn->hdr_idx, &ctx)) {
/* The header is set to be added only if none is present
* and we found it, so don't do anything.
*/
}
else if (cli_conn && cli_conn->addr.from.ss_family == AF_INET) {
/* Add an X-Forwarded-For header unless the source IP is
* in the 'except' network range.
*/
if ((!sess->fe->except_mask.s_addr ||
(((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr & sess->fe->except_mask.s_addr)
!= sess->fe->except_net.s_addr) &&
(!s->be->except_mask.s_addr ||
(((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr & s->be->except_mask.s_addr)
!= s->be->except_net.s_addr)) {
int len;
unsigned char *pn;
pn = (unsigned char *)&((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr;
/* Note: we rely on the backend to get the header name to be used for
* x-forwarded-for, because the header is really meant for the backends.
* However, if the backend did not specify any option, we have to rely
* on the frontend's header name.
*/
if (s->be->fwdfor_hdr_len) {
len = s->be->fwdfor_hdr_len;
memcpy(trash.str, s->be->fwdfor_hdr_name, len);
} else {
len = sess->fe->fwdfor_hdr_len;
memcpy(trash.str, sess->fe->fwdfor_hdr_name, len);
}
len += snprintf(trash.str + len, trash.size - len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
goto return_bad_req;
}
}
else if (cli_conn && cli_conn->addr.from.ss_family == AF_INET6) {
/* FIXME: for the sake of completeness, we should also support
* 'except' here, although it is mostly useless in this case.
*/
int len;
char pn[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6,
(const void *)&((struct sockaddr_in6 *)(&cli_conn->addr.from))->sin6_addr,
pn, sizeof(pn));
/* Note: we rely on the backend to get the header name to be used for
* x-forwarded-for, because the header is really meant for the backends.
* However, if the backend did not specify any option, we have to rely
* on the frontend's header name.
*/
if (s->be->fwdfor_hdr_len) {
len = s->be->fwdfor_hdr_len;
memcpy(trash.str, s->be->fwdfor_hdr_name, len);
} else {
len = sess->fe->fwdfor_hdr_len;
memcpy(trash.str, sess->fe->fwdfor_hdr_name, len);
}
len += snprintf(trash.str + len, trash.size - len, ": %s", pn);
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
goto return_bad_req;
}
}
/*
* 10: add X-Original-To if either the frontend or the backend
* asks for it.
*/
if ((sess->fe->options | s->be->options) & PR_O_ORGTO) {
/* FIXME: don't know if IPv6 can handle that case too. */
if (cli_conn && cli_conn->addr.from.ss_family == AF_INET) {
/* Add an X-Original-To header unless the destination IP is
* in the 'except' network range.
*/
conn_get_to_addr(cli_conn);
if (cli_conn->addr.to.ss_family == AF_INET &&
((!sess->fe->except_mask_to.s_addr ||
(((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr.s_addr & sess->fe->except_mask_to.s_addr)
!= sess->fe->except_to.s_addr) &&
(!s->be->except_mask_to.s_addr ||
(((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr.s_addr & s->be->except_mask_to.s_addr)
!= s->be->except_to.s_addr))) {
int len;
unsigned char *pn;
pn = (unsigned char *)&((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr;
/* Note: we rely on the backend to get the header name to be used for
* x-original-to, because the header is really meant for the backends.
* However, if the backend did not specify any option, we have to rely
* on the frontend's header name.
*/
if (s->be->orgto_hdr_len) {
len = s->be->orgto_hdr_len;
memcpy(trash.str, s->be->orgto_hdr_name, len);
} else {
len = sess->fe->orgto_hdr_len;
memcpy(trash.str, sess->fe->orgto_hdr_name, len);
}
len += snprintf(trash.str + len, trash.size - len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
goto return_bad_req;
}
}
}
/* 11: add "Connection: close" or "Connection: keep-alive" if needed and not yet set.
* If an "Upgrade" token is found, the header is left untouched in order not to have
* to deal with some servers bugs : some of them fail an Upgrade if anything but
* "Upgrade" is present in the Connection header.
*/
if (!(txn->flags & TX_HDR_CONN_UPG) &&
(((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) ||
((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))) {
unsigned int want_flags = 0;
if (msg->flags & HTTP_MSGF_VER_11) {
if (((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL ||
((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
(s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)) &&
!((sess->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
want_flags |= TX_CON_CLO_SET;
} else {
if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL &&
((sess->fe->options & PR_O_HTTP_MODE) != PR_O_HTTP_PCL &&
(s->be->options & PR_O_HTTP_MODE) != PR_O_HTTP_PCL)) ||
((sess->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
want_flags |= TX_CON_KAL_SET;
}
if (want_flags != (txn->flags & (TX_CON_CLO_SET|TX_CON_KAL_SET)))
http_change_connection_header(txn, msg, want_flags);
}
/* If we have no server assigned yet and we're balancing on url_param
* with a POST request, we may be interested in checking the body for
* that parameter. This will be done in another analyser.
*/
if (!(s->flags & (SF_ASSIGNED|SF_DIRECT)) &&
s->txn->meth == HTTP_METH_POST && s->be->url_param_name != NULL &&
(msg->flags & (HTTP_MSGF_CNT_LEN|HTTP_MSGF_TE_CHNK))) {
channel_dont_connect(req);
req->analysers |= AN_REQ_HTTP_BODY;
}
req->analysers &= ~AN_REQ_FLT_XFER_DATA;
req->analysers |= AN_REQ_HTTP_XFER_BODY;
#ifdef TCP_QUICKACK
/* We expect some data from the client. Unless we know for sure
* we already have a full request, we have to re-enable quick-ack
* in case we previously disabled it, otherwise we might cause
* the client to delay further data.
*/
if ((sess->listener->options & LI_O_NOQUICKACK) &&
cli_conn && conn_ctrl_ready(cli_conn) &&
((msg->flags & HTTP_MSGF_TE_CHNK) ||
(msg->body_len > req->buf->i - txn->req.eoh - 2)))
setsockopt(cli_conn->handle.fd, IPPROTO_TCP, TCP_QUICKACK, &one, sizeof(one));
#endif
/*************************************************************
* OK, that's finished for the headers. We have done what we *
* could. Let's switch to the DATA state. *
************************************************************/
req->analyse_exp = TICK_ETERNITY;
req->analysers &= ~an_bit;
s->logs.tv_request = now;
/* OK let's go on with the BODY now */
return 1;
return_bad_req: /* let's centralize all bad requests */
if (unlikely(msg->msg_state == HTTP_MSG_ERROR) || msg->err_pos >= 0) {
/* we detected a parsing error. We want to archive this request
* in the dedicated proxy area for later troubleshooting.
*/
http_capture_bad_message(sess->fe, &sess->fe->invalid_req, s, msg, msg->err_state, sess->fe);
}
txn->req.err_state = txn->req.msg_state;
txn->req.msg_state = HTTP_MSG_ERROR;
txn->status = 400;
req->analysers &= AN_REQ_FLT_END;
http_reply_and_close(s, txn->status, http_error_message(s));
HA_ATOMIC_ADD(&sess->fe->fe_counters.failed_req, 1);
if (sess->listener->counters)
HA_ATOMIC_ADD(&sess->listener->counters->failed_req, 1);
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_PRXCOND;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_R;
return 0;
}
|
CWE-200
| 6,841 | 15,091 |
6525516534694956220935252879103556252
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_process_tarpit(struct stream *s, struct channel *req, int an_bit)
{
struct http_txn *txn = s->txn;
/* This connection is being tarpitted. The CLIENT side has
* already set the connect expiration date to the right
* timeout. We just have to check that the client is still
* there and that the timeout has not expired.
*/
channel_dont_connect(req);
if ((req->flags & (CF_SHUTR|CF_READ_ERROR)) == 0 &&
!tick_is_expired(req->analyse_exp, now_ms))
return 0;
/* We will set the queue timer to the time spent, just for
* logging purposes. We fake a 500 server error, so that the
* attacker will not suspect his connection has been tarpitted.
* It will not cause trouble to the logs because we can exclude
* the tarpitted connections by filtering on the 'PT' status flags.
*/
s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
if (!(req->flags & CF_READ_ERROR))
http_reply_and_close(s, txn->status, http_error_message(s));
req->analysers &= AN_REQ_FLT_END;
req->analyse_exp = TICK_ETERNITY;
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_PRXCOND;
if (!(s->flags & SF_FINST_MASK))
s->flags |= SF_FINST_T;
return 0;
}
|
CWE-200
| 6,843 | 15,092 |
246519527474549662212671925080738597879
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_remove_header2(struct http_msg *msg, struct hdr_idx *idx, struct hdr_ctx *ctx)
{
int cur_idx = ctx->idx;
char *sol = ctx->line;
struct hdr_idx_elem *hdr;
int delta, skip_comma;
if (!cur_idx)
return 0;
hdr = &idx->v[cur_idx];
if (sol[ctx->del] == ':' && ctx->val + ctx->vlen + ctx->tws == hdr->len) {
/* This was the only value of the header, we must now remove it entirely. */
delta = buffer_replace2(msg->chn->buf, sol, sol + hdr->len + hdr->cr + 1, NULL, 0);
http_msg_move_end(msg, delta);
idx->used--;
hdr->len = 0; /* unused entry */
idx->v[ctx->prev].next = idx->v[ctx->idx].next;
if (idx->tail == ctx->idx)
idx->tail = ctx->prev;
ctx->idx = ctx->prev; /* walk back to the end of previous header */
ctx->line -= idx->v[ctx->idx].len + idx->v[ctx->idx].cr + 1;
ctx->val = idx->v[ctx->idx].len; /* point to end of previous header */
ctx->tws = ctx->vlen = 0;
return ctx->idx;
}
/* This was not the only value of this header. We have to remove between
* ctx->del+1 and ctx->val+ctx->vlen+ctx->tws+1 included. If it is the
* last entry of the list, we remove the last separator.
*/
skip_comma = (ctx->val + ctx->vlen + ctx->tws == hdr->len) ? 0 : 1;
delta = buffer_replace2(msg->chn->buf, sol + ctx->del + skip_comma,
sol + ctx->val + ctx->vlen + ctx->tws + skip_comma,
NULL, 0);
hdr->len += delta;
http_msg_move_end(msg, delta);
ctx->val = ctx->del;
ctx->tws = ctx->vlen = 0;
return ctx->idx;
}
|
CWE-200
| 6,844 | 15,093 |
198912169496856488933939953672096634198
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
int http_replace_req_line(int action, const char *replace, int len,
struct proxy *px, struct stream *s)
{
struct http_txn *txn = s->txn;
char *cur_ptr, *cur_end;
int offset = 0;
int delta;
switch (action) {
case 0: // method
cur_ptr = s->req.buf->p;
cur_end = cur_ptr + txn->req.sl.rq.m_l;
/* adjust req line offsets and lengths */
delta = len - offset - (cur_end - cur_ptr);
txn->req.sl.rq.m_l += delta;
txn->req.sl.rq.u += delta;
txn->req.sl.rq.v += delta;
break;
case 1: // path
cur_ptr = http_get_path(txn);
if (!cur_ptr)
cur_ptr = s->req.buf->p + txn->req.sl.rq.u;
cur_end = cur_ptr;
while (cur_end < s->req.buf->p + txn->req.sl.rq.u + txn->req.sl.rq.u_l && *cur_end != '?')
cur_end++;
/* adjust req line offsets and lengths */
delta = len - offset - (cur_end - cur_ptr);
txn->req.sl.rq.u_l += delta;
txn->req.sl.rq.v += delta;
break;
case 2: // query
offset = 1;
cur_ptr = s->req.buf->p + txn->req.sl.rq.u;
cur_end = cur_ptr + txn->req.sl.rq.u_l;
while (cur_ptr < cur_end && *cur_ptr != '?')
cur_ptr++;
/* skip the question mark or indicate that we must insert it
* (but only if the format string is not empty then).
*/
if (cur_ptr < cur_end)
cur_ptr++;
else if (len > 1)
offset = 0;
/* adjust req line offsets and lengths */
delta = len - offset - (cur_end - cur_ptr);
txn->req.sl.rq.u_l += delta;
txn->req.sl.rq.v += delta;
break;
case 3: // uri
cur_ptr = s->req.buf->p + txn->req.sl.rq.u;
cur_end = cur_ptr + txn->req.sl.rq.u_l;
/* adjust req line offsets and lengths */
delta = len - offset - (cur_end - cur_ptr);
txn->req.sl.rq.u_l += delta;
txn->req.sl.rq.v += delta;
break;
default:
return -1;
}
/* commit changes and adjust end of message */
delta = buffer_replace2(s->req.buf, cur_ptr, cur_end, replace + offset, len - offset);
txn->req.sl.rq.l += delta;
txn->hdr_idx.v[0].len += delta;
http_msg_move_end(&txn->req, delta);
return 0;
}
|
CWE-200
| 6,845 | 15,094 |
112603466683579799794462426618753180704
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
http_reply_and_close(struct stream *s, short status, struct chunk *msg)
{
s->txn->flags &= ~TX_WAIT_NEXT_RQ;
FLT_STRM_CB(s, flt_http_reply(s, status, msg));
stream_int_retnclose(&s->si[0], msg);
}
|
CWE-200
| 6,846 | 15,095 |
178827525668069354293461500911938387157
| null | null | null |
haproxy
|
17514045e5d934dede62116216c1b016fe23dd06
| 0 |
http_req_get_intercept_rule(struct proxy *px, struct list *rules, struct stream *s, int *deny_status)
{
struct session *sess = strm_sess(s);
struct http_txn *txn = s->txn;
struct connection *cli_conn;
struct act_rule *rule;
struct hdr_ctx ctx;
const char *auth_realm;
int act_flags = 0;
int len;
/* If "the current_rule_list" match the executed rule list, we are in
* resume condition. If a resume is needed it is always in the action
* and never in the ACL or converters. In this case, we initialise the
* current rule, and go to the action execution point.
*/
if (s->current_rule) {
rule = s->current_rule;
s->current_rule = NULL;
if (s->current_rule_list == rules)
goto resume_execution;
}
s->current_rule_list = rules;
list_for_each_entry(rule, rules, list) {
/* check optional condition */
if (rule->cond) {
int ret;
ret = acl_exec_cond(rule->cond, px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
ret = acl_pass(ret);
if (rule->cond->pol == ACL_COND_UNLESS)
ret = !ret;
if (!ret) /* condition not matched */
continue;
}
act_flags |= ACT_FLAG_FIRST;
resume_execution:
switch (rule->action) {
case ACT_ACTION_ALLOW:
return HTTP_RULE_RES_STOP;
case ACT_ACTION_DENY:
if (deny_status)
*deny_status = rule->deny_status;
return HTTP_RULE_RES_DENY;
case ACT_HTTP_REQ_TARPIT:
txn->flags |= TX_CLTARPIT;
if (deny_status)
*deny_status = rule->deny_status;
return HTTP_RULE_RES_DENY;
case ACT_HTTP_REQ_AUTH:
/* Auth might be performed on regular http-req rules as well as on stats */
auth_realm = rule->arg.auth.realm;
if (!auth_realm) {
if (px->uri_auth && rules == &px->uri_auth->http_req_rules)
auth_realm = STATS_DEFAULT_REALM;
else
auth_realm = px->id;
}
/* send 401/407 depending on whether we use a proxy or not. We still
* count one error, because normal browsing won't significantly
* increase the counter but brute force attempts will.
*/
chunk_printf(&trash, (txn->flags & TX_USE_PX_CONN) ? HTTP_407_fmt : HTTP_401_fmt, auth_realm);
txn->status = (txn->flags & TX_USE_PX_CONN) ? 407 : 401;
http_reply_and_close(s, txn->status, &trash);
stream_inc_http_err_ctr(s);
return HTTP_RULE_RES_ABRT;
case ACT_HTTP_REDIR:
if (!http_apply_redirect_rule(rule->arg.redir, s, txn))
return HTTP_RULE_RES_BADREQ;
return HTTP_RULE_RES_DONE;
case ACT_HTTP_SET_NICE:
s->task->nice = rule->arg.nice;
break;
case ACT_HTTP_SET_TOS:
if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
inet_set_tos(cli_conn->handle.fd, &cli_conn->addr.from, rule->arg.tos);
break;
case ACT_HTTP_SET_MARK:
#ifdef SO_MARK
if ((cli_conn = objt_conn(sess->origin)) && conn_ctrl_ready(cli_conn))
setsockopt(cli_conn->handle.fd, SOL_SOCKET, SO_MARK, &rule->arg.mark, sizeof(rule->arg.mark));
#endif
break;
case ACT_HTTP_SET_LOGL:
s->logs.level = rule->arg.loglevel;
break;
case ACT_HTTP_REPLACE_HDR:
case ACT_HTTP_REPLACE_VAL:
if (http_transform_header(s, &txn->req, rule->arg.hdr_add.name,
rule->arg.hdr_add.name_len,
&rule->arg.hdr_add.fmt,
&rule->arg.hdr_add.re, rule->action))
return HTTP_RULE_RES_BADREQ;
break;
case ACT_HTTP_DEL_HDR:
ctx.idx = 0;
/* remove all occurrences of the header */
while (http_find_header2(rule->arg.hdr_add.name, rule->arg.hdr_add.name_len,
txn->req.chn->buf->p, &txn->hdr_idx, &ctx)) {
http_remove_header2(&txn->req, &txn->hdr_idx, &ctx);
}
break;
case ACT_HTTP_SET_HDR:
case ACT_HTTP_ADD_HDR: {
/* The scope of the trash buffer must be limited to this function. The
* build_logline() function can execute a lot of other function which
* can use the trash buffer. So for limiting the scope of this global
* buffer, we build first the header value using build_logline, and
* after we store the header name.
*/
struct chunk *replace;
replace = alloc_trash_chunk();
if (!replace)
return HTTP_RULE_RES_BADREQ;
len = rule->arg.hdr_add.name_len + 2,
len += build_logline(s, replace->str + len, replace->size - len, &rule->arg.hdr_add.fmt);
memcpy(replace->str, rule->arg.hdr_add.name, rule->arg.hdr_add.name_len);
replace->str[rule->arg.hdr_add.name_len] = ':';
replace->str[rule->arg.hdr_add.name_len + 1] = ' ';
replace->len = len;
if (rule->action == ACT_HTTP_SET_HDR) {
/* remove all occurrences of the header */
ctx.idx = 0;
while (http_find_header2(rule->arg.hdr_add.name, rule->arg.hdr_add.name_len,
txn->req.chn->buf->p, &txn->hdr_idx, &ctx)) {
http_remove_header2(&txn->req, &txn->hdr_idx, &ctx);
}
}
http_header_add_tail2(&txn->req, &txn->hdr_idx, replace->str, replace->len);
free_trash_chunk(replace);
break;
}
case ACT_HTTP_DEL_ACL:
case ACT_HTTP_DEL_MAP: {
struct pat_ref *ref;
struct chunk *key;
/* collect reference */
ref = pat_ref_lookup(rule->arg.map.ref);
if (!ref)
continue;
/* allocate key */
key = alloc_trash_chunk();
if (!key)
return HTTP_RULE_RES_BADREQ;
/* collect key */
key->len = build_logline(s, key->str, key->size, &rule->arg.map.key);
key->str[key->len] = '\0';
/* perform update */
/* returned code: 1=ok, 0=ko */
HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
pat_ref_delete(ref, key->str);
HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
free_trash_chunk(key);
break;
}
case ACT_HTTP_ADD_ACL: {
struct pat_ref *ref;
struct chunk *key;
/* collect reference */
ref = pat_ref_lookup(rule->arg.map.ref);
if (!ref)
continue;
/* allocate key */
key = alloc_trash_chunk();
if (!key)
return HTTP_RULE_RES_BADREQ;
/* collect key */
key->len = build_logline(s, key->str, key->size, &rule->arg.map.key);
key->str[key->len] = '\0';
/* perform update */
/* add entry only if it does not already exist */
HA_SPIN_LOCK(PATREF_LOCK, &ref->lock);
if (pat_ref_find_elt(ref, key->str) == NULL)
pat_ref_add(ref, key->str, NULL, NULL);
HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock);
free_trash_chunk(key);
break;
}
case ACT_HTTP_SET_MAP: {
struct pat_ref *ref;
struct chunk *key, *value;
/* collect reference */
ref = pat_ref_lookup(rule->arg.map.ref);
if (!ref)
continue;
/* allocate key */
key = alloc_trash_chunk();
if (!key)
return HTTP_RULE_RES_BADREQ;
/* allocate value */
value = alloc_trash_chunk();
if (!value) {
free_trash_chunk(key);
return HTTP_RULE_RES_BADREQ;
}
/* collect key */
key->len = build_logline(s, key->str, key->size, &rule->arg.map.key);
key->str[key->len] = '\0';
/* collect value */
value->len = build_logline(s, value->str, value->size, &rule->arg.map.value);
value->str[value->len] = '\0';
/* perform update */
if (pat_ref_find_elt(ref, key->str) != NULL)
/* update entry if it exists */
pat_ref_set(ref, key->str, value->str, NULL);
else
/* insert a new entry */
pat_ref_add(ref, key->str, value->str, NULL);
free_trash_chunk(key);
free_trash_chunk(value);
break;
}
case ACT_CUSTOM:
if ((s->req.flags & CF_READ_ERROR) ||
((s->req.flags & (CF_SHUTR|CF_READ_NULL)) &&
!(s->si[0].flags & SI_FL_CLEAN_ABRT) &&
(px->options & PR_O_ABRT_CLOSE)))
act_flags |= ACT_FLAG_FINAL;
switch (rule->action_ptr(rule, px, s->sess, s, act_flags)) {
case ACT_RET_ERR:
case ACT_RET_CONT:
break;
case ACT_RET_STOP:
return HTTP_RULE_RES_DONE;
case ACT_RET_YIELD:
s->current_rule = rule;
return HTTP_RULE_RES_YIELD;
}
break;
case ACT_ACTION_TRK_SC0 ... ACT_ACTION_TRK_SCMAX:
/* Note: only the first valid tracking parameter of each
* applies.
*/
if (stkctr_entry(&s->stkctr[trk_idx(rule->action)]) == NULL) {
struct stktable *t;
struct stksess *ts;
struct stktable_key *key;
void *ptr1, *ptr2;
t = rule->arg.trk_ctr.table.t;
key = stktable_fetch_key(t, s->be, sess, s, SMP_OPT_DIR_REQ | SMP_OPT_FINAL, rule->arg.trk_ctr.expr, NULL);
if (key && (ts = stktable_get_entry(t, key))) {
stream_track_stkctr(&s->stkctr[trk_idx(rule->action)], t, ts);
/* let's count a new HTTP request as it's the first time we do it */
ptr1 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
ptr2 = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
if (ptr1 || ptr2) {
HA_RWLOCK_WRLOCK(STK_SESS_LOCK, &ts->lock);
if (ptr1)
stktable_data_cast(ptr1, http_req_cnt)++;
if (ptr2)
update_freq_ctr_period(&stktable_data_cast(ptr2, http_req_rate),
t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
HA_RWLOCK_WRUNLOCK(STK_SESS_LOCK, &ts->lock);
/* If data was modified, we need to touch to re-schedule sync */
stktable_touch_local(t, ts, 0);
}
stkctr_set_flags(&s->stkctr[trk_idx(rule->action)], STKCTR_TRACK_CONTENT);
if (sess->fe != s->be)
stkctr_set_flags(&s->stkctr[trk_idx(rule->action)], STKCTR_TRACK_BACKEND);
}
}
break;
/* other flags exists, but normaly, they never be matched. */
default:
break;
}
}
/* we reached the end of the rules, nothing to report */
return HTTP_RULE_RES_CONT;
}
|
CWE-200
| 6,847 | 15,096 |
297838230293685304190701390011507502622
| null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.