idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
2,100
|
jsonb_to_record(PG_FUNCTION_ARGS)
{
return populate_record_worker(fcinfo, "jsonb_to_record", false);
}
|
DoS Overflow
| 0
|
jsonb_to_record(PG_FUNCTION_ARGS)
{
return populate_record_worker(fcinfo, "jsonb_to_record", false);
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,101
|
jsonb_to_recordset(PG_FUNCTION_ARGS)
{
return populate_recordset_worker(fcinfo, "jsonb_to_recordset", false);
}
|
DoS Overflow
| 0
|
jsonb_to_recordset(PG_FUNCTION_ARGS)
{
return populate_recordset_worker(fcinfo, "jsonb_to_recordset", false);
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,102
|
okeys_object_field_start(void *state, char *fname, bool isnull)
{
OkeysState *_state = (OkeysState *) state;
/* only collecting keys for the top level object */
if (_state->lex->lex_level != 1)
return;
/* enlarge result array if necessary */
if (_state->result_count >= _state->result_size)
{
_state->result_size *= 2;
_state->result = (char **)
repalloc(_state->result, sizeof(char *) * _state->result_size);
}
/* save a copy of the field name */
_state->result[_state->result_count++] = pstrdup(fname);
}
|
DoS Overflow
| 0
|
okeys_object_field_start(void *state, char *fname, bool isnull)
{
OkeysState *_state = (OkeysState *) state;
/* only collecting keys for the top level object */
if (_state->lex->lex_level != 1)
return;
/* enlarge result array if necessary */
if (_state->result_count >= _state->result_size)
{
_state->result_size *= 2;
_state->result = (char **)
repalloc(_state->result, sizeof(char *) * _state->result_size);
}
/* save a copy of the field name */
_state->result[_state->result_count++] = pstrdup(fname);
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,103
|
populate_recordset_array_element_start(void *state, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level == 1 &&
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument of %s must be an array of objects",
_state->function_name)));
}
|
DoS Overflow
| 0
|
populate_recordset_array_element_start(void *state, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level == 1 &&
_state->lex->token_type != JSON_TOKEN_OBJECT_START)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument of %s must be an array of objects",
_state->function_name)));
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,104
|
populate_recordset_array_start(void *state)
{
/* nothing to do */
}
|
DoS Overflow
| 0
|
populate_recordset_array_start(void *state)
{
/* nothing to do */
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,105
|
populate_recordset_object_field_end(void *state, char *fname, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
JsonHashEntry *hashentry;
bool found;
/*
* Ignore nested fields.
*/
if (_state->lex->lex_level > 2)
return;
/*
* Ignore field names >= NAMEDATALEN - they can't match a record field.
* (Note: without this test, the hash code would truncate the string at
* NAMEDATALEN-1, and could then match against a similarly-truncated
* record field name. That would be a reasonable behavior, but this code
* has previously insisted on exact equality, so we keep this behavior.)
*/
if (strlen(fname) >= NAMEDATALEN)
return;
hashentry = hash_search(_state->json_hash, fname, HASH_ENTER, &found);
/*
* found being true indicates a duplicate. We don't do anything about
* that, a later field with the same name overrides the earlier field.
*/
hashentry->isnull = isnull;
if (_state->save_json_start != NULL)
{
int len = _state->lex->prev_token_terminator - _state->save_json_start;
char *val = palloc((len + 1) * sizeof(char));
memcpy(val, _state->save_json_start, len);
val[len] = '\0';
hashentry->val = val;
}
else
{
/* must have had a scalar instead */
hashentry->val = _state->saved_scalar;
}
}
|
DoS Overflow
| 0
|
populate_recordset_object_field_end(void *state, char *fname, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
JsonHashEntry *hashentry;
bool found;
/*
* Ignore nested fields.
*/
if (_state->lex->lex_level > 2)
return;
/*
* Ignore field names >= NAMEDATALEN - they can't match a record field.
* (Note: without this test, the hash code would truncate the string at
* NAMEDATALEN-1, and could then match against a similarly-truncated
* record field name. That would be a reasonable behavior, but this code
* has previously insisted on exact equality, so we keep this behavior.)
*/
if (strlen(fname) >= NAMEDATALEN)
return;
hashentry = hash_search(_state->json_hash, fname, HASH_ENTER, &found);
/*
* found being true indicates a duplicate. We don't do anything about
* that, a later field with the same name overrides the earlier field.
*/
hashentry->isnull = isnull;
if (_state->save_json_start != NULL)
{
int len = _state->lex->prev_token_terminator - _state->save_json_start;
char *val = palloc((len + 1) * sizeof(char));
memcpy(val, _state->save_json_start, len);
val[len] = '\0';
hashentry->val = val;
}
else
{
/* must have had a scalar instead */
hashentry->val = _state->saved_scalar;
}
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,106
|
populate_recordset_object_field_start(void *state, char *fname, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level > 2)
return;
if (_state->lex->token_type == JSON_TOKEN_ARRAY_START ||
_state->lex->token_type == JSON_TOKEN_OBJECT_START)
{
_state->save_json_start = _state->lex->token_start;
}
else
{
_state->save_json_start = NULL;
}
}
|
DoS Overflow
| 0
|
populate_recordset_object_field_start(void *state, char *fname, bool isnull)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
if (_state->lex->lex_level > 2)
return;
if (_state->lex->token_type == JSON_TOKEN_ARRAY_START ||
_state->lex->token_type == JSON_TOKEN_OBJECT_START)
{
_state->save_json_start = _state->lex->token_start;
}
else
{
_state->save_json_start = NULL;
}
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,107
|
populate_recordset_object_start(void *state)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
int lex_level = _state->lex->lex_level;
HASHCTL ctl;
/* Reject object at top level: we must have an array at level 0 */
if (lex_level == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot call %s on an object",
_state->function_name)));
/* Nested objects require no special processing */
if (lex_level > 1)
return;
/* Object at level 1: set up a new hash table for this object */
memset(&ctl, 0, sizeof(ctl));
ctl.keysize = NAMEDATALEN;
ctl.entrysize = sizeof(JsonHashEntry);
ctl.hcxt = CurrentMemoryContext;
_state->json_hash = hash_create("json object hashtable",
100,
&ctl,
HASH_ELEM | HASH_CONTEXT);
}
|
DoS Overflow
| 0
|
populate_recordset_object_start(void *state)
{
PopulateRecordsetState *_state = (PopulateRecordsetState *) state;
int lex_level = _state->lex->lex_level;
HASHCTL ctl;
/* Reject object at top level: we must have an array at level 0 */
if (lex_level == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot call %s on an object",
_state->function_name)));
/* Nested objects require no special processing */
if (lex_level > 1)
return;
/* Object at level 1: set up a new hash table for this object */
memset(&ctl, 0, sizeof(ctl));
ctl.keysize = NAMEDATALEN;
ctl.entrysize = sizeof(JsonHashEntry);
ctl.hcxt = CurrentMemoryContext;
_state->json_hash = hash_create("json object hashtable",
100,
&ctl,
HASH_ELEM | HASH_CONTEXT);
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,108
|
populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
bool have_record_arg)
{
int json_arg_num = have_record_arg ? 1 : 0;
Oid jtype = get_fn_expr_argtype(fcinfo->flinfo, json_arg_num);
ReturnSetInfo *rsi;
MemoryContext old_cxt;
Oid tupType;
int32 tupTypmod;
HeapTupleHeader rec;
TupleDesc tupdesc;
RecordIOData *my_extra;
int ncolumns;
PopulateRecordsetState *state;
if (have_record_arg)
{
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
if (!type_is_rowtype(argtype))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("first argument of %s must be a row type",
funcname)));
}
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
if (!rsi || !IsA(rsi, ReturnSetInfo) ||
(rsi->allowedModes & SFRM_Materialize) == 0 ||
rsi->expectedDesc == NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that "
"cannot accept a set")));
rsi->returnMode = SFRM_Materialize;
/*
* get the tupdesc from the result set info - it must be a record type
* because we already checked that arg1 is a record type, or we're in a
* to_record function which returns a setof record.
*/
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
"that cannot accept type record")));
/* if the json is null send back an empty set */
if (PG_ARGISNULL(json_arg_num))
PG_RETURN_NULL();
if (!have_record_arg || PG_ARGISNULL(0))
rec = NULL;
else
rec = PG_GETARG_HEAPTUPLEHEADER(0);
tupType = tupdesc->tdtypeid;
tupTypmod = tupdesc->tdtypmod;
ncolumns = tupdesc->natts;
/*
* We arrange to look up the needed I/O info just once per series of
* calls, assuming the record type doesn't change underneath us.
*/
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
if (my_extra == NULL ||
my_extra->ncolumns != ncolumns)
{
fcinfo->flinfo->fn_extra =
MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
my_extra->record_type = InvalidOid;
my_extra->record_typmod = 0;
}
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
MemSet(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
my_extra->record_typmod = tupTypmod;
my_extra->ncolumns = ncolumns;
}
state = palloc0(sizeof(PopulateRecordsetState));
/* make these in a sufficiently long-lived memory context */
old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
state->ret_tdesc = CreateTupleDescCopy(tupdesc);
BlessTupleDesc(state->ret_tdesc);
state->tuple_store = tuplestore_begin_heap(rsi->allowedModes &
SFRM_Materialize_Random,
false, work_mem);
MemoryContextSwitchTo(old_cxt);
state->function_name = funcname;
state->my_extra = my_extra;
state->rec = rec;
state->fn_mcxt = fcinfo->flinfo->fn_mcxt;
if (jtype == JSONOID)
{
text *json = PG_GETARG_TEXT_P(json_arg_num);
JsonLexContext *lex;
JsonSemAction *sem;
sem = palloc0(sizeof(JsonSemAction));
lex = makeJsonLexContext(json, true);
sem->semstate = (void *) state;
sem->array_start = populate_recordset_array_start;
sem->array_element_start = populate_recordset_array_element_start;
sem->scalar = populate_recordset_scalar;
sem->object_field_start = populate_recordset_object_field_start;
sem->object_field_end = populate_recordset_object_field_end;
sem->object_start = populate_recordset_object_start;
sem->object_end = populate_recordset_object_end;
state->lex = lex;
pg_parse_json(lex, sem);
}
else
{
Jsonb *jb = PG_GETARG_JSONB(json_arg_num);
JsonbIterator *it;
JsonbValue v;
bool skipNested = false;
int r;
Assert(jtype == JSONBOID);
if (JB_ROOT_IS_SCALAR(jb) || !JB_ROOT_IS_ARRAY(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot call %s on a non-array",
funcname)));
it = JsonbIteratorInit(&jb->root);
while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
{
skipNested = true;
if (r == WJB_ELEM)
{
Jsonb *element = JsonbValueToJsonb(&v);
if (!JB_ROOT_IS_OBJECT(element))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument of %s must be an array of objects",
funcname)));
make_row_from_rec_and_jsonb(element, state);
}
}
}
rsi->setResult = state->tuple_store;
rsi->setDesc = state->ret_tdesc;
PG_RETURN_NULL();
}
|
DoS Overflow
| 0
|
populate_recordset_worker(FunctionCallInfo fcinfo, const char *funcname,
bool have_record_arg)
{
int json_arg_num = have_record_arg ? 1 : 0;
Oid jtype = get_fn_expr_argtype(fcinfo->flinfo, json_arg_num);
ReturnSetInfo *rsi;
MemoryContext old_cxt;
Oid tupType;
int32 tupTypmod;
HeapTupleHeader rec;
TupleDesc tupdesc;
RecordIOData *my_extra;
int ncolumns;
PopulateRecordsetState *state;
if (have_record_arg)
{
Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
if (!type_is_rowtype(argtype))
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("first argument of %s must be a row type",
funcname)));
}
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
if (!rsi || !IsA(rsi, ReturnSetInfo) ||
(rsi->allowedModes & SFRM_Materialize) == 0 ||
rsi->expectedDesc == NULL)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("set-valued function called in context that "
"cannot accept a set")));
rsi->returnMode = SFRM_Materialize;
/*
* get the tupdesc from the result set info - it must be a record type
* because we already checked that arg1 is a record type, or we're in a
* to_record function which returns a setof record.
*/
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("function returning record called in context "
"that cannot accept type record")));
/* if the json is null send back an empty set */
if (PG_ARGISNULL(json_arg_num))
PG_RETURN_NULL();
if (!have_record_arg || PG_ARGISNULL(0))
rec = NULL;
else
rec = PG_GETARG_HEAPTUPLEHEADER(0);
tupType = tupdesc->tdtypeid;
tupTypmod = tupdesc->tdtypmod;
ncolumns = tupdesc->natts;
/*
* We arrange to look up the needed I/O info just once per series of
* calls, assuming the record type doesn't change underneath us.
*/
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
if (my_extra == NULL ||
my_extra->ncolumns != ncolumns)
{
fcinfo->flinfo->fn_extra =
MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
my_extra->record_type = InvalidOid;
my_extra->record_typmod = 0;
}
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
MemSet(my_extra, 0,
offsetof(RecordIOData, columns) +
ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
my_extra->record_typmod = tupTypmod;
my_extra->ncolumns = ncolumns;
}
state = palloc0(sizeof(PopulateRecordsetState));
/* make these in a sufficiently long-lived memory context */
old_cxt = MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
state->ret_tdesc = CreateTupleDescCopy(tupdesc);
BlessTupleDesc(state->ret_tdesc);
state->tuple_store = tuplestore_begin_heap(rsi->allowedModes &
SFRM_Materialize_Random,
false, work_mem);
MemoryContextSwitchTo(old_cxt);
state->function_name = funcname;
state->my_extra = my_extra;
state->rec = rec;
state->fn_mcxt = fcinfo->flinfo->fn_mcxt;
if (jtype == JSONOID)
{
text *json = PG_GETARG_TEXT_P(json_arg_num);
JsonLexContext *lex;
JsonSemAction *sem;
sem = palloc0(sizeof(JsonSemAction));
lex = makeJsonLexContext(json, true);
sem->semstate = (void *) state;
sem->array_start = populate_recordset_array_start;
sem->array_element_start = populate_recordset_array_element_start;
sem->scalar = populate_recordset_scalar;
sem->object_field_start = populate_recordset_object_field_start;
sem->object_field_end = populate_recordset_object_field_end;
sem->object_start = populate_recordset_object_start;
sem->object_end = populate_recordset_object_end;
state->lex = lex;
pg_parse_json(lex, sem);
}
else
{
Jsonb *jb = PG_GETARG_JSONB(json_arg_num);
JsonbIterator *it;
JsonbValue v;
bool skipNested = false;
int r;
Assert(jtype == JSONBOID);
if (JB_ROOT_IS_SCALAR(jb) || !JB_ROOT_IS_ARRAY(jb))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("cannot call %s on a non-array",
funcname)));
it = JsonbIteratorInit(&jb->root);
while ((r = JsonbIteratorNext(&it, &v, skipNested)) != WJB_DONE)
{
skipNested = true;
if (r == WJB_ELEM)
{
Jsonb *element = JsonbValueToJsonb(&v);
if (!JB_ROOT_IS_OBJECT(element))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("argument of %s must be an array of objects",
funcname)));
make_row_from_rec_and_jsonb(element, state);
}
}
}
rsi->setResult = state->tuple_store;
rsi->setDesc = state->ret_tdesc;
PG_RETURN_NULL();
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,109
|
setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
int path_len, JsonbParseState **st, int level,
Jsonb *newval, uint32 nelems, bool create)
{
JsonbValue v;
int idx,
i;
char *badp;
bool done = false;
/* pick correct index */
if (level < path_len && !path_nulls[level])
{
char *c = VARDATA_ANY(path_elems[level]);
long lindex;
errno = 0;
lindex = strtol(c, &badp, 10);
if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX ||
lindex < INT_MIN)
elog(ERROR, "path element at the position %d is not an integer", level + 1);
else
idx = lindex;
}
else
idx = nelems;
if (idx < 0)
{
if (-idx > nelems)
idx = INT_MIN;
else
idx = nelems + idx;
}
if (idx > 0 && idx > nelems)
idx = nelems;
/*
* if we're creating, and idx == INT_MIN, we prepend the new value to the
* array also if the array is empty - in which case we don't really care
* what the idx value is
*/
if ((idx == INT_MIN || nelems == 0) && create && (level == path_len - 1))
{
Assert(newval != NULL);
addJsonbToParseState(st, newval);
done = true;
}
/* iterate over the array elements */
for (i = 0; i < nelems; i++)
{
int r;
if (i == idx && level < path_len)
{
if (level == path_len - 1)
{
r = JsonbIteratorNext(it, &v, true); /* skip */
if (newval != NULL)
addJsonbToParseState(st, newval);
done = true;
}
else
(void) setPath(it, path_elems, path_nulls, path_len,
st, level + 1, newval, create);
}
else
{
r = JsonbIteratorNext(it, &v, false);
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
{
int walking_level = 1;
while (walking_level != 0)
{
r = JsonbIteratorNext(it, &v, false);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
++walking_level;
if (r == WJB_END_ARRAY || r == WJB_END_OBJECT)
--walking_level;
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
}
}
if (create && !done && level == path_len - 1 && i == nelems - 1)
{
addJsonbToParseState(st, newval);
}
}
}
}
|
DoS Overflow
| 0
|
setPathArray(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
int path_len, JsonbParseState **st, int level,
Jsonb *newval, uint32 nelems, bool create)
{
JsonbValue v;
int idx,
i;
char *badp;
bool done = false;
/* pick correct index */
if (level < path_len && !path_nulls[level])
{
char *c = VARDATA_ANY(path_elems[level]);
long lindex;
errno = 0;
lindex = strtol(c, &badp, 10);
if (errno != 0 || badp == c || *badp != '\0' || lindex > INT_MAX ||
lindex < INT_MIN)
elog(ERROR, "path element at the position %d is not an integer", level + 1);
else
idx = lindex;
}
else
idx = nelems;
if (idx < 0)
{
if (-idx > nelems)
idx = INT_MIN;
else
idx = nelems + idx;
}
if (idx > 0 && idx > nelems)
idx = nelems;
/*
* if we're creating, and idx == INT_MIN, we prepend the new value to the
* array also if the array is empty - in which case we don't really care
* what the idx value is
*/
if ((idx == INT_MIN || nelems == 0) && create && (level == path_len - 1))
{
Assert(newval != NULL);
addJsonbToParseState(st, newval);
done = true;
}
/* iterate over the array elements */
for (i = 0; i < nelems; i++)
{
int r;
if (i == idx && level < path_len)
{
if (level == path_len - 1)
{
r = JsonbIteratorNext(it, &v, true); /* skip */
if (newval != NULL)
addJsonbToParseState(st, newval);
done = true;
}
else
(void) setPath(it, path_elems, path_nulls, path_len,
st, level + 1, newval, create);
}
else
{
r = JsonbIteratorNext(it, &v, false);
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
{
int walking_level = 1;
while (walking_level != 0)
{
r = JsonbIteratorNext(it, &v, false);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
++walking_level;
if (r == WJB_END_ARRAY || r == WJB_END_OBJECT)
--walking_level;
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
}
}
if (create && !done && level == path_len - 1 && i == nelems - 1)
{
addJsonbToParseState(st, newval);
}
}
}
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,110
|
setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
int path_len, JsonbParseState **st, int level,
Jsonb *newval, uint32 npairs, bool create)
{
JsonbValue v;
int i;
JsonbValue k;
bool done = false;
if (level >= path_len || path_nulls[level])
done = true;
/* empty object is a special case for create */
if ((npairs == 0) && create && (level == path_len - 1))
{
JsonbValue newkey;
newkey.type = jbvString;
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
(void) pushJsonbValue(st, WJB_KEY, &newkey);
addJsonbToParseState(st, newval);
}
for (i = 0; i < npairs; i++)
{
int r = JsonbIteratorNext(it, &k, true);
Assert(r == WJB_KEY);
if (!done &&
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
k.val.string.len) == 0)
{
if (level == path_len - 1)
{
r = JsonbIteratorNext(it, &v, true); /* skip */
if (newval != NULL)
{
(void) pushJsonbValue(st, WJB_KEY, &k);
addJsonbToParseState(st, newval);
}
done = true;
}
else
{
(void) pushJsonbValue(st, r, &k);
setPath(it, path_elems, path_nulls, path_len,
st, level + 1, newval, create);
}
}
else
{
if (create && !done && level == path_len - 1 && i == npairs - 1)
{
JsonbValue newkey;
newkey.type = jbvString;
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
(void) pushJsonbValue(st, WJB_KEY, &newkey);
addJsonbToParseState(st, newval);
}
(void) pushJsonbValue(st, r, &k);
r = JsonbIteratorNext(it, &v, false);
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
{
int walking_level = 1;
while (walking_level != 0)
{
r = JsonbIteratorNext(it, &v, false);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
++walking_level;
if (r == WJB_END_ARRAY || r == WJB_END_OBJECT)
--walking_level;
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
}
}
}
}
}
|
DoS Overflow
| 0
|
setPathObject(JsonbIterator **it, Datum *path_elems, bool *path_nulls,
int path_len, JsonbParseState **st, int level,
Jsonb *newval, uint32 npairs, bool create)
{
JsonbValue v;
int i;
JsonbValue k;
bool done = false;
if (level >= path_len || path_nulls[level])
done = true;
/* empty object is a special case for create */
if ((npairs == 0) && create && (level == path_len - 1))
{
JsonbValue newkey;
newkey.type = jbvString;
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
(void) pushJsonbValue(st, WJB_KEY, &newkey);
addJsonbToParseState(st, newval);
}
for (i = 0; i < npairs; i++)
{
int r = JsonbIteratorNext(it, &k, true);
Assert(r == WJB_KEY);
if (!done &&
k.val.string.len == VARSIZE_ANY_EXHDR(path_elems[level]) &&
memcmp(k.val.string.val, VARDATA_ANY(path_elems[level]),
k.val.string.len) == 0)
{
if (level == path_len - 1)
{
r = JsonbIteratorNext(it, &v, true); /* skip */
if (newval != NULL)
{
(void) pushJsonbValue(st, WJB_KEY, &k);
addJsonbToParseState(st, newval);
}
done = true;
}
else
{
(void) pushJsonbValue(st, r, &k);
setPath(it, path_elems, path_nulls, path_len,
st, level + 1, newval, create);
}
}
else
{
if (create && !done && level == path_len - 1 && i == npairs - 1)
{
JsonbValue newkey;
newkey.type = jbvString;
newkey.val.string.len = VARSIZE_ANY_EXHDR(path_elems[level]);
newkey.val.string.val = VARDATA_ANY(path_elems[level]);
(void) pushJsonbValue(st, WJB_KEY, &newkey);
addJsonbToParseState(st, newval);
}
(void) pushJsonbValue(st, r, &k);
r = JsonbIteratorNext(it, &v, false);
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
{
int walking_level = 1;
while (walking_level != 0)
{
r = JsonbIteratorNext(it, &v, false);
if (r == WJB_BEGIN_ARRAY || r == WJB_BEGIN_OBJECT)
++walking_level;
if (r == WJB_END_ARRAY || r == WJB_END_OBJECT)
--walking_level;
(void) pushJsonbValue(st, r, r < WJB_BEGIN_ARRAY ? &v : NULL);
}
}
}
}
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,111
|
sn_array_element_start(void *state, bool isnull)
{
StripnullState *_state = (StripnullState *) state;
if (_state->strval->data[_state->strval->len - 1] != '[')
appendStringInfoCharMacro(_state->strval, ',');
}
|
DoS Overflow
| 0
|
sn_array_element_start(void *state, bool isnull)
{
StripnullState *_state = (StripnullState *) state;
if (_state->strval->data[_state->strval->len - 1] != '[')
appendStringInfoCharMacro(_state->strval, ',');
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,112
|
sn_array_end(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, ']');
}
|
DoS Overflow
| 0
|
sn_array_end(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, ']');
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,113
|
sn_array_start(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, '[');
}
|
DoS Overflow
| 0
|
sn_array_start(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, '[');
}
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,114
|
sn_object_end(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, '}');
|
DoS Overflow
| 0
|
sn_object_end(void *state)
{
StripnullState *_state = (StripnullState *) state;
appendStringInfoCharMacro(_state->strval, '}');
|
@@ -3724,6 +3724,8 @@ setPath(JsonbIterator **it, Datum *path_elems,
JsonbValue *res = NULL;
int r;
+ check_stack_depth();
+
if (path_nulls[level])
elog(ERROR, "path element at the position %d is NULL", level + 1);
|
CWE-119
| null | null |
2,115
|
static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary)
avail = boundary - index;
else
avail = (s->stop - s->start) - (index - boundary);
if (avail < (MAX_ETH_FRAME_SIZE + 4))
return 1;
return 0;
}
|
DoS Exec Code Overflow
| 0
|
static int ne2000_buffer_full(NE2000State *s)
{
int avail, index, boundary;
index = s->curpag << 8;
boundary = s->boundary << 8;
if (index < boundary)
avail = boundary - index;
else
avail = (s->stop - s->start) - (index - boundary);
if (avail < (MAX_ETH_FRAME_SIZE + 4))
return 1;
return 0;
}
|
@@ -230,6 +230,9 @@ ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
}
index = s->curpag << 8;
+ if (index >= NE2000_PMEM_END) {
+ index = s->start;
+ }
/* 4 bytes for header */
total_len = size + 4;
/* address for next packet (4 bytes for CRC) */
@@ -315,13 +318,19 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
offset = addr | (page << 4);
switch(offset) {
case EN0_STARTPG:
- s->start = val << 8;
+ if (val << 8 <= NE2000_PMEM_END) {
+ s->start = val << 8;
+ }
break;
case EN0_STOPPG:
- s->stop = val << 8;
+ if (val << 8 <= NE2000_PMEM_END) {
+ s->stop = val << 8;
+ }
break;
case EN0_BOUNDARY:
- s->boundary = val;
+ if (val << 8 < NE2000_PMEM_END) {
+ s->boundary = val;
+ }
break;
case EN0_IMR:
s->imr = val;
@@ -362,7 +371,9 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
s->phys[offset - EN1_PHYS] = val;
break;
case EN1_CURPAG:
- s->curpag = val;
+ if (val << 8 < NE2000_PMEM_END) {
+ s->curpag = val;
+ }
break;
case EN1_MULT ... EN1_MULT + 7:
s->mult[offset - EN1_MULT] = val;
|
CWE-119
| null | null |
2,116
|
int ne2000_can_receive(NetClientState *nc)
{
NE2000State *s = qemu_get_nic_opaque(nc);
if (s->cmd & E8390_STOP)
return 1;
return !ne2000_buffer_full(s);
}
|
DoS Exec Code Overflow
| 0
|
int ne2000_can_receive(NetClientState *nc)
{
NE2000State *s = qemu_get_nic_opaque(nc);
if (s->cmd & E8390_STOP)
return 1;
return !ne2000_buffer_full(s);
}
|
@@ -230,6 +230,9 @@ ssize_t ne2000_receive(NetClientState *nc, const uint8_t *buf, size_t size_)
}
index = s->curpag << 8;
+ if (index >= NE2000_PMEM_END) {
+ index = s->start;
+ }
/* 4 bytes for header */
total_len = size + 4;
/* address for next packet (4 bytes for CRC) */
@@ -315,13 +318,19 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
offset = addr | (page << 4);
switch(offset) {
case EN0_STARTPG:
- s->start = val << 8;
+ if (val << 8 <= NE2000_PMEM_END) {
+ s->start = val << 8;
+ }
break;
case EN0_STOPPG:
- s->stop = val << 8;
+ if (val << 8 <= NE2000_PMEM_END) {
+ s->stop = val << 8;
+ }
break;
case EN0_BOUNDARY:
- s->boundary = val;
+ if (val << 8 < NE2000_PMEM_END) {
+ s->boundary = val;
+ }
break;
case EN0_IMR:
s->imr = val;
@@ -362,7 +371,9 @@ static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
s->phys[offset - EN1_PHYS] = val;
break;
case EN1_CURPAG:
- s->curpag = val;
+ if (val << 8 < NE2000_PMEM_END) {
+ s->curpag = val;
+ }
break;
case EN1_MULT ... EN1_MULT + 7:
s->mult[offset - EN1_MULT] = val;
|
CWE-119
| null | null |
2,117
|
NTSTATUS smb_register_vfs(int version, const char *name,
const struct vfs_fn_pointers *fns)
{
struct vfs_init_function_entry *entry = backends;
if ((version != SMB_VFS_INTERFACE_VERSION)) {
DEBUG(0, ("Failed to register vfs module.\n"
"The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
"current SMB_VFS_INTERFACE_VERSION is %d.\n"
"Please recompile against the current Samba Version!\n",
version, SMB_VFS_INTERFACE_VERSION));
return NT_STATUS_OBJECT_TYPE_MISMATCH;
}
if (!name || !name[0]) {
DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
return NT_STATUS_INVALID_PARAMETER;
}
if (vfs_find_backend_entry(name)) {
DEBUG(0,("VFS module %s already loaded!\n", name));
return NT_STATUS_OBJECT_NAME_COLLISION;
}
entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
entry->name = smb_xstrdup(name);
entry->fns = fns;
DLIST_ADD(backends, entry);
DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
return NT_STATUS_OK;
}
|
Bypass
| 0
|
NTSTATUS smb_register_vfs(int version, const char *name,
const struct vfs_fn_pointers *fns)
{
struct vfs_init_function_entry *entry = backends;
if ((version != SMB_VFS_INTERFACE_VERSION)) {
DEBUG(0, ("Failed to register vfs module.\n"
"The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
"current SMB_VFS_INTERFACE_VERSION is %d.\n"
"Please recompile against the current Samba Version!\n",
version, SMB_VFS_INTERFACE_VERSION));
return NT_STATUS_OBJECT_TYPE_MISMATCH;
}
if (!name || !name[0]) {
DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
return NT_STATUS_INVALID_PARAMETER;
}
if (vfs_find_backend_entry(name)) {
DEBUG(0,("VFS module %s already loaded!\n", name));
return NT_STATUS_OBJECT_NAME_COLLISION;
}
entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
entry->name = smb_xstrdup(name);
entry->fns = fns;
DLIST_ADD(backends, entry);
DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
return NT_STATUS_OK;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,118
|
bool smbd_vfs_init(connection_struct *conn)
{
const char **vfs_objects;
unsigned int i = 0;
int j = 0;
/* Normal share - initialise with disk access functions */
vfs_init_default(conn);
/* No need to load vfs modules for printer connections */
if (conn->printer) {
return True;
}
vfs_objects = lp_vfs_objects(SNUM(conn));
/* Override VFS functions if 'vfs object' was not specified*/
if (!vfs_objects || !vfs_objects[0])
return True;
for (i=0; vfs_objects[i] ;) {
i++;
}
for (j=i-1; j >= 0; j--) {
if (!vfs_init_custom(conn, vfs_objects[j])) {
DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
return False;
}
}
return True;
}
|
Bypass
| 0
|
bool smbd_vfs_init(connection_struct *conn)
{
const char **vfs_objects;
unsigned int i = 0;
int j = 0;
/* Normal share - initialise with disk access functions */
vfs_init_default(conn);
/* No need to load vfs modules for printer connections */
if (conn->printer) {
return True;
}
vfs_objects = lp_vfs_objects(SNUM(conn));
/* Override VFS functions if 'vfs object' was not specified*/
if (!vfs_objects || !vfs_objects[0])
return True;
for (i=0; vfs_objects[i] ;) {
i++;
}
for (j=i-1; j >= 0; j--) {
if (!vfs_init_custom(conn, vfs_objects[j])) {
DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
return False;
}
}
return True;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,119
|
void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
files_struct *fsp, size_t ext_size,
void (*destroy_fn)(void *p_data))
{
struct vfs_fsp_data *ext;
void * ext_data;
/* Prevent VFS modules adding multiple extensions. */
if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
return ext_data;
}
ext = (struct vfs_fsp_data *)TALLOC_ZERO(
handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
if (ext == NULL) {
return NULL;
}
ext->owner = handle;
ext->next = fsp->vfs_extension;
ext->destroy = destroy_fn;
fsp->vfs_extension = ext;
return EXT_DATA_AREA(ext);
}
|
Bypass
| 0
|
void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
files_struct *fsp, size_t ext_size,
void (*destroy_fn)(void *p_data))
{
struct vfs_fsp_data *ext;
void * ext_data;
/* Prevent VFS modules adding multiple extensions. */
if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
return ext_data;
}
ext = (struct vfs_fsp_data *)TALLOC_ZERO(
handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
if (ext == NULL) {
return NULL;
}
ext->owner = handle;
ext->next = fsp->vfs_extension;
ext->destroy = destroy_fn;
fsp->vfs_extension = ext;
return EXT_DATA_AREA(ext);
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,120
|
int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
{
int ret;
connection_struct *conn = fsp->conn;
uint64_t space_avail;
uint64_t bsize,dfree,dsize;
NTSTATUS status;
/*
* Actually try and commit the space on disk....
*/
DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
fsp_str_dbg(fsp), (double)len));
if (((off_t)len) < 0) {
DEBUG(0,("vfs_allocate_file_space: %s negative len "
"requested.\n", fsp_str_dbg(fsp)));
errno = EINVAL;
return -1;
}
status = vfs_stat_fsp(fsp);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
return 0;
if (len < (uint64_t)fsp->fsp_name->st.st_ex_size) {
/* Shrink - use ftruncate. */
DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
"size %.0f\n", fsp_str_dbg(fsp),
(double)fsp->fsp_name->st.st_ex_size));
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
if ((ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len)) != -1) {
set_filelen_write_cache(fsp, len);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
return ret;
}
/* Grow - we need to test if we have enough space. */
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
if (lp_strict_allocate(SNUM(fsp->conn))) {
/* See if we have a syscall that will allocate beyond
end-of-file without changing EOF. */
ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
0, len);
} else {
ret = 0;
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
if (ret == 0) {
/* We changed the allocation size on disk, but not
EOF - exactly as required. We're done ! */
return 0;
}
if (ret == -1 && errno == ENOSPC) {
return -1;
}
len -= fsp->fsp_name->st.st_ex_size;
len /= 1024; /* Len is now number of 1k blocks needed. */
space_avail = get_dfree_info(conn, fsp->fsp_name->base_name,
&bsize, &dfree, &dsize);
if (space_avail == (uint64_t)-1) {
return -1;
}
DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
"needed blocks = %.0f, space avail = %.0f\n",
fsp_str_dbg(fsp), (double)fsp->fsp_name->st.st_ex_size, (double)len,
(double)space_avail));
if (len > space_avail) {
errno = ENOSPC;
return -1;
}
return 0;
}
|
Bypass
| 0
|
int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
{
int ret;
connection_struct *conn = fsp->conn;
uint64_t space_avail;
uint64_t bsize,dfree,dsize;
NTSTATUS status;
/*
* Actually try and commit the space on disk....
*/
DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
fsp_str_dbg(fsp), (double)len));
if (((off_t)len) < 0) {
DEBUG(0,("vfs_allocate_file_space: %s negative len "
"requested.\n", fsp_str_dbg(fsp)));
errno = EINVAL;
return -1;
}
status = vfs_stat_fsp(fsp);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
return 0;
if (len < (uint64_t)fsp->fsp_name->st.st_ex_size) {
/* Shrink - use ftruncate. */
DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
"size %.0f\n", fsp_str_dbg(fsp),
(double)fsp->fsp_name->st.st_ex_size));
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
if ((ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len)) != -1) {
set_filelen_write_cache(fsp, len);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
return ret;
}
/* Grow - we need to test if we have enough space. */
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
if (lp_strict_allocate(SNUM(fsp->conn))) {
/* See if we have a syscall that will allocate beyond
end-of-file without changing EOF. */
ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
0, len);
} else {
ret = 0;
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
if (ret == 0) {
/* We changed the allocation size on disk, but not
EOF - exactly as required. We're done ! */
return 0;
}
if (ret == -1 && errno == ENOSPC) {
return -1;
}
len -= fsp->fsp_name->st.st_ex_size;
len /= 1024; /* Len is now number of 1k blocks needed. */
space_avail = get_dfree_info(conn, fsp->fsp_name->base_name,
&bsize, &dfree, &dsize);
if (space_avail == (uint64_t)-1) {
return -1;
}
DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
"needed blocks = %.0f, space avail = %.0f\n",
fsp_str_dbg(fsp), (double)fsp->fsp_name->st.st_ex_size, (double)len,
(double)space_avail));
if (len > space_avail) {
errno = ENOSPC;
return -1;
}
return 0;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,121
|
void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *head;
head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
if (head != NULL) {
return EXT_DATA_AREA(head);
}
return NULL;
}
|
Bypass
| 0
|
void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *head;
head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
if (head != NULL) {
return EXT_DATA_AREA(head);
}
return NULL;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,122
|
NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
{
/* Only return OK if stat was successful and S_ISREG */
if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
S_ISREG(smb_fname->st.st_ex_mode)) {
return NT_STATUS_OK;
}
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
|
Bypass
| 0
|
NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
{
/* Only return OK if stat was successful and S_ISREG */
if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
S_ISREG(smb_fname->st.st_ex_mode)) {
return NT_STATUS_OK;
}
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,123
|
int vfs_fill_sparse(files_struct *fsp, off_t len)
{
int ret;
NTSTATUS status;
off_t offset;
size_t num_to_write;
status = vfs_stat_fsp(fsp);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
if (len <= fsp->fsp_name->st.st_ex_size) {
return 0;
}
#ifdef S_ISFIFO
if (S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
return 0;
}
#endif
DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
"len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp),
(double)fsp->fsp_name->st.st_ex_size, (double)len,
(double)(len - fsp->fsp_name->st.st_ex_size)));
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
offset = fsp->fsp_name->st.st_ex_size;
num_to_write = len - fsp->fsp_name->st.st_ex_size;
/* Only do this on non-stream file handles. */
if (fsp->base_fsp == NULL) {
/* for allocation try fallocate first. This can fail on some
* platforms e.g. when the filesystem doesn't support it and no
* emulation is being done by the libc (like on AIX with JFS1). In that
* case we do our own emulation. fallocate implementations can
* return ENOTSUP or EINVAL in cases like that. */
ret = SMB_VFS_FALLOCATE(fsp, 0, offset, num_to_write);
if (ret == -1 && errno == ENOSPC) {
goto out;
}
if (ret == 0) {
goto out;
}
DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
"error %d. Falling back to slow manual allocation\n", ret));
}
ret = vfs_slow_fallocate(fsp, offset, num_to_write);
out:
if (ret == 0) {
set_filelen_write_cache(fsp, len);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
return ret;
}
|
Bypass
| 0
|
int vfs_fill_sparse(files_struct *fsp, off_t len)
{
int ret;
NTSTATUS status;
off_t offset;
size_t num_to_write;
status = vfs_stat_fsp(fsp);
if (!NT_STATUS_IS_OK(status)) {
return -1;
}
if (len <= fsp->fsp_name->st.st_ex_size) {
return 0;
}
#ifdef S_ISFIFO
if (S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
return 0;
}
#endif
DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
"len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp),
(double)fsp->fsp_name->st.st_ex_size, (double)len,
(double)(len - fsp->fsp_name->st.st_ex_size)));
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
offset = fsp->fsp_name->st.st_ex_size;
num_to_write = len - fsp->fsp_name->st.st_ex_size;
/* Only do this on non-stream file handles. */
if (fsp->base_fsp == NULL) {
/* for allocation try fallocate first. This can fail on some
* platforms e.g. when the filesystem doesn't support it and no
* emulation is being done by the libc (like on AIX with JFS1). In that
* case we do our own emulation. fallocate implementations can
* return ENOTSUP or EINVAL in cases like that. */
ret = SMB_VFS_FALLOCATE(fsp, 0, offset, num_to_write);
if (ret == -1 && errno == ENOSPC) {
goto out;
}
if (ret == 0) {
goto out;
}
DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
"error %d. Falling back to slow manual allocation\n", ret));
}
ret = vfs_slow_fallocate(fsp, offset, num_to_write);
out:
if (ret == 0) {
set_filelen_write_cache(fsp, len);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
return ret;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,124
|
bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
{
char *module_path = NULL;
char *module_name = NULL;
char *module_param = NULL, *p;
vfs_handle_struct *handle;
const struct vfs_init_function_entry *entry;
if (!conn||!vfs_object||!vfs_object[0]) {
DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
"empty vfs_object!\n"));
return False;
}
if(!backends) {
static_init_vfs;
}
DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
module_path = smb_xstrdup(vfs_object);
p = strchr_m(module_path, ':');
if (p) {
*p = 0;
module_param = p+1;
trim_char(module_param, ' ', ' ');
}
trim_char(module_path, ' ', ' ');
module_name = smb_xstrdup(module_path);
if ((module_name[0] == '/') &&
(strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
/*
* Extract the module name from the path. Just use the base
* name of the last path component.
*/
SAFE_FREE(module_name);
module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
p = strchr_m(module_name, '.');
if (p != NULL) {
*p = '\0';
}
}
/* First, try to load the module with the new module system */
entry = vfs_find_backend_entry(module_name);
if (!entry) {
NTSTATUS status;
DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
vfs_object));
status = smb_load_module("vfs", module_path);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("error probing vfs module '%s': %s\n",
module_path, nt_errstr(status)));
goto fail;
}
entry = vfs_find_backend_entry(module_name);
if (!entry) {
DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
goto fail;
}
}
DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
handle = talloc_zero(conn, vfs_handle_struct);
if (!handle) {
DEBUG(0,("TALLOC_ZERO() failed!\n"));
goto fail;
}
handle->conn = conn;
handle->fns = entry->fns;
if (module_param) {
handle->param = talloc_strdup(conn, module_param);
}
DLIST_ADD(conn->vfs_handles, handle);
SAFE_FREE(module_path);
SAFE_FREE(module_name);
return True;
fail:
SAFE_FREE(module_path);
SAFE_FREE(module_name);
return False;
}
|
Bypass
| 0
|
bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
{
char *module_path = NULL;
char *module_name = NULL;
char *module_param = NULL, *p;
vfs_handle_struct *handle;
const struct vfs_init_function_entry *entry;
if (!conn||!vfs_object||!vfs_object[0]) {
DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
"empty vfs_object!\n"));
return False;
}
if(!backends) {
static_init_vfs;
}
DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
module_path = smb_xstrdup(vfs_object);
p = strchr_m(module_path, ':');
if (p) {
*p = 0;
module_param = p+1;
trim_char(module_param, ' ', ' ');
}
trim_char(module_path, ' ', ' ');
module_name = smb_xstrdup(module_path);
if ((module_name[0] == '/') &&
(strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
/*
* Extract the module name from the path. Just use the base
* name of the last path component.
*/
SAFE_FREE(module_name);
module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
p = strchr_m(module_name, '.');
if (p != NULL) {
*p = '\0';
}
}
/* First, try to load the module with the new module system */
entry = vfs_find_backend_entry(module_name);
if (!entry) {
NTSTATUS status;
DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
vfs_object));
status = smb_load_module("vfs", module_path);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("error probing vfs module '%s': %s\n",
module_path, nt_errstr(status)));
goto fail;
}
entry = vfs_find_backend_entry(module_name);
if (!entry) {
DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
goto fail;
}
}
DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
handle = talloc_zero(conn, vfs_handle_struct);
if (!handle) {
DEBUG(0,("TALLOC_ZERO() failed!\n"));
goto fail;
}
handle->conn = conn;
handle->fns = entry->fns;
if (module_param) {
handle->param = talloc_strdup(conn, module_param);
}
DLIST_ADD(conn->vfs_handles, handle);
SAFE_FREE(module_path);
SAFE_FREE(module_name);
return True;
fail:
SAFE_FREE(module_path);
SAFE_FREE(module_name);
return False;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,125
|
static void vfs_init_default(connection_struct *conn)
{
DEBUG(3, ("Initialising default vfs hooks\n"));
vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
}
|
Bypass
| 0
|
static void vfs_init_default(connection_struct *conn)
{
DEBUG(3, ("Initialising default vfs hooks\n"));
vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,126
|
void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *head;
for (head = fsp->vfs_extension; head; head = head->next) {
if (head->owner == handle) {
return head;
}
}
return NULL;
}
|
Bypass
| 0
|
void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *head;
for (head = fsp->vfs_extension; head; head = head->next) {
if (head->owner == handle) {
return head;
}
}
return NULL;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,127
|
static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset)
{
struct files_struct *fsp = (struct files_struct *)file;
return SMB_VFS_PWRITE(fsp, buf, len, offset);
}
|
Bypass
| 0
|
static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset)
{
struct files_struct *fsp = (struct files_struct *)file;
return SMB_VFS_PWRITE(fsp, buf, len, offset);
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,128
|
ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
{
size_t total=0;
while (total < byte_count)
{
ssize_t ret = SMB_VFS_READ(fsp, buf + total,
byte_count - total);
if (ret == 0) return total;
if (ret == -1) {
if (errno == EINTR)
continue;
else
return -1;
}
total += ret;
}
return (ssize_t)total;
}
|
Bypass
| 0
|
ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
{
size_t total=0;
while (total < byte_count)
{
ssize_t ret = SMB_VFS_READ(fsp, buf + total,
byte_count - total);
if (ret == 0) return total;
if (ret == -1) {
if (errno == EINTR)
continue;
else
return -1;
}
total += ret;
}
return (ssize_t)total;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,129
|
void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *curr;
struct vfs_fsp_data *prev;
for (curr = fsp->vfs_extension, prev = NULL;
curr;
prev = curr, curr = curr->next) {
if (curr->owner == handle) {
if (prev) {
prev->next = curr->next;
} else {
fsp->vfs_extension = curr->next;
}
if (curr->destroy) {
curr->destroy(EXT_DATA_AREA(curr));
}
TALLOC_FREE(curr);
return;
}
}
}
|
Bypass
| 0
|
void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
{
struct vfs_fsp_data *curr;
struct vfs_fsp_data *prev;
for (curr = fsp->vfs_extension, prev = NULL;
curr;
prev = curr, curr = curr->next) {
if (curr->owner == handle) {
if (prev) {
prev->next = curr->next;
} else {
fsp->vfs_extension = curr->next;
}
if (curr->destroy) {
curr->destroy(EXT_DATA_AREA(curr));
}
TALLOC_FREE(curr);
return;
}
}
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,130
|
int vfs_set_filelen(files_struct *fsp, off_t len)
{
int ret;
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
fsp_str_dbg(fsp), (double)len));
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
set_filelen_write_cache(fsp, len);
notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
FILE_NOTIFY_CHANGE_SIZE
| FILE_NOTIFY_CHANGE_ATTRIBUTES,
fsp->fsp_name->base_name);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
return ret;
}
|
Bypass
| 0
|
int vfs_set_filelen(files_struct *fsp, off_t len)
{
int ret;
contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
fsp_str_dbg(fsp), (double)len));
flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
set_filelen_write_cache(fsp, len);
notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
FILE_NOTIFY_CHANGE_SIZE
| FILE_NOTIFY_CHANGE_ATTRIBUTES,
fsp->fsp_name->base_name);
}
contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
return ret;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,131
|
int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
{
ssize_t pwrite_ret;
size_t total = 0;
if (!sparse_buf) {
sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
if (!sparse_buf) {
errno = ENOMEM;
return -1;
}
}
while (total < len) {
size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total));
pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
if (pwrite_ret == -1) {
int saved_errno = errno;
DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
"%s failed with error %s\n",
fsp_str_dbg(fsp), strerror(saved_errno)));
errno = saved_errno;
return -1;
}
total += pwrite_ret;
}
return 0;
}
|
Bypass
| 0
|
int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
{
ssize_t pwrite_ret;
size_t total = 0;
if (!sparse_buf) {
sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
if (!sparse_buf) {
errno = ENOMEM;
return -1;
}
}
while (total < len) {
size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total));
pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
if (pwrite_ret == -1) {
int saved_errno = errno;
DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
"%s failed with error %s\n",
fsp_str_dbg(fsp), strerror(saved_errno)));
errno = saved_errno;
return -1;
}
total += pwrite_ret;
}
return 0;
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,132
|
off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n)
{
return transfer_file_internal((void *)in, (void *)out, n,
vfs_pread_fn, vfs_pwrite_fn);
}
|
Bypass
| 0
|
off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n)
{
return transfer_file_internal((void *)in, (void *)out, n,
vfs_pread_fn, vfs_pwrite_fn);
}
|
@@ -982,6 +982,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
struct smb_filename *smb_fname_cwd = NULL;
struct privilege_paths *priv_paths = NULL;
int ret;
+ bool matched;
DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
fname,
@@ -1076,7 +1077,10 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name, rootdir_len) == 0);
+
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
"attempt: %s is a symlink outside the "
"share path\n",
@@ -1216,6 +1220,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
if (!allow_widelinks || !allow_symlinks) {
const char *conn_rootdir;
size_t rootdir_len;
+ bool matched;
conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
if (conn_rootdir == NULL) {
@@ -1226,8 +1231,10 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
}
rootdir_len = strlen(conn_rootdir);
- if (strncmp(conn_rootdir, resolved_name,
- rootdir_len) != 0) {
+ matched = (strncmp(conn_rootdir, resolved_name,
+ rootdir_len) == 0);
+ if (!matched || (resolved_name[rootdir_len] != '/' &&
+ resolved_name[rootdir_len] != '\0')) {
DEBUG(2, ("check_reduced_name: Bad access "
"attempt: %s is a symlink outside the "
"share path\n", fname));
|
CWE-264
| null | null |
2,133
|
another_hunk (enum diff difftype, bool rev)
{
char *s;
lin context = 0;
size_t chars_read;
char numbuf0[LINENUM_LENGTH_BOUND + 1];
char numbuf1[LINENUM_LENGTH_BOUND + 1];
char numbuf2[LINENUM_LENGTH_BOUND + 1];
char numbuf3[LINENUM_LENGTH_BOUND + 1];
set_hunkmax();
while (p_end >= 0) {
if (p_end == p_efake)
p_end = p_bfake; /* don't free twice */
else
free(p_line[p_end]);
p_end--;
}
assert(p_end == -1);
p_efake = -1;
if (p_c_function)
{
free (p_c_function);
p_c_function = NULL;
}
p_max = hunkmax; /* gets reduced when --- found */
if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) {
file_offset line_beginning = file_tell (pfp);
/* file pos of the current line */
lin repl_beginning = 0; /* index of --- line */
lin fillcnt = 0; /* #lines of missing ptrn or repl */
lin fillsrc; /* index of first line to copy */
lin filldst; /* index of first missing line */
bool ptrn_spaces_eaten = false; /* ptrn was slightly misformed */
bool some_context = false; /* (perhaps internal) context seen */
bool repl_could_be_missing = true;
bool ptrn_missing = false; /* The pattern was missing. */
bool repl_missing = false; /* Likewise for replacement. */
file_offset repl_backtrack_position = 0;
/* file pos of first repl line */
lin repl_patch_line; /* input line number for same */
lin repl_context; /* context for same */
lin ptrn_prefix_context = -1; /* lines in pattern prefix context */
lin ptrn_suffix_context = -1; /* lines in pattern suffix context */
lin repl_prefix_context = -1; /* lines in replac. prefix context */
lin ptrn_copiable = 0; /* # of copiable lines in ptrn */
lin repl_copiable = 0; /* Likewise for replacement. */
/* Pacify 'gcc -Wall'. */
fillsrc = filldst = repl_patch_line = repl_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 8
|| strncmp (buf, "********", 8) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = buf;
while (*s == '*')
s++;
if (*s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
if (! p_c_function)
return -1;
}
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
return -1;
if (!chars_read) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (p_max - p_end < 4) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 3;
} else {
fatal ("unexpected end of file in patch");
}
}
p_end++;
if (p_end == hunkmax)
fatal ("unterminated hunk starting at line %s; giving up at line %s: %s",
format_linenum (numbuf0, pch_hunk_beg ()),
format_linenum (numbuf1, p_input_line), buf);
assert(p_end < hunkmax);
p_Char[p_end] = *buf;
p_len[p_end] = 0;
p_line[p_end] = 0;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
else
fatal ("unexpected end of hunk at line %s",
format_linenum (numbuf0, p_input_line));
}
if (p_end != 0) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
fatal ("unexpected '***' at line %s: %s",
format_linenum (numbuf0, p_input_line), buf);
}
context = 0;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf))) {
p_end--;
return -1;
}
for (s = buf; *s && !ISDIGIT (*s); s++)
/* do nothing */ ;
if (strnEQ(s,"0,0",3))
remove_prefix (s, 2);
s = scan_linenum (s, &p_first);
if (*s == ',') {
while (*s && !ISDIGIT (*s))
s++;
scan_linenum (s, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
if (p_ptrn_lines < 0)
malformed ();
}
else if (p_first)
p_ptrn_lines = 1;
else {
p_ptrn_lines = 0;
p_first = 1;
}
if (p_first >= LINENUM_MAX - p_ptrn_lines ||
p_ptrn_lines >= LINENUM_MAX - 6)
malformed ();
p_max = p_ptrn_lines + 6; /* we need this much at least */
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
p_max = hunkmax;
break;
case '-':
if (buf[1] != '-')
goto change_line;
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
ptrn_suffix_context = context;
if (repl_beginning
|| (p_end
!= p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n')))
{
if (p_end == 1)
{
/* 'Old' lines were omitted. Set up to fill
them in from 'new' context lines. */
ptrn_missing = true;
p_end = p_ptrn_lines + 1;
ptrn_prefix_context = ptrn_suffix_context = -1;
fillsrc = p_end + 1;
filldst = 1;
fillcnt = p_ptrn_lines;
}
else if (! repl_beginning)
fatal ("%s '---' at line %s; check line numbers at line %s",
(p_end <= p_ptrn_lines
? "Premature"
: "Overdue"),
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1, p_hunk_beg));
else if (! repl_could_be_missing)
fatal ("duplicate '---' at line %s; check line numbers at line %s",
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1,
p_hunk_beg + repl_beginning));
else
{
repl_missing = true;
goto hunk_done;
}
}
repl_beginning = p_end;
repl_backtrack_position = file_tell (pfp);
repl_patch_line = p_input_line;
repl_context = context;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf)))
{
p_end--;
return -1;
}
p_Char[p_end] = '=';
for (s = buf; *s && ! ISDIGIT (*s); s++)
/* do nothing */ ;
s = scan_linenum (s, &p_newfirst);
if (*s == ',')
{
do
{
if (!*++s)
malformed ();
}
while (! ISDIGIT (*s));
scan_linenum (s, &p_repl_lines);
p_repl_lines += 1 - p_newfirst;
if (p_repl_lines < 0)
malformed ();
}
else if (p_newfirst)
p_repl_lines = 1;
else
{
p_repl_lines = 0;
p_newfirst = 1;
}
if (p_newfirst >= LINENUM_MAX - p_repl_lines ||
p_repl_lines >= LINENUM_MAX - p_end)
malformed ();
p_max = p_repl_lines + p_end;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
if (p_repl_lines != ptrn_copiable
&& (p_prefix_context != 0
|| context != 0
|| p_repl_lines != 1))
repl_could_be_missing = false;
context = 0;
break;
case '+': case '!':
repl_could_be_missing = false;
change_line:
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize_ws) {
strcpy (s, " \n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (! repl_beginning)
{
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
}
else
{
if (repl_prefix_context == -1)
repl_prefix_context = context;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
context = 0;
break;
case '\t': case '\n': /* assume spaces got eaten */
s = buf;
if (*buf == '\t') {
s++;
chars_read--;
}
if (repl_beginning && repl_could_be_missing &&
(!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) {
repl_missing = true;
goto hunk_done;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (buf, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
if (p_end != p_ptrn_lines + 1) {
ptrn_spaces_eaten |= (repl_beginning != 0);
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
p_Char[p_end] = ' ';
}
break;
case ' ':
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize_ws) {
strcpy (s, "\n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
break;
default:
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
malformed ();
}
}
hunk_done:
if (p_end >=0 && !repl_beginning)
fatal ("no '---' found in patch at line %s",
format_linenum (numbuf0, pch_hunk_beg ()));
if (repl_missing) {
/* reset state back to just after --- */
p_input_line = repl_patch_line;
context = repl_context;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
Fseek (pfp, repl_backtrack_position, SEEK_SET);
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
fillsrc = 1;
filldst = repl_beginning+1;
fillcnt = p_repl_lines;
p_end = p_max;
}
else if (! ptrn_missing && ptrn_copiable != repl_copiable)
fatal ("context mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
else if (!some_context && fillcnt == 1) {
/* the first hunk was a null hunk with no context */
/* and we were expecting one line -- fix it up. */
while (filldst < p_end) {
p_line[filldst] = p_line[filldst+1];
p_Char[filldst] = p_Char[filldst+1];
p_len[filldst] = p_len[filldst+1];
filldst++;
}
#if 0
repl_beginning--; /* this doesn't need to be fixed */
#endif
p_end--;
p_first++; /* do append rather than insert */
fillcnt = 0;
p_ptrn_lines = 0;
}
p_prefix_context = ((repl_prefix_context == -1
|| (ptrn_prefix_context != -1
&& ptrn_prefix_context < repl_prefix_context))
? ptrn_prefix_context : repl_prefix_context);
p_suffix_context = ((ptrn_suffix_context != -1
&& ptrn_suffix_context < context)
? ptrn_suffix_context : context);
if (p_prefix_context == -1 || p_suffix_context == -1)
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
if (difftype == CONTEXT_DIFF
&& (fillcnt
|| (p_first > 1
&& p_prefix_context + p_suffix_context < ptrn_copiable))) {
if (verbosity == VERBOSE)
say ("%s\n%s\n%s\n",
"(Fascinating -- this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
diff_type = difftype = NEW_CONTEXT_DIFF;
}
/* if there were omitted context lines, fill them in now */
if (fillcnt) {
p_bfake = filldst; /* remember where not to free() */
p_efake = filldst + fillcnt - 1;
while (fillcnt-- > 0) {
while (fillsrc <= p_end && fillsrc != repl_beginning
&& p_Char[fillsrc] != ' ')
fillsrc++;
if (p_end < fillsrc || fillsrc == repl_beginning)
{
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
}
p_line[filldst] = p_line[fillsrc];
p_Char[filldst] = p_Char[fillsrc];
p_len[filldst] = p_len[fillsrc];
fillsrc++; filldst++;
}
while (fillsrc <= p_end && fillsrc != repl_beginning)
{
if (p_Char[fillsrc] == ' ')
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
fillsrc++;
}
if (debug & 64)
printf ("fillsrc %s, filldst %s, rb %s, e+1 %s\n",
format_linenum (numbuf0, fillsrc),
format_linenum (numbuf1, filldst),
format_linenum (numbuf2, repl_beginning),
format_linenum (numbuf3, p_end + 1));
assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
assert(filldst==p_end+1 || filldst==repl_beginning);
}
}
else if (difftype == UNI_DIFF) {
file_offset line_beginning = file_tell (pfp); /* file pos of the current line */
lin fillsrc; /* index of old lines */
lin filldst; /* index of new lines */
char ch = '\0';
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 4
|| strncmp (buf, "@@ -", 4) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf + 4, &p_first);
if (*s == ',')
s = scan_linenum (s + 1, &p_ptrn_lines);
else
p_ptrn_lines = 1;
if (p_first >= LINENUM_MAX - p_ptrn_lines)
malformed ();
if (*s == ' ') s++;
if (*s != '+')
malformed ();
s = scan_linenum (s + 1, &p_newfirst);
if (*s == ',')
s = scan_linenum (s + 1, &p_repl_lines);
else
p_repl_lines = 1;
if (p_newfirst >= LINENUM_MAX - p_repl_lines)
malformed ();
if (*s == ' ') s++;
if (*s++ != '@')
malformed ();
if (*s++ == '@' && *s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
if (! p_c_function)
return -1;
}
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
if (!p_repl_lines)
p_newfirst++;
if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1))
malformed ();
p_max = p_ptrn_lines + p_repl_lines + 1;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
sprintf (buf, "*** %s,%s ****\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
sprintf (buf, "--- %s,%s ----\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_newfirst + p_repl_lines - 1));
p_len[filldst] = strlen (buf);
if (! (p_line[filldst] = savestr (buf))) {
p_end = 0;
return -1;
}
p_Char[filldst++] = '=';
p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
chars_read = get_line ();
if (!chars_read) {
if (p_max - filldst < 3) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 2;
} else {
fatal ("unexpected end of file in patch");
}
}
if (chars_read == (size_t) -1)
s = 0;
else if (*buf == '\t' || *buf == '\n') {
ch = ' '; /* assume the space got eaten */
s = savebuf (buf, chars_read);
}
else {
ch = *buf;
s = savebuf (buf+1, --chars_read);
}
if (chars_read && ! s)
{
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
switch (ch) {
case '-':
if (fillsrc > p_ptrn_lines) {
free(s);
p_end = filldst-1;
malformed ();
}
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
break;
case '=':
ch = ' ';
/* FALL THROUGH */
case ' ':
if (fillsrc > p_ptrn_lines) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
context++;
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
s = savebuf (s, chars_read);
if (chars_read && ! s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
/* FALL THROUGH */
case '+':
if (filldst > p_end) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
chars_read -= filldst == p_end && incomplete_line ();
p_Char[filldst] = ch;
p_line[filldst] = s;
p_len[filldst++] = chars_read;
break;
default:
p_end = filldst;
malformed ();
}
if (ch != ' ') {
if (p_prefix_context == -1)
p_prefix_context = context;
context = 0;
}
}/* while */
if (p_prefix_context == -1)
malformed ();
p_suffix_context = context;
}
else { /* normal diff--fake it up */
char hunk_type;
int i;
lin min, max;
file_offset line_beginning = file_tell (pfp);
p_prefix_context = p_suffix_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf, &p_first);
if (*s == ',') {
s = scan_linenum (s + 1, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else
p_ptrn_lines = (*s != 'a');
if (p_first >= LINENUM_MAX - p_ptrn_lines)
malformed ();
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
s = scan_linenum (s + 1, &min);
if (*s == ',')
scan_linenum (s + 1, &max);
else
max = min;
if (min > max || max - min == LINENUM_MAX)
malformed ();
if (hunk_type == 'd')
min++;
p_newfirst = min;
p_repl_lines = max - min + 1;
if (p_newfirst >= LINENUM_MAX - p_repl_lines)
malformed ();
if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1))
malformed ();
p_end = p_ptrn_lines + p_repl_lines + 1;
while (p_end + 1 >= hunkmax)
if (! grow_hunkmax ())
{
p_end = -1;
return -1;
}
sprintf (buf, "*** %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
for (i=1; i<=p_ptrn_lines; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("'<' followed by space or tab expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '-';
}
if (hunk_type == 'c') {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (! chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (*buf != '-')
fatal ("'---' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
}
sprintf (buf, "--- %s,%s\n",
format_linenum (numbuf0, min),
format_linenum (numbuf1, max));
p_len[i] = strlen (buf);
if (! (p_line[i] = savestr (buf))) {
p_end = i-1;
return -1;
}
p_Char[i] = '=';
for (i++; i<=p_end; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("'>' followed by space or tab expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_end && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '+';
}
}
if (rev) /* backwards patch? */
if (!pch_swap())
say ("Not enough memory to swap next hunk!\n");
assert (p_end + 1 < hunkmax);
p_Char[p_end + 1] = '^'; /* add a stopper for apply_hunk */
if (debug & 2) {
lin i;
for (i = 0; i <= p_end + 1; i++) {
fprintf (stderr, "%s %c",
format_linenum (numbuf0, i),
p_Char[i]);
if (p_Char[i] == '*')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_ptrn_lines));
else if (p_Char[i] == '=')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_repl_lines));
else if (p_Char[i] != '^')
{
fputs(" |", stderr);
pch_write_line (i, stderr);
}
else
fputc('\n', stderr);
}
fflush (stderr);
}
return 1;
}
| null | 0
|
another_hunk (enum diff difftype, bool rev)
{
char *s;
lin context = 0;
size_t chars_read;
char numbuf0[LINENUM_LENGTH_BOUND + 1];
char numbuf1[LINENUM_LENGTH_BOUND + 1];
char numbuf2[LINENUM_LENGTH_BOUND + 1];
char numbuf3[LINENUM_LENGTH_BOUND + 1];
set_hunkmax();
while (p_end >= 0) {
if (p_end == p_efake)
p_end = p_bfake; /* don't free twice */
else
free(p_line[p_end]);
p_end--;
}
assert(p_end == -1);
p_efake = -1;
if (p_c_function)
{
free (p_c_function);
p_c_function = NULL;
}
p_max = hunkmax; /* gets reduced when --- found */
if (difftype == CONTEXT_DIFF || difftype == NEW_CONTEXT_DIFF) {
file_offset line_beginning = file_tell (pfp);
/* file pos of the current line */
lin repl_beginning = 0; /* index of --- line */
lin fillcnt = 0; /* #lines of missing ptrn or repl */
lin fillsrc; /* index of first line to copy */
lin filldst; /* index of first missing line */
bool ptrn_spaces_eaten = false; /* ptrn was slightly misformed */
bool some_context = false; /* (perhaps internal) context seen */
bool repl_could_be_missing = true;
bool ptrn_missing = false; /* The pattern was missing. */
bool repl_missing = false; /* Likewise for replacement. */
file_offset repl_backtrack_position = 0;
/* file pos of first repl line */
lin repl_patch_line; /* input line number for same */
lin repl_context; /* context for same */
lin ptrn_prefix_context = -1; /* lines in pattern prefix context */
lin ptrn_suffix_context = -1; /* lines in pattern suffix context */
lin repl_prefix_context = -1; /* lines in replac. prefix context */
lin ptrn_copiable = 0; /* # of copiable lines in ptrn */
lin repl_copiable = 0; /* Likewise for replacement. */
/* Pacify 'gcc -Wall'. */
fillsrc = filldst = repl_patch_line = repl_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 8
|| strncmp (buf, "********", 8) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = buf;
while (*s == '*')
s++;
if (*s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
if (! p_c_function)
return -1;
}
p_hunk_beg = p_input_line + 1;
while (p_end < p_max) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
return -1;
if (!chars_read) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (p_max - p_end < 4) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 3;
} else {
fatal ("unexpected end of file in patch");
}
}
p_end++;
if (p_end == hunkmax)
fatal ("unterminated hunk starting at line %s; giving up at line %s: %s",
format_linenum (numbuf0, pch_hunk_beg ()),
format_linenum (numbuf1, p_input_line), buf);
assert(p_end < hunkmax);
p_Char[p_end] = *buf;
p_len[p_end] = 0;
p_line[p_end] = 0;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
else
fatal ("unexpected end of hunk at line %s",
format_linenum (numbuf0, p_input_line));
}
if (p_end != 0) {
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
fatal ("unexpected '***' at line %s: %s",
format_linenum (numbuf0, p_input_line), buf);
}
context = 0;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf))) {
p_end--;
return -1;
}
for (s = buf; *s && !ISDIGIT (*s); s++)
/* do nothing */ ;
if (strnEQ(s,"0,0",3))
remove_prefix (s, 2);
s = scan_linenum (s, &p_first);
if (*s == ',') {
while (*s && !ISDIGIT (*s))
s++;
scan_linenum (s, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
if (p_ptrn_lines < 0)
malformed ();
}
else if (p_first)
p_ptrn_lines = 1;
else {
p_ptrn_lines = 0;
p_first = 1;
}
if (p_first >= LINENUM_MAX - p_ptrn_lines ||
p_ptrn_lines >= LINENUM_MAX - 6)
malformed ();
p_max = p_ptrn_lines + 6; /* we need this much at least */
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
p_max = hunkmax;
break;
case '-':
if (buf[1] != '-')
goto change_line;
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
ptrn_suffix_context = context;
if (repl_beginning
|| (p_end
!= p_ptrn_lines + 1 + (p_Char[p_end - 1] == '\n')))
{
if (p_end == 1)
{
/* 'Old' lines were omitted. Set up to fill
them in from 'new' context lines. */
ptrn_missing = true;
p_end = p_ptrn_lines + 1;
ptrn_prefix_context = ptrn_suffix_context = -1;
fillsrc = p_end + 1;
filldst = 1;
fillcnt = p_ptrn_lines;
}
else if (! repl_beginning)
fatal ("%s '---' at line %s; check line numbers at line %s",
(p_end <= p_ptrn_lines
? "Premature"
: "Overdue"),
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1, p_hunk_beg));
else if (! repl_could_be_missing)
fatal ("duplicate '---' at line %s; check line numbers at line %s",
format_linenum (numbuf0, p_input_line),
format_linenum (numbuf1,
p_hunk_beg + repl_beginning));
else
{
repl_missing = true;
goto hunk_done;
}
}
repl_beginning = p_end;
repl_backtrack_position = file_tell (pfp);
repl_patch_line = p_input_line;
repl_context = context;
p_len[p_end] = strlen (buf);
if (! (p_line[p_end] = savestr (buf)))
{
p_end--;
return -1;
}
p_Char[p_end] = '=';
for (s = buf; *s && ! ISDIGIT (*s); s++)
/* do nothing */ ;
s = scan_linenum (s, &p_newfirst);
if (*s == ',')
{
do
{
if (!*++s)
malformed ();
}
while (! ISDIGIT (*s));
scan_linenum (s, &p_repl_lines);
p_repl_lines += 1 - p_newfirst;
if (p_repl_lines < 0)
malformed ();
}
else if (p_newfirst)
p_repl_lines = 1;
else
{
p_repl_lines = 0;
p_newfirst = 1;
}
if (p_newfirst >= LINENUM_MAX - p_repl_lines ||
p_repl_lines >= LINENUM_MAX - p_end)
malformed ();
p_max = p_repl_lines + p_end;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
if (p_repl_lines != ptrn_copiable
&& (p_prefix_context != 0
|| context != 0
|| p_repl_lines != 1))
repl_could_be_missing = false;
context = 0;
break;
case '+': case '!':
repl_could_be_missing = false;
change_line:
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize_ws) {
strcpy (s, " \n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
if (! repl_beginning)
{
if (ptrn_prefix_context == -1)
ptrn_prefix_context = context;
}
else
{
if (repl_prefix_context == -1)
repl_prefix_context = context;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
context = 0;
break;
case '\t': case '\n': /* assume spaces got eaten */
s = buf;
if (*buf == '\t') {
s++;
chars_read--;
}
if (repl_beginning && repl_could_be_missing &&
(!ptrn_spaces_eaten || difftype == NEW_CONTEXT_DIFF) ) {
repl_missing = true;
goto hunk_done;
}
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (buf, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
if (p_end != p_ptrn_lines + 1) {
ptrn_spaces_eaten |= (repl_beginning != 0);
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
p_Char[p_end] = ' ';
}
break;
case ' ':
s = buf + 1;
chars_read--;
if (*s == '\n' && canonicalize_ws) {
strcpy (s, "\n");
chars_read = 2;
}
if (*s == ' ' || *s == '\t') {
s++;
chars_read--;
} else if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
some_context = true;
context++;
if (repl_beginning)
repl_copiable++;
else
ptrn_copiable++;
chars_read -=
(1 < chars_read
&& p_end == (repl_beginning ? p_max : p_ptrn_lines)
&& incomplete_line ());
p_len[p_end] = chars_read;
p_line[p_end] = savebuf (s, chars_read);
if (chars_read && ! p_line[p_end]) {
p_end--;
return -1;
}
break;
default:
if (repl_beginning && repl_could_be_missing) {
repl_missing = true;
goto hunk_done;
}
malformed ();
}
}
hunk_done:
if (p_end >=0 && !repl_beginning)
fatal ("no '---' found in patch at line %s",
format_linenum (numbuf0, pch_hunk_beg ()));
if (repl_missing) {
/* reset state back to just after --- */
p_input_line = repl_patch_line;
context = repl_context;
for (p_end--; p_end > repl_beginning; p_end--)
free(p_line[p_end]);
Fseek (pfp, repl_backtrack_position, SEEK_SET);
/* redundant 'new' context lines were omitted - set */
/* up to fill them in from the old file context */
fillsrc = 1;
filldst = repl_beginning+1;
fillcnt = p_repl_lines;
p_end = p_max;
}
else if (! ptrn_missing && ptrn_copiable != repl_copiable)
fatal ("context mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
else if (!some_context && fillcnt == 1) {
/* the first hunk was a null hunk with no context */
/* and we were expecting one line -- fix it up. */
while (filldst < p_end) {
p_line[filldst] = p_line[filldst+1];
p_Char[filldst] = p_Char[filldst+1];
p_len[filldst] = p_len[filldst+1];
filldst++;
}
#if 0
repl_beginning--; /* this doesn't need to be fixed */
#endif
p_end--;
p_first++; /* do append rather than insert */
fillcnt = 0;
p_ptrn_lines = 0;
}
p_prefix_context = ((repl_prefix_context == -1
|| (ptrn_prefix_context != -1
&& ptrn_prefix_context < repl_prefix_context))
? ptrn_prefix_context : repl_prefix_context);
p_suffix_context = ((ptrn_suffix_context != -1
&& ptrn_suffix_context < context)
? ptrn_suffix_context : context);
if (p_prefix_context == -1 || p_suffix_context == -1)
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
if (difftype == CONTEXT_DIFF
&& (fillcnt
|| (p_first > 1
&& p_prefix_context + p_suffix_context < ptrn_copiable))) {
if (verbosity == VERBOSE)
say ("%s\n%s\n%s\n",
"(Fascinating -- this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
diff_type = difftype = NEW_CONTEXT_DIFF;
}
/* if there were omitted context lines, fill them in now */
if (fillcnt) {
p_bfake = filldst; /* remember where not to free() */
p_efake = filldst + fillcnt - 1;
while (fillcnt-- > 0) {
while (fillsrc <= p_end && fillsrc != repl_beginning
&& p_Char[fillsrc] != ' ')
fillsrc++;
if (p_end < fillsrc || fillsrc == repl_beginning)
{
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
}
p_line[filldst] = p_line[fillsrc];
p_Char[filldst] = p_Char[fillsrc];
p_len[filldst] = p_len[fillsrc];
fillsrc++; filldst++;
}
while (fillsrc <= p_end && fillsrc != repl_beginning)
{
if (p_Char[fillsrc] == ' ')
fatal ("replacement text or line numbers mangled in hunk at line %s",
format_linenum (numbuf0, p_hunk_beg));
fillsrc++;
}
if (debug & 64)
printf ("fillsrc %s, filldst %s, rb %s, e+1 %s\n",
format_linenum (numbuf0, fillsrc),
format_linenum (numbuf1, filldst),
format_linenum (numbuf2, repl_beginning),
format_linenum (numbuf3, p_end + 1));
assert(fillsrc==p_end+1 || fillsrc==repl_beginning);
assert(filldst==p_end+1 || filldst==repl_beginning);
}
}
else if (difftype == UNI_DIFF) {
file_offset line_beginning = file_tell (pfp); /* file pos of the current line */
lin fillsrc; /* index of old lines */
lin filldst; /* index of new lines */
char ch = '\0';
chars_read = get_line ();
if (chars_read == (size_t) -1
|| chars_read <= 4
|| strncmp (buf, "@@ -", 4) != 0) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf + 4, &p_first);
if (*s == ',')
s = scan_linenum (s + 1, &p_ptrn_lines);
else
p_ptrn_lines = 1;
if (p_first >= LINENUM_MAX - p_ptrn_lines)
malformed ();
if (*s == ' ') s++;
if (*s != '+')
malformed ();
s = scan_linenum (s + 1, &p_newfirst);
if (*s == ',')
s = scan_linenum (s + 1, &p_repl_lines);
else
p_repl_lines = 1;
if (p_newfirst >= LINENUM_MAX - p_repl_lines)
malformed ();
if (*s == ' ') s++;
if (*s++ != '@')
malformed ();
if (*s++ == '@' && *s == ' ')
{
p_c_function = s;
while (*s != '\n')
s++;
*s = '\0';
p_c_function = savestr (p_c_function);
if (! p_c_function)
return -1;
}
if (!p_ptrn_lines)
p_first++; /* do append rather than insert */
if (!p_repl_lines)
p_newfirst++;
if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1))
malformed ();
p_max = p_ptrn_lines + p_repl_lines + 1;
while (p_max + 1 >= hunkmax)
if (! grow_hunkmax ())
return -1;
fillsrc = 1;
filldst = fillsrc + p_ptrn_lines;
p_end = filldst + p_repl_lines;
sprintf (buf, "*** %s,%s ****\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
sprintf (buf, "--- %s,%s ----\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_newfirst + p_repl_lines - 1));
p_len[filldst] = strlen (buf);
if (! (p_line[filldst] = savestr (buf))) {
p_end = 0;
return -1;
}
p_Char[filldst++] = '=';
p_prefix_context = -1;
p_hunk_beg = p_input_line + 1;
while (fillsrc <= p_ptrn_lines || filldst <= p_end) {
chars_read = get_line ();
if (!chars_read) {
if (p_max - filldst < 3) {
strcpy (buf, " \n"); /* assume blank lines got chopped */
chars_read = 2;
} else {
fatal ("unexpected end of file in patch");
}
}
if (chars_read == (size_t) -1)
s = 0;
else if (*buf == '\t' || *buf == '\n') {
ch = ' '; /* assume the space got eaten */
s = savebuf (buf, chars_read);
}
else {
ch = *buf;
s = savebuf (buf+1, --chars_read);
}
if (chars_read && ! s)
{
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
switch (ch) {
case '-':
if (fillsrc > p_ptrn_lines) {
free(s);
p_end = filldst-1;
malformed ();
}
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
break;
case '=':
ch = ' ';
/* FALL THROUGH */
case ' ':
if (fillsrc > p_ptrn_lines) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
context++;
chars_read -= fillsrc == p_ptrn_lines && incomplete_line ();
p_Char[fillsrc] = ch;
p_line[fillsrc] = s;
p_len[fillsrc++] = chars_read;
s = savebuf (s, chars_read);
if (chars_read && ! s) {
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
return -1;
}
/* FALL THROUGH */
case '+':
if (filldst > p_end) {
free(s);
while (--filldst > p_ptrn_lines)
free(p_line[filldst]);
p_end = fillsrc-1;
malformed ();
}
chars_read -= filldst == p_end && incomplete_line ();
p_Char[filldst] = ch;
p_line[filldst] = s;
p_len[filldst++] = chars_read;
break;
default:
p_end = filldst;
malformed ();
}
if (ch != ' ') {
if (p_prefix_context == -1)
p_prefix_context = context;
context = 0;
}
}/* while */
if (p_prefix_context == -1)
malformed ();
p_suffix_context = context;
}
else { /* normal diff--fake it up */
char hunk_type;
int i;
lin min, max;
file_offset line_beginning = file_tell (pfp);
p_prefix_context = p_suffix_context = 0;
chars_read = get_line ();
if (chars_read == (size_t) -1 || !chars_read || !ISDIGIT (*buf)) {
next_intuit_at(line_beginning,p_input_line);
return chars_read == (size_t) -1 ? -1 : 0;
}
s = scan_linenum (buf, &p_first);
if (*s == ',') {
s = scan_linenum (s + 1, &p_ptrn_lines);
p_ptrn_lines += 1 - p_first;
}
else
p_ptrn_lines = (*s != 'a');
if (p_first >= LINENUM_MAX - p_ptrn_lines)
malformed ();
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
s = scan_linenum (s + 1, &min);
if (*s == ',')
scan_linenum (s + 1, &max);
else
max = min;
if (min > max || max - min == LINENUM_MAX)
malformed ();
if (hunk_type == 'd')
min++;
p_newfirst = min;
p_repl_lines = max - min + 1;
if (p_newfirst >= LINENUM_MAX - p_repl_lines)
malformed ();
if (p_ptrn_lines >= LINENUM_MAX - (p_repl_lines + 1))
malformed ();
p_end = p_ptrn_lines + p_repl_lines + 1;
while (p_end + 1 >= hunkmax)
if (! grow_hunkmax ())
{
p_end = -1;
return -1;
}
sprintf (buf, "*** %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_first + p_ptrn_lines - 1));
p_len[0] = strlen (buf);
if (! (p_line[0] = savestr (buf))) {
p_end = -1;
return -1;
}
p_Char[0] = '*';
for (i=1; i<=p_ptrn_lines; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '<' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("'<' followed by space or tab expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_ptrn_lines && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '-';
}
if (hunk_type == 'c') {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (! chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (*buf != '-')
fatal ("'---' expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
}
sprintf (buf, "--- %s,%s\n",
format_linenum (numbuf0, min),
format_linenum (numbuf1, max));
p_len[i] = strlen (buf);
if (! (p_line[i] = savestr (buf))) {
p_end = i-1;
return -1;
}
p_Char[i] = '=';
for (i++; i<=p_end; i++) {
chars_read = get_line ();
if (chars_read == (size_t) -1)
{
p_end = i - 1;
return -1;
}
if (!chars_read)
fatal ("unexpected end of file in patch at line %s",
format_linenum (numbuf0, p_input_line));
if (buf[0] != '>' || (buf[1] != ' ' && buf[1] != '\t'))
fatal ("'>' followed by space or tab expected at line %s of patch",
format_linenum (numbuf0, p_input_line));
chars_read -= 2 + (i == p_end && incomplete_line ());
p_len[i] = chars_read;
p_line[i] = savebuf (buf + 2, chars_read);
if (chars_read && ! p_line[i]) {
p_end = i-1;
return -1;
}
p_Char[i] = '+';
}
}
if (rev) /* backwards patch? */
if (!pch_swap())
say ("Not enough memory to swap next hunk!\n");
assert (p_end + 1 < hunkmax);
p_Char[p_end + 1] = '^'; /* add a stopper for apply_hunk */
if (debug & 2) {
lin i;
for (i = 0; i <= p_end + 1; i++) {
fprintf (stderr, "%s %c",
format_linenum (numbuf0, i),
p_Char[i]);
if (p_Char[i] == '*')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_first),
format_linenum (numbuf1, p_ptrn_lines));
else if (p_Char[i] == '=')
fprintf (stderr, " %s,%s\n",
format_linenum (numbuf0, p_newfirst),
format_linenum (numbuf1, p_repl_lines));
else if (p_Char[i] != '^')
{
fputs(" |", stderr);
pch_write_line (i, stderr);
}
else
fputc('\n', stderr);
}
fflush (stderr);
}
return 1;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,134
|
best_name (char *const *name, int const *ignore)
{
enum nametype i;
int components[3];
int components_min = INT_MAX;
size_t basename_len[3];
size_t basename_len_min = SIZE_MAX;
size_t len[3];
size_t len_min = SIZE_MAX;
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i])
{
/* Take the names with the fewest prefix components. */
components[i] = prefix_components (name[i], false);
if (components_min < components[i])
continue;
components_min = components[i];
/* Of those, take the names with the shortest basename. */
basename_len[i] = base_len (name[i]);
if (basename_len_min < basename_len[i])
continue;
basename_len_min = basename_len[i];
/* Of those, take the shortest names. */
len[i] = strlen (name[i]);
if (len_min < len[i])
continue;
len_min = len[i];
}
/* Of those, take the first name. */
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i]
&& name_is_valid (name[i])
&& components[i] == components_min
&& basename_len[i] == basename_len_min
&& len[i] == len_min)
break;
return i;
}
| null | 0
|
best_name (char *const *name, int const *ignore)
{
enum nametype i;
int components[3];
int components_min = INT_MAX;
size_t basename_len[3];
size_t basename_len_min = SIZE_MAX;
size_t len[3];
size_t len_min = SIZE_MAX;
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i])
{
/* Take the names with the fewest prefix components. */
components[i] = prefix_components (name[i], false);
if (components_min < components[i])
continue;
components_min = components[i];
/* Of those, take the names with the shortest basename. */
basename_len[i] = base_len (name[i]);
if (basename_len_min < basename_len[i])
continue;
basename_len_min = basename_len[i];
/* Of those, take the shortest names. */
len[i] = strlen (name[i]);
if (len_min < len[i])
continue;
len_min = len[i];
}
/* Of those, take the first name. */
for (i = OLD; i <= INDEX; i++)
if (name[i] && !ignore[i]
&& name_is_valid (name[i])
&& components[i] == components_min
&& basename_len[i] == basename_len_min
&& len[i] == len_min)
break;
return i;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,135
|
fetchmode (char const *str)
{
const char *s;
mode_t mode;
while (ISSPACE ((unsigned char) *str))
str++;
for (s = str, mode = 0; s < str + 6; s++)
{
if (*s >= '0' && *s <= '7')
mode = (mode << 3) + (*s - '0');
else
{
mode = 0;
break;
}
}
if (*s == '\r')
s++;
if (*s != '\n')
mode = 0;
/* NOTE: The "diff --git" format always sets the file mode permission
bits of symlinks to 0. (On Linux, symlinks actually always have
0777 permissions, so this is not even consistent.) */
return mode;
}
| null | 0
|
fetchmode (char const *str)
{
const char *s;
mode_t mode;
while (ISSPACE ((unsigned char) *str))
str++;
for (s = str, mode = 0; s < str + 6; s++)
{
if (*s >= '0' && *s <= '7')
mode = (mode << 3) + (*s - '0');
else
{
mode = 0;
break;
}
}
if (*s == '\r')
s++;
if (*s != '\n')
mode = 0;
/* NOTE: The "diff --git" format always sets the file mode permission
bits of symlinks to 0. (On Linux, symlinks actually always have
0777 permissions, so this is not even consistent.) */
return mode;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,136
|
get_line (void)
{
return pget_line (p_indent, p_rfc934_nesting, p_strip_trailing_cr,
p_pass_comments_through);
}
| null | 0
|
get_line (void)
{
return pget_line (p_indent, p_rfc934_nesting, p_strip_trailing_cr,
p_pass_comments_through);
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,137
|
get_sha1(char **sha1, char const *start, char const *end)
{
unsigned int len = end - start;
*sha1 = xmalloc (len + 1);
memcpy (*sha1, start, len);
(*sha1)[len] = 0;
}
| null | 0
|
get_sha1(char **sha1, char const *start, char const *end)
{
unsigned int len = end - start;
*sha1 = xmalloc (len + 1);
memcpy (*sha1, start, len);
(*sha1)[len] = 0;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,138
|
grow_hunkmax (void)
{
hunkmax *= 2;
assert (p_line && p_len && p_Char);
if ((p_line = realloc (p_line, hunkmax * sizeof (*p_line)))
&& (p_len = realloc (p_len, hunkmax * sizeof (*p_len)))
&& (p_Char = realloc (p_Char, hunkmax * sizeof (*p_Char))))
return true;
if (!using_plan_a)
xalloc_die ();
/* Don't free previous values of p_line etc.,
since some broken implementations free them for us.
Whatever is null will be allocated again from within plan_a (),
of all places. */
return false;
}
| null | 0
|
grow_hunkmax (void)
{
hunkmax *= 2;
assert (p_line && p_len && p_Char);
if ((p_line = realloc (p_line, hunkmax * sizeof (*p_line)))
&& (p_len = realloc (p_len, hunkmax * sizeof (*p_len)))
&& (p_Char = realloc (p_Char, hunkmax * sizeof (*p_Char))))
return true;
if (!using_plan_a)
xalloc_die ();
/* Don't free previous values of p_line etc.,
since some broken implementations free them for us.
Whatever is null will be allocated again from within plan_a (),
of all places. */
return false;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,139
|
incomplete_line (void)
{
FILE *fp = pfp;
int c;
file_offset line_beginning = file_tell (fp);
if (getc (fp) == '\\')
{
while ((c = getc (fp)) != '\n' && c != EOF)
/* do nothing */ ;
return true;
}
else
{
/* We don't trust ungetc. */
Fseek (pfp, line_beginning, SEEK_SET);
return false;
}
}
| null | 0
|
incomplete_line (void)
{
FILE *fp = pfp;
int c;
file_offset line_beginning = file_tell (fp);
if (getc (fp) == '\\')
{
while ((c = getc (fp)) != '\n' && c != EOF)
/* do nothing */ ;
return true;
}
else
{
/* We don't trust ungetc. */
Fseek (pfp, line_beginning, SEEK_SET);
return false;
}
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,140
|
maybe_reverse (char const *name, bool nonexistent, bool is_empty)
{
bool looks_reversed = (! is_empty) < p_says_nonexistent[reverse ^ is_empty];
/* Allow to create and delete empty files when we know that they are empty:
in the "diff --git" format, we know that from the index header. */
if (is_empty
&& p_says_nonexistent[reverse ^ nonexistent] == 1
&& p_says_nonexistent[! reverse ^ nonexistent] == 2)
return false;
if (looks_reversed)
reverse ^=
ok_to_reverse ("The next patch%s would %s the file %s,\nwhich %s!",
reverse ? ", when reversed," : "",
(nonexistent ? "delete"
: is_empty ? "empty out"
: "create"),
quotearg (name),
(nonexistent ? "does not exist"
: is_empty ? "is already empty"
: "already exists"));
return looks_reversed;
}
| null | 0
|
maybe_reverse (char const *name, bool nonexistent, bool is_empty)
{
bool looks_reversed = (! is_empty) < p_says_nonexistent[reverse ^ is_empty];
/* Allow to create and delete empty files when we know that they are empty:
in the "diff --git" format, we know that from the index header. */
if (is_empty
&& p_says_nonexistent[reverse ^ nonexistent] == 1
&& p_says_nonexistent[! reverse ^ nonexistent] == 2)
return false;
if (looks_reversed)
reverse ^=
ok_to_reverse ("The next patch%s would %s the file %s,\nwhich %s!",
reverse ? ", when reversed," : "",
(nonexistent ? "delete"
: is_empty ? "empty out"
: "create"),
quotearg (name),
(nonexistent ? "does not exist"
: is_empty ? "is already empty"
: "already exists"));
return looks_reversed;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,141
|
name_is_valid (char const *name)
{
int i;
bool is_valid = true;
for (i = 0; i < ARRAY_SIZE (invalid_names); i++)
{
if (! invalid_names[i])
break;
if (! strcmp (invalid_names[i], name))
return false;
}
is_valid = filename_is_safe (name);
/* Allow any filename if we are in the filesystem root. */
if (! is_valid && cwd_is_root (name))
is_valid = true;
if (! is_valid)
{
say ("Ignoring potentially dangerous file name %s\n", quotearg (name));
if (i < ARRAY_SIZE (invalid_names))
invalid_names[i] = name;
}
return is_valid;
}
| null | 0
|
name_is_valid (char const *name)
{
int i;
bool is_valid = true;
for (i = 0; i < ARRAY_SIZE (invalid_names); i++)
{
if (! invalid_names[i])
break;
if (! strcmp (invalid_names[i], name))
return false;
}
is_valid = filename_is_safe (name);
/* Allow any filename if we are in the filesystem root. */
if (! is_valid && cwd_is_root (name))
is_valid = true;
if (! is_valid)
{
say ("Ignoring potentially dangerous file name %s\n", quotearg (name));
if (i < ARRAY_SIZE (invalid_names))
invalid_names[i] = name;
}
return is_valid;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,142
|
next_intuit_at (file_offset file_pos, lin file_line)
{
p_base = file_pos;
p_bline = file_line;
}
| null | 0
|
next_intuit_at (file_offset file_pos, lin file_line)
{
p_base = file_pos;
p_bline = file_line;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,143
|
open_patch_file (char const *filename)
{
file_offset file_pos = 0;
file_offset pos;
struct stat st;
if (!filename || !*filename || strEQ (filename, "-"))
pfp = stdin;
else
{
pfp = fopen (filename, binary_transput ? "rb" : "r");
if (!pfp)
pfatal ("Can't open patch file %s", quotearg (filename));
}
#if HAVE_SETMODE_DOS
if (binary_transput)
{
if (isatty (fileno (pfp)))
fatal ("cannot read binary data from tty on this platform");
setmode (fileno (pfp), O_BINARY);
}
#endif
if (fstat (fileno (pfp), &st) != 0)
pfatal ("fstat");
if (S_ISREG (st.st_mode) && (pos = file_tell (pfp)) != -1)
file_pos = pos;
else
{
size_t charsread;
int fd;
FILE *read_pfp = pfp;
fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0);
if (fd == -1)
pfatal ("Can't create temporary file %s", TMPPATNAME);
TMPPATNAME_needs_removal = true;
pfp = fdopen (fd, "w+b");
if (! pfp)
pfatal ("Can't open stream for file %s", quotearg (TMPPATNAME));
for (st.st_size = 0;
(charsread = fread (buf, 1, bufsize, read_pfp)) != 0;
st.st_size += charsread)
if (fwrite (buf, 1, charsread, pfp) != charsread)
write_fatal ();
if (ferror (read_pfp) || fclose (read_pfp) != 0)
read_fatal ();
if (fflush (pfp) != 0
|| file_seek (pfp, (file_offset) 0, SEEK_SET) != 0)
write_fatal ();
}
p_filesize = st.st_size;
if (p_filesize != (file_offset) p_filesize)
fatal ("patch file is too long");
next_intuit_at (file_pos, 1);
}
| null | 0
|
open_patch_file (char const *filename)
{
file_offset file_pos = 0;
file_offset pos;
struct stat st;
if (!filename || !*filename || strEQ (filename, "-"))
pfp = stdin;
else
{
pfp = fopen (filename, binary_transput ? "rb" : "r");
if (!pfp)
pfatal ("Can't open patch file %s", quotearg (filename));
}
#if HAVE_SETMODE_DOS
if (binary_transput)
{
if (isatty (fileno (pfp)))
fatal ("cannot read binary data from tty on this platform");
setmode (fileno (pfp), O_BINARY);
}
#endif
if (fstat (fileno (pfp), &st) != 0)
pfatal ("fstat");
if (S_ISREG (st.st_mode) && (pos = file_tell (pfp)) != -1)
file_pos = pos;
else
{
size_t charsread;
int fd;
FILE *read_pfp = pfp;
fd = make_tempfile (&TMPPATNAME, 'p', NULL, O_RDWR | O_BINARY, 0);
if (fd == -1)
pfatal ("Can't create temporary file %s", TMPPATNAME);
TMPPATNAME_needs_removal = true;
pfp = fdopen (fd, "w+b");
if (! pfp)
pfatal ("Can't open stream for file %s", quotearg (TMPPATNAME));
for (st.st_size = 0;
(charsread = fread (buf, 1, bufsize, read_pfp)) != 0;
st.st_size += charsread)
if (fwrite (buf, 1, charsread, pfp) != charsread)
write_fatal ();
if (ferror (read_pfp) || fclose (read_pfp) != 0)
read_fatal ();
if (fflush (pfp) != 0
|| file_seek (pfp, (file_offset) 0, SEEK_SET) != 0)
write_fatal ();
}
p_filesize = st.st_size;
if (p_filesize != (file_offset) p_filesize)
fatal ("patch file is too long");
next_intuit_at (file_pos, 1);
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,144
|
pch_c_function (void)
{
return p_c_function;
}
| null | 0
|
pch_c_function (void)
{
return p_c_function;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,145
|
bool pch_copy (void)
{
return p_copy[OLD] && p_copy[NEW];
}
| null | 0
|
bool pch_copy (void)
{
return p_copy[OLD] && p_copy[NEW];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,146
|
pch_end (void)
{
return p_end;
}
| null | 0
|
pch_end (void)
{
return p_end;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,147
|
pch_first (void)
{
return p_first;
}
| null | 0
|
pch_first (void)
{
return p_first;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,148
|
pch_git_diff (void)
{
return p_git_diff;
}
| null | 0
|
pch_git_diff (void)
{
return p_git_diff;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,149
|
pch_line_len (lin line)
{
return p_len[line];
}
| null | 0
|
pch_line_len (lin line)
{
return p_len[line];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,150
|
pch_mode (bool which)
{
return p_mode[which];
}
| null | 0
|
pch_mode (bool which)
{
return p_mode[which];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,151
|
pch_name (enum nametype type)
{
return type == NONE ? NULL : p_name[type];
}
| null | 0
|
pch_name (enum nametype type)
{
return type == NONE ? NULL : p_name[type];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,152
|
pch_newfirst (void)
{
return p_newfirst;
}
| null | 0
|
pch_newfirst (void)
{
return p_newfirst;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,153
|
pch_prefix_context (void)
{
return p_prefix_context;
}
| null | 0
|
pch_prefix_context (void)
{
return p_prefix_context;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,154
|
pch_ptrn_lines (void)
{
return p_ptrn_lines;
}
| null | 0
|
pch_ptrn_lines (void)
{
return p_ptrn_lines;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,155
|
bool pch_rename (void)
{
return p_rename[OLD] && p_rename[NEW];
}
| null | 0
|
bool pch_rename (void)
{
return p_rename[OLD] && p_rename[NEW];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,156
|
pch_repl_lines (void)
{
return p_repl_lines;
}
| null | 0
|
pch_repl_lines (void)
{
return p_repl_lines;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,157
|
pch_says_nonexistent (bool which)
{
return p_says_nonexistent[which];
}
| null | 0
|
pch_says_nonexistent (bool which)
{
return p_says_nonexistent[which];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,158
|
pch_suffix_context (void)
{
return p_suffix_context;
}
| null | 0
|
pch_suffix_context (void)
{
return p_suffix_context;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,159
|
pch_swap (void)
{
char **tp_line; /* the text of the hunk */
size_t *tp_len; /* length of each line */
char *tp_char; /* +, -, and ! */
lin i;
lin n;
bool blankline = false;
char *s;
i = p_first;
p_first = p_newfirst;
p_newfirst = i;
/* make a scratch copy */
tp_line = p_line;
tp_len = p_len;
tp_char = p_Char;
p_line = 0; /* force set_hunkmax to allocate again */
p_len = 0;
p_Char = 0;
set_hunkmax();
if (!p_line || !p_len || !p_Char) {
free (p_line);
p_line = tp_line;
free (p_len);
p_len = tp_len;
free (p_Char);
p_Char = tp_char;
return false; /* not enough memory to swap hunk! */
}
/* now turn the new into the old */
i = p_ptrn_lines + 1;
if (tp_char[i] == '\n') { /* account for possible blank line */
blankline = true;
i++;
}
if (p_efake >= 0) { /* fix non-freeable ptr range */
if (p_efake <= i)
n = p_end - i + 1;
else
n = -i;
p_efake += n;
p_bfake += n;
}
for (n=0; i <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '+')
p_Char[n] = '-';
p_len[n] = tp_len[i];
}
if (blankline) {
i = p_ptrn_lines + 1;
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
p_len[n] = tp_len[i];
n++;
}
assert(p_Char[0] == '=');
p_Char[0] = '*';
for (s=p_line[0]; *s; s++)
if (*s == '-')
*s = '*';
/* now turn the old into the new */
assert(tp_char[0] == '*');
tp_char[0] = '=';
for (s=tp_line[0]; *s; s++)
if (*s == '*')
*s = '-';
for (i=0; n <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '-')
p_Char[n] = '+';
p_len[n] = tp_len[i];
}
assert(i == p_ptrn_lines + 1);
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
p_Char[p_end + 1] = '^';
free (tp_line);
free (tp_len);
free (tp_char);
return true;
}
| null | 0
|
pch_swap (void)
{
char **tp_line; /* the text of the hunk */
size_t *tp_len; /* length of each line */
char *tp_char; /* +, -, and ! */
lin i;
lin n;
bool blankline = false;
char *s;
i = p_first;
p_first = p_newfirst;
p_newfirst = i;
/* make a scratch copy */
tp_line = p_line;
tp_len = p_len;
tp_char = p_Char;
p_line = 0; /* force set_hunkmax to allocate again */
p_len = 0;
p_Char = 0;
set_hunkmax();
if (!p_line || !p_len || !p_Char) {
free (p_line);
p_line = tp_line;
free (p_len);
p_len = tp_len;
free (p_Char);
p_Char = tp_char;
return false; /* not enough memory to swap hunk! */
}
/* now turn the new into the old */
i = p_ptrn_lines + 1;
if (tp_char[i] == '\n') { /* account for possible blank line */
blankline = true;
i++;
}
if (p_efake >= 0) { /* fix non-freeable ptr range */
if (p_efake <= i)
n = p_end - i + 1;
else
n = -i;
p_efake += n;
p_bfake += n;
}
for (n=0; i <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '+')
p_Char[n] = '-';
p_len[n] = tp_len[i];
}
if (blankline) {
i = p_ptrn_lines + 1;
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
p_len[n] = tp_len[i];
n++;
}
assert(p_Char[0] == '=');
p_Char[0] = '*';
for (s=p_line[0]; *s; s++)
if (*s == '-')
*s = '*';
/* now turn the old into the new */
assert(tp_char[0] == '*');
tp_char[0] = '=';
for (s=tp_line[0]; *s; s++)
if (*s == '*')
*s = '-';
for (i=0; n <= p_end; i++,n++) {
p_line[n] = tp_line[i];
p_Char[n] = tp_char[i];
if (p_Char[n] == '-')
p_Char[n] = '+';
p_len[n] = tp_len[i];
}
assert(i == p_ptrn_lines + 1);
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
p_Char[p_end + 1] = '^';
free (tp_line);
free (tp_len);
free (tp_char);
return true;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,160
|
pch_timestr (bool which)
{
return p_timestr[which];
}
| null | 0
|
pch_timestr (bool which)
{
return p_timestr[which];
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,161
|
pch_write_line (lin line, FILE *file)
{
bool after_newline = (p_len[line] > 0) && (p_line[line][p_len[line] - 1] == '\n');
if (! fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file))
write_fatal ();
return after_newline;
}
| null | 0
|
pch_write_line (lin line, FILE *file)
{
bool after_newline = (p_len[line] > 0) && (p_line[line][p_len[line] - 1] == '\n');
if (! fwrite (p_line[line], sizeof (*p_line[line]), p_len[line], file))
write_fatal ();
return after_newline;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,162
|
pget_line (size_t indent, int rfc934_nesting, bool strip_trailing_cr,
bool pass_comments_through)
{
FILE *fp = pfp;
int c;
size_t i;
char *b;
size_t s;
do
{
i = 0;
for (;;)
{
c = getc (fp);
if (c == EOF)
{
if (ferror (fp))
read_fatal ();
return 0;
}
if (indent <= i)
break;
if (c == ' ' || c == 'X')
i++;
else if (c == '\t')
i = (i + 8) & ~7;
else
break;
}
i = 0;
b = buf;
while (c == '-' && 0 <= --rfc934_nesting)
{
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
if (c != ' ')
{
i = 1;
b[0] = '-';
break;
}
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
}
s = bufsize;
for (;;)
{
if (i == s - 1)
{
s *= 2;
b = realloc (b, s);
if (!b)
{
if (!using_plan_a)
xalloc_die ();
return (size_t) -1;
}
buf = b;
bufsize = s;
}
b[i++] = c;
if (c == '\n')
break;
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
}
p_input_line++;
}
while (*b == '#' && !pass_comments_through);
if (strip_trailing_cr && 2 <= i && b[i - 2] == '\r')
b[i-- - 2] = '\n';
b[i] = '\0';
return i;
patch_ends_in_middle_of_line:
if (ferror (fp))
read_fatal ();
say ("patch unexpectedly ends in middle of line\n");
return 0;
}
| null | 0
|
pget_line (size_t indent, int rfc934_nesting, bool strip_trailing_cr,
bool pass_comments_through)
{
FILE *fp = pfp;
int c;
size_t i;
char *b;
size_t s;
do
{
i = 0;
for (;;)
{
c = getc (fp);
if (c == EOF)
{
if (ferror (fp))
read_fatal ();
return 0;
}
if (indent <= i)
break;
if (c == ' ' || c == 'X')
i++;
else if (c == '\t')
i = (i + 8) & ~7;
else
break;
}
i = 0;
b = buf;
while (c == '-' && 0 <= --rfc934_nesting)
{
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
if (c != ' ')
{
i = 1;
b[0] = '-';
break;
}
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
}
s = bufsize;
for (;;)
{
if (i == s - 1)
{
s *= 2;
b = realloc (b, s);
if (!b)
{
if (!using_plan_a)
xalloc_die ();
return (size_t) -1;
}
buf = b;
bufsize = s;
}
b[i++] = c;
if (c == '\n')
break;
c = getc (fp);
if (c == EOF)
goto patch_ends_in_middle_of_line;
}
p_input_line++;
}
while (*b == '#' && !pass_comments_through);
if (strip_trailing_cr && 2 <= i && b[i - 2] == '\r')
b[i-- - 2] = '\n';
b[i] = '\0';
return i;
patch_ends_in_middle_of_line:
if (ferror (fp))
read_fatal ();
say ("patch unexpectedly ends in middle of line\n");
return 0;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,163
|
prefix_components (char *filename, bool checkdirs)
{
int count = 0;
struct stat stat_buf;
int stat_result;
char *f = filename + FILE_SYSTEM_PREFIX_LEN (filename);
if (*f)
while (*++f)
if (ISSLASH (f[0]) && ! ISSLASH (f[-1]))
{
if (checkdirs)
{
*f = '\0';
stat_result = safe_stat (filename, &stat_buf);
*f = '/';
if (! (stat_result == 0 && S_ISDIR (stat_buf.st_mode)))
break;
}
count++;
}
return count;
}
| null | 0
|
prefix_components (char *filename, bool checkdirs)
{
int count = 0;
struct stat stat_buf;
int stat_result;
char *f = filename + FILE_SYSTEM_PREFIX_LEN (filename);
if (*f)
while (*++f)
if (ISSLASH (f[0]) && ! ISSLASH (f[-1]))
{
if (checkdirs)
{
*f = '\0';
stat_result = safe_stat (filename, &stat_buf);
*f = '/';
if (! (stat_result == 0 && S_ISDIR (stat_buf.st_mode)))
break;
}
count++;
}
return count;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,164
|
set_hunkmax (void)
{
if (!p_line)
p_line = xmalloc (hunkmax * sizeof *p_line);
if (!p_len)
p_len = xmalloc (hunkmax * sizeof *p_len);
if (!p_Char)
p_Char = xmalloc (hunkmax * sizeof *p_Char);
}
| null | 0
|
set_hunkmax (void)
{
if (!p_line)
p_line = xmalloc (hunkmax * sizeof *p_line);
if (!p_len)
p_len = xmalloc (hunkmax * sizeof *p_len);
if (!p_Char)
p_Char = xmalloc (hunkmax * sizeof *p_Char);
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,165
|
sha1_says_nonexistent(char const *sha1)
{
char const *empty_sha1 = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
char const *s;
/* Nonexisting files have an all-zero checksum. */
for (s = sha1; *s; s++)
if (*s != '0')
break;
if (! *s)
return 2;
/* Empty files have empty_sha1 as their checksum. */
for (s = sha1; *s; s++, empty_sha1++)
if (*s != *empty_sha1)
break;
return ! *s;
}
| null | 0
|
sha1_says_nonexistent(char const *sha1)
{
char const *empty_sha1 = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
char const *s;
/* Nonexisting files have an all-zero checksum. */
for (s = sha1; *s; s++)
if (*s != '0')
break;
if (! *s)
return 2;
/* Empty files have empty_sha1 as their checksum. */
for (s = sha1; *s; s++, empty_sha1++)
if (*s != *empty_sha1)
break;
return ! *s;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,166
|
skip_to (file_offset file_pos, lin file_line)
{
FILE *i = pfp;
FILE *o = stdout;
int c;
assert(p_base <= file_pos);
if ((verbosity == VERBOSE || !inname) && p_base < file_pos) {
Fseek (i, p_base, SEEK_SET);
say ("The text leading up to this was:\n--------------------------\n");
while (file_tell (i) < file_pos)
{
putc ('|', o);
do
{
if ((c = getc (i)) == EOF)
read_fatal ();
putc (c, o);
}
while (c != '\n');
}
say ("--------------------------\n");
}
else
Fseek (i, file_pos, SEEK_SET);
p_input_line = file_line - 1;
}
| null | 0
|
skip_to (file_offset file_pos, lin file_line)
{
FILE *i = pfp;
FILE *o = stdout;
int c;
assert(p_base <= file_pos);
if ((verbosity == VERBOSE || !inname) && p_base < file_pos) {
Fseek (i, p_base, SEEK_SET);
say ("The text leading up to this was:\n--------------------------\n");
while (file_tell (i) < file_pos)
{
putc ('|', o);
do
{
if ((c = getc (i)) == EOF)
read_fatal ();
putc (c, o);
}
while (c != '\n');
}
say ("--------------------------\n");
}
else
Fseek (i, file_pos, SEEK_SET);
p_input_line = file_line - 1;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,167
|
there_is_another_patch (bool need_header, mode_t *file_type)
{
if (p_base != 0 && p_base >= p_filesize) {
if (verbosity == VERBOSE)
say ("done\n");
return false;
}
if (verbosity == VERBOSE)
say ("Hmm...");
diff_type = intuit_diff_type (need_header, file_type);
if (diff_type == NO_DIFF) {
if (verbosity == VERBOSE)
say (p_base
? " Ignoring the trailing garbage.\ndone\n"
: " I can't seem to find a patch in there anywhere.\n");
if (! p_base && p_filesize)
fatal ("Only garbage was found in the patch input.");
return false;
}
if (skip_rest_of_patch)
{
Fseek (pfp, p_start, SEEK_SET);
p_input_line = p_sline - 1;
return true;
}
if (verbosity == VERBOSE)
say (" %sooks like %s to me...\n",
(p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
diff_type == NORMAL_DIFF ? "a normal diff" :
diff_type == GIT_BINARY_DIFF ? "a git binary diff" :
"an ed script" );
if (no_strip_trailing_cr)
p_strip_trailing_cr = false;
if (verbosity != SILENT)
{
if (p_indent)
say ("(Patch is indented %lu space%s.)\n",
(unsigned long int) p_indent, p_indent==1?"":"s");
if (p_strip_trailing_cr)
say ("(Stripping trailing CRs from patch; use --binary to disable.)\n");
if (! inname)
{
char numbuf[LINENUM_LENGTH_BOUND + 1];
say ("can't find file to patch at input line %s\n",
format_linenum (numbuf, p_sline));
if (diff_type != ED_DIFF && diff_type != NORMAL_DIFF)
say (strippath == -1
? "Perhaps you should have used the -p or --strip option?\n"
: "Perhaps you used the wrong -p or --strip option?\n");
}
}
skip_to(p_start,p_sline);
while (!inname) {
char *t;
if (force | batch) {
say ("No file to patch. Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
ask ("File to patch: ");
t = buf + strlen (buf);
if (t > buf + 1 && *(t - 1) == '\n')
{
inname = xmemdup0 (buf, t - buf - 1);
inerrno = stat_file (inname, &instat);
if (inerrno)
{
perror (inname);
fflush (stderr);
free (inname);
inname = 0;
}
else
invc = -1;
}
if (!inname) {
ask ("Skip this patch? [y] ");
if (*buf != 'n') {
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
}
}
return true;
}
| null | 0
|
there_is_another_patch (bool need_header, mode_t *file_type)
{
if (p_base != 0 && p_base >= p_filesize) {
if (verbosity == VERBOSE)
say ("done\n");
return false;
}
if (verbosity == VERBOSE)
say ("Hmm...");
diff_type = intuit_diff_type (need_header, file_type);
if (diff_type == NO_DIFF) {
if (verbosity == VERBOSE)
say (p_base
? " Ignoring the trailing garbage.\ndone\n"
: " I can't seem to find a patch in there anywhere.\n");
if (! p_base && p_filesize)
fatal ("Only garbage was found in the patch input.");
return false;
}
if (skip_rest_of_patch)
{
Fseek (pfp, p_start, SEEK_SET);
p_input_line = p_sline - 1;
return true;
}
if (verbosity == VERBOSE)
say (" %sooks like %s to me...\n",
(p_base == 0 ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
diff_type == NEW_CONTEXT_DIFF ? "a new-style context diff" :
diff_type == NORMAL_DIFF ? "a normal diff" :
diff_type == GIT_BINARY_DIFF ? "a git binary diff" :
"an ed script" );
if (no_strip_trailing_cr)
p_strip_trailing_cr = false;
if (verbosity != SILENT)
{
if (p_indent)
say ("(Patch is indented %lu space%s.)\n",
(unsigned long int) p_indent, p_indent==1?"":"s");
if (p_strip_trailing_cr)
say ("(Stripping trailing CRs from patch; use --binary to disable.)\n");
if (! inname)
{
char numbuf[LINENUM_LENGTH_BOUND + 1];
say ("can't find file to patch at input line %s\n",
format_linenum (numbuf, p_sline));
if (diff_type != ED_DIFF && diff_type != NORMAL_DIFF)
say (strippath == -1
? "Perhaps you should have used the -p or --strip option?\n"
: "Perhaps you used the wrong -p or --strip option?\n");
}
}
skip_to(p_start,p_sline);
while (!inname) {
char *t;
if (force | batch) {
say ("No file to patch. Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
ask ("File to patch: ");
t = buf + strlen (buf);
if (t > buf + 1 && *(t - 1) == '\n')
{
inname = xmemdup0 (buf, t - buf - 1);
inerrno = stat_file (inname, &instat);
if (inerrno)
{
perror (inname);
fflush (stderr);
free (inname);
inname = 0;
}
else
invc = -1;
}
if (!inname) {
ask ("Skip this patch? [y] ");
if (*buf != 'n') {
if (verbosity != SILENT)
say ("Skipping patch.\n");
skip_rest_of_patch = true;
return true;
}
}
}
return true;
}
|
@@ -2459,9 +2459,6 @@ do_ed_script (char const *inname, char const *outname,
*outname_needs_removal = true;
copy_file (inname, outname, 0, exclusive, instat.st_mode, true);
}
- sprintf (buf, "%s %s%s", editor_program,
- verbosity == VERBOSE ? "" : "- ",
- outname);
fflush (stdout);
pid = fork();
@@ -2470,7 +2467,8 @@ do_ed_script (char const *inname, char const *outname,
else if (pid == 0)
{
dup2 (tmpfd, 0);
- execl ("/bin/sh", "sh", "-c", buf, (char *) 0);
+ assert (outname[0] != '!' && outname[0] != '-');
+ execlp (editor_program, editor_program, "-", outname, (char *) NULL);
_exit (2);
}
else
|
CWE-78
| null | null |
2,168
|
get_input_file (char const *filename, char const *outname, mode_t file_type)
{
bool elsewhere = strcmp (filename, outname) != 0;
char const *cs;
char *diffbuf;
char *getbuf;
if (inerrno == -1)
inerrno = stat_file (filename, &instat);
/* Perhaps look for RCS or SCCS versions. */
if (S_ISREG (file_type)
&& patch_get
&& invc != 0
&& (inerrno
|| (! elsewhere
&& (/* No one can write to it. */
(instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0
/* Only the owner (who's not me) can write to it. */
|| ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0
&& instat.st_uid != geteuid ()))))
&& (invc = !! (cs = (version_controller
(filename, elsewhere,
inerrno ? (struct stat *) 0 : &instat,
&getbuf, &diffbuf))))) {
if (!inerrno) {
if (!elsewhere
&& (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0)
/* Somebody can write to it. */
fatal ("File %s seems to be locked by somebody else under %s",
quotearg (filename), cs);
if (diffbuf)
{
/* It might be checked out unlocked. See if it's safe to
check out the default version locked. */
if (verbosity == VERBOSE)
say ("Comparing file %s to default %s version...\n",
quotearg (filename), cs);
if (systemic (diffbuf) != 0)
{
say ("warning: Patching file %s, which does not match default %s version\n",
quotearg (filename), cs);
cs = 0;
}
}
if (dry_run)
cs = 0;
}
if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf,
&instat))
inerrno = 0;
free (getbuf);
free (diffbuf);
}
if (inerrno)
{
instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
instat.st_size = 0;
}
else if (! ((S_ISREG (file_type) || S_ISLNK (file_type))
&& (file_type & S_IFMT) == (instat.st_mode & S_IFMT)))
{
say ("File %s is not a %s -- refusing to patch\n",
quotearg (filename),
S_ISLNK (file_type) ? "symbolic link" : "regular file");
return false;
}
return true;
}
| null | 0
|
get_input_file (char const *filename, char const *outname, mode_t file_type)
{
bool elsewhere = strcmp (filename, outname) != 0;
char const *cs;
char *diffbuf;
char *getbuf;
if (inerrno == -1)
inerrno = stat_file (filename, &instat);
/* Perhaps look for RCS or SCCS versions. */
if (S_ISREG (file_type)
&& patch_get
&& invc != 0
&& (inerrno
|| (! elsewhere
&& (/* No one can write to it. */
(instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0
/* Only the owner (who's not me) can write to it. */
|| ((instat.st_mode & (S_IWGRP|S_IWOTH)) == 0
&& instat.st_uid != geteuid ()))))
&& (invc = !! (cs = (version_controller
(filename, elsewhere,
inerrno ? (struct stat *) 0 : &instat,
&getbuf, &diffbuf))))) {
if (!inerrno) {
if (!elsewhere
&& (instat.st_mode & (S_IWUSR|S_IWGRP|S_IWOTH)) != 0)
/* Somebody can write to it. */
fatal ("File %s seems to be locked by somebody else under %s",
quotearg (filename), cs);
if (diffbuf)
{
/* It might be checked out unlocked. See if it's safe to
check out the default version locked. */
if (verbosity == VERBOSE)
say ("Comparing file %s to default %s version...\n",
quotearg (filename), cs);
if (systemic (diffbuf) != 0)
{
say ("warning: Patching file %s, which does not match default %s version\n",
quotearg (filename), cs);
cs = 0;
}
}
if (dry_run)
cs = 0;
}
if (cs && version_get (filename, cs, ! inerrno, elsewhere, getbuf,
&instat))
inerrno = 0;
free (getbuf);
free (diffbuf);
}
if (inerrno)
{
instat.st_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
instat.st_size = 0;
}
else if (! ((S_ISREG (file_type) || S_ISLNK (file_type))
&& (file_type & S_IFMT) == (instat.st_mode & S_IFMT)))
{
say ("File %s is not a %s -- refusing to patch\n",
quotearg (filename),
S_ISLNK (file_type) ? "symbolic link" : "regular file");
return false;
}
return true;
}
|
@@ -238,8 +238,13 @@ plan_a (char const *filename)
{
if (S_ISREG (instat.st_mode))
{
- int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
+ int flags = O_RDONLY | binary_transput;
size_t buffered = 0, n;
+ int ifd;
+
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ ifd = safe_open (filename, flags, 0);
if (ifd < 0)
pfatal ("can't open file %s", quotearg (filename));
@@ -340,6 +345,7 @@ plan_a (char const *filename)
static void
plan_b (char const *filename)
{
+ int flags = O_RDONLY | binary_transput;
int ifd;
FILE *ifp;
int c;
@@ -353,7 +359,9 @@ plan_b (char const *filename)
if (instat.st_size == 0)
filename = NULL_DEVICE;
- if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ if ((ifd = safe_open (filename, flags, 0)) < 0
|| ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
pfatal ("Can't open file %s", quotearg (filename));
if (TMPINNAME_needs_removal)
|
CWE-59
| null | null |
2,169
|
lines_too_long (char const *filename)
{
fatal ("Lines in file %s are too long", quotearg (filename));
}
| null | 0
|
lines_too_long (char const *filename)
{
fatal ("Lines in file %s are too long", quotearg (filename));
}
|
@@ -238,8 +238,13 @@ plan_a (char const *filename)
{
if (S_ISREG (instat.st_mode))
{
- int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
+ int flags = O_RDONLY | binary_transput;
size_t buffered = 0, n;
+ int ifd;
+
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ ifd = safe_open (filename, flags, 0);
if (ifd < 0)
pfatal ("can't open file %s", quotearg (filename));
@@ -340,6 +345,7 @@ plan_a (char const *filename)
static void
plan_b (char const *filename)
{
+ int flags = O_RDONLY | binary_transput;
int ifd;
FILE *ifp;
int c;
@@ -353,7 +359,9 @@ plan_b (char const *filename)
if (instat.st_size == 0)
filename = NULL_DEVICE;
- if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ if ((ifd = safe_open (filename, flags, 0)) < 0
|| ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
pfatal ("Can't open file %s", quotearg (filename));
if (TMPINNAME_needs_removal)
|
CWE-59
| null | null |
2,170
|
re_input (void)
{
if (using_plan_a) {
if (i_buffer)
{
free (i_buffer);
i_buffer = 0;
free (i_ptr);
}
}
else {
if (tifd >= 0)
close (tifd);
tifd = -1;
if (tibuf[0])
{
free (tibuf[0]);
tibuf[0] = 0;
}
tiline[0] = tiline[1] = -1;
tireclen = 0;
}
}
| null | 0
|
re_input (void)
{
if (using_plan_a) {
if (i_buffer)
{
free (i_buffer);
i_buffer = 0;
free (i_ptr);
}
}
else {
if (tifd >= 0)
close (tifd);
tifd = -1;
if (tibuf[0])
{
free (tibuf[0]);
tibuf[0] = 0;
}
tiline[0] = tiline[1] = -1;
tireclen = 0;
}
}
|
@@ -238,8 +238,13 @@ plan_a (char const *filename)
{
if (S_ISREG (instat.st_mode))
{
- int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
+ int flags = O_RDONLY | binary_transput;
size_t buffered = 0, n;
+ int ifd;
+
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ ifd = safe_open (filename, flags, 0);
if (ifd < 0)
pfatal ("can't open file %s", quotearg (filename));
@@ -340,6 +345,7 @@ plan_a (char const *filename)
static void
plan_b (char const *filename)
{
+ int flags = O_RDONLY | binary_transput;
int ifd;
FILE *ifp;
int c;
@@ -353,7 +359,9 @@ plan_b (char const *filename)
if (instat.st_size == 0)
filename = NULL_DEVICE;
- if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ if ((ifd = safe_open (filename, flags, 0)) < 0
|| ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
pfatal ("Can't open file %s", quotearg (filename));
if (TMPINNAME_needs_removal)
|
CWE-59
| null | null |
2,171
|
report_revision (bool found_revision)
{
char const *rev = quotearg (revision);
if (found_revision)
{
if (verbosity == VERBOSE)
say ("Good. This file appears to be the %s version.\n", rev);
}
else if (force)
{
if (verbosity != SILENT)
say ("Warning: this file doesn't appear to be the %s version -- patching anyway.\n",
rev);
}
else if (batch)
fatal ("This file doesn't appear to be the %s version -- aborting.",
rev);
else
{
ask ("This file doesn't appear to be the %s version -- patch anyway? [n] ",
rev);
if (*buf != 'y')
fatal ("aborted");
}
}
| null | 0
|
report_revision (bool found_revision)
{
char const *rev = quotearg (revision);
if (found_revision)
{
if (verbosity == VERBOSE)
say ("Good. This file appears to be the %s version.\n", rev);
}
else if (force)
{
if (verbosity != SILENT)
say ("Warning: this file doesn't appear to be the %s version -- patching anyway.\n",
rev);
}
else if (batch)
fatal ("This file doesn't appear to be the %s version -- aborting.",
rev);
else
{
ask ("This file doesn't appear to be the %s version -- patch anyway? [n] ",
rev);
if (*buf != 'y')
fatal ("aborted");
}
}
|
@@ -238,8 +238,13 @@ plan_a (char const *filename)
{
if (S_ISREG (instat.st_mode))
{
- int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
+ int flags = O_RDONLY | binary_transput;
size_t buffered = 0, n;
+ int ifd;
+
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ ifd = safe_open (filename, flags, 0);
if (ifd < 0)
pfatal ("can't open file %s", quotearg (filename));
@@ -340,6 +345,7 @@ plan_a (char const *filename)
static void
plan_b (char const *filename)
{
+ int flags = O_RDONLY | binary_transput;
int ifd;
FILE *ifp;
int c;
@@ -353,7 +359,9 @@ plan_b (char const *filename)
if (instat.st_size == 0)
filename = NULL_DEVICE;
- if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ if ((ifd = safe_open (filename, flags, 0)) < 0
|| ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
pfatal ("Can't open file %s", quotearg (filename));
if (TMPINNAME_needs_removal)
|
CWE-59
| null | null |
2,172
|
too_many_lines (char const *filename)
{
fatal ("File %s has too many lines", quotearg (filename));
}
| null | 0
|
too_many_lines (char const *filename)
{
fatal ("File %s has too many lines", quotearg (filename));
}
|
@@ -238,8 +238,13 @@ plan_a (char const *filename)
{
if (S_ISREG (instat.st_mode))
{
- int ifd = safe_open (filename, O_RDONLY|binary_transput, 0);
+ int flags = O_RDONLY | binary_transput;
size_t buffered = 0, n;
+ int ifd;
+
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ ifd = safe_open (filename, flags, 0);
if (ifd < 0)
pfatal ("can't open file %s", quotearg (filename));
@@ -340,6 +345,7 @@ plan_a (char const *filename)
static void
plan_b (char const *filename)
{
+ int flags = O_RDONLY | binary_transput;
int ifd;
FILE *ifp;
int c;
@@ -353,7 +359,9 @@ plan_b (char const *filename)
if (instat.st_size == 0)
filename = NULL_DEVICE;
- if ((ifd = safe_open (filename, O_RDONLY | binary_transput, 0)) < 0
+ if (! follow_symlinks)
+ flags |= O_NOFOLLOW;
+ if ((ifd = safe_open (filename, flags, 0)) < 0
|| ! (ifp = fdopen (ifd, binary_transput ? "rb" : "r")))
pfatal ("Can't open file %s", quotearg (filename));
if (TMPINNAME_needs_removal)
|
CWE-59
| null | null |
2,173
|
Fseek (FILE *stream, file_offset offset, int ptrname)
{
if (file_seek (stream, offset, ptrname) != 0)
pfatal ("fseek");
}
| null | 0
|
Fseek (FILE *stream, file_offset offset, int ptrname)
{
if (file_seek (stream, offset, ptrname) != 0)
pfatal ("fseek");
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,174
|
__insert_file_id (struct stat const *st, enum file_id_type type)
{
file_id *p;
static file_id *next_slot;
if (!next_slot)
next_slot = xmalloc (sizeof *next_slot);
next_slot->dev = st->st_dev;
next_slot->ino = st->st_ino;
next_slot->queued_output = false;
p = hash_insert (file_id_table, next_slot);
if (!p)
xalloc_die ();
if (p == next_slot)
next_slot = NULL;
p->type = type;
return p;
}
| null | 0
|
__insert_file_id (struct stat const *st, enum file_id_type type)
{
file_id *p;
static file_id *next_slot;
if (!next_slot)
next_slot = xmalloc (sizeof *next_slot);
next_slot->dev = st->st_dev;
next_slot->ino = st->st_ino;
next_slot->queued_output = false;
p = hash_insert (file_id_table, next_slot);
if (!p)
xalloc_die ();
if (p == next_slot)
next_slot = NULL;
p->type = type;
return p;
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,175
|
contains_slash (const char *s)
{
for (; *s; s++)
if (ISSLASH(*s))
return true;
return false;
}
| null | 0
|
contains_slash (const char *s)
{
for (; *s; s++)
if (ISSLASH(*s))
return true;
return false;
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,176
|
copy_attr (char const *src_path, char const *dst_path)
{
struct error_context ctx =
{
.error = copy_attr_error,
.quote = copy_attr_quote,
.quote_free = copy_attr_free
};
/* FIXME: We are copying between files we know we can safely access by
* pathname. A safe_ version of attr_copy_file() might still be slightly
* more efficient for deep paths. */
return attr_copy_file (src_path, dst_path, copy_attr_check, &ctx);
}
| null | 0
|
copy_attr (char const *src_path, char const *dst_path)
{
struct error_context ctx =
{
.error = copy_attr_error,
.quote = copy_attr_quote,
.quote_free = copy_attr_free
};
/* FIXME: We are copying between files we know we can safely access by
* pathname. A safe_ version of attr_copy_file() might still be slightly
* more efficient for deep paths. */
return attr_copy_file (src_path, dst_path, copy_attr_check, &ctx);
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,177
|
copy_attr (char const *src_path, char const *dst_path)
{
return 0;
}
| null | 0
|
copy_attr (char const *src_path, char const *dst_path)
{
return 0;
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,178
|
copy_attr_check (const char *name, struct error_context *ctx)
{
int action = attr_copy_action (name, ctx);
return action == 0 || action == ATTR_ACTION_PERMISSIONS;
}
| null | 0
|
copy_attr_check (const char *name, struct error_context *ctx)
{
int action = attr_copy_action (name, ctx);
return action == 0 || action == ATTR_ACTION_PERMISSIONS;
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,179
|
copy_attr_error (struct error_context *ctx, char const *fmt, ...)
{
int err = errno;
va_list ap;
if (err != ENOSYS && err != ENOTSUP && err != EPERM)
{
/* use verror module to print error message */
va_start (ap, fmt);
verror (0, err, fmt, ap);
va_end (ap);
}
}
| null | 0
|
copy_attr_error (struct error_context *ctx, char const *fmt, ...)
{
int err = errno;
va_list ap;
if (err != ENOSYS && err != ENOTSUP && err != EPERM)
{
/* use verror module to print error message */
va_start (ap, fmt);
verror (0, err, fmt, ap);
va_end (ap);
}
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,180
|
copy_attr_free (struct error_context *ctx, char const *str)
{
}
| null | 0
|
copy_attr_free (struct error_context *ctx, char const *str)
{
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,181
|
copy_attr_quote (struct error_context *ctx, char const *str)
{
return quotearg (str);
}
| null | 0
|
copy_attr_quote (struct error_context *ctx, char const *str)
{
return quotearg (str);
}
|
@@ -388,7 +388,7 @@ create_backup (char const *to, const struct stat *to_st, bool leave_original)
try_makedirs_errno = ENOENT;
safe_unlink (bakname);
- while ((fd = safe_open (bakname, O_CREAT | O_WRONLY | O_TRUNC, 0666)) < 0)
+ while ((fd = safe_open (bakname, O_CREAT | O_EXCL | O_WRONLY | O_TRUNC, 0666)) < 0)
{
if (errno != try_makedirs_errno)
pfatal ("Can't create file %s", quotearg (bakname));
@@ -579,10 +579,13 @@ create_file (char const *file, int open_flags, mode_t mode,
static void
copy_to_fd (const char *from, int tofd)
{
+ int from_flags = O_RDONLY | O_BINARY;
int fromfd;
ssize_t i;
- if ((fromfd = safe_open (from, O_RDONLY | O_BINARY, 0)) < 0)
+ if (! follow_symlinks)
+ from_flags |= O_NOFOLLOW;
+ if ((fromfd = safe_open (from, from_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (from));
while ((i = read (fromfd, buf, bufsize)) != 0)
{
@@ -625,6 +628,8 @@ copy_file (char const *from, char const *to, struct stat *tost,
else
{
assert (S_ISREG (mode));
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
tofd = create_file (to, O_WRONLY | O_BINARY | to_flags, mode,
to_dir_known_to_exist);
copy_to_fd (from, tofd);
@@ -640,9 +645,12 @@ copy_file (char const *from, char const *to, struct stat *tost,
void
append_to_file (char const *from, char const *to)
{
+ int to_flags = O_WRONLY | O_APPEND | O_BINARY;
int tofd;
- if ((tofd = safe_open (to, O_WRONLY | O_BINARY | O_APPEND, 0)) < 0)
+ if (! follow_symlinks)
+ to_flags |= O_NOFOLLOW;
+ if ((tofd = safe_open (to, to_flags, 0)) < 0)
pfatal ("Can't reopen file %s", quotearg (to));
copy_to_fd (from, tofd);
if (close (tofd) != 0)
|
CWE-59
| null | null |
2,182
|
_dbus_header_cache_check (DBusHeader *header,
int field)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_UNKNOWN)
_dbus_header_cache_revalidate (header);
if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT)
return FALSE;
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_header_cache_check (DBusHeader *header,
int field)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_UNKNOWN)
_dbus_header_cache_revalidate (header);
if (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT)
return FALSE;
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,183
|
_dbus_header_cache_invalidate_all (DBusHeader *header)
{
int i;
i = 0;
while (i <= DBUS_HEADER_FIELD_LAST)
{
header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_UNKNOWN;
++i;
}
}
|
DoS +Info
| 0
|
_dbus_header_cache_invalidate_all (DBusHeader *header)
{
int i;
i = 0;
while (i <= DBUS_HEADER_FIELD_LAST)
{
header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_UNKNOWN;
++i;
}
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,184
|
_dbus_header_cache_known_nonexistent (DBusHeader *header,
int field)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
return (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT);
}
|
DoS +Info
| 0
|
_dbus_header_cache_known_nonexistent (DBusHeader *header,
int field)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
return (header->fields[field].value_pos == _DBUS_HEADER_FIELD_VALUE_NONEXISTENT);
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,185
|
_dbus_header_cache_one (DBusHeader *header,
int field_code,
DBusTypeReader *variant_reader)
{
header->fields[field_code].value_pos =
_dbus_type_reader_get_value_pos (variant_reader);
#if 0
_dbus_verbose ("cached value_pos %d for field %d\n",
header->fields[field_code].value_pos, field_code)
#endif
}
|
DoS +Info
| 0
|
_dbus_header_cache_one (DBusHeader *header,
int field_code,
DBusTypeReader *variant_reader)
{
header->fields[field_code].value_pos =
_dbus_type_reader_get_value_pos (variant_reader);
#if 0
_dbus_verbose ("cached value_pos %d for field %d\n",
header->fields[field_code].value_pos, field_code)
#endif
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,186
|
_dbus_header_cache_revalidate (DBusHeader *header)
{
DBusTypeReader array;
DBusTypeReader reader;
int i;
i = 0;
while (i <= DBUS_HEADER_FIELD_LAST)
{
header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_NONEXISTENT;
++i;
}
_dbus_type_reader_init (&reader,
header->byte_order,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&header->data,
FIELDS_ARRAY_LENGTH_OFFSET);
_dbus_type_reader_recurse (&reader, &array);
while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID)
{
DBusTypeReader sub;
DBusTypeReader variant;
unsigned char field_code;
_dbus_type_reader_recurse (&array, &sub);
_dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE);
_dbus_type_reader_read_basic (&sub, &field_code);
/* Unknown fields should be ignored */
if (field_code > DBUS_HEADER_FIELD_LAST)
goto next_field;
_dbus_type_reader_next (&sub);
_dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_VARIANT);
_dbus_type_reader_recurse (&sub, &variant);
_dbus_header_cache_one (header, field_code, &variant);
next_field:
_dbus_type_reader_next (&array);
}
}
|
DoS +Info
| 0
|
_dbus_header_cache_revalidate (DBusHeader *header)
{
DBusTypeReader array;
DBusTypeReader reader;
int i;
i = 0;
while (i <= DBUS_HEADER_FIELD_LAST)
{
header->fields[i].value_pos = _DBUS_HEADER_FIELD_VALUE_NONEXISTENT;
++i;
}
_dbus_type_reader_init (&reader,
header->byte_order,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&header->data,
FIELDS_ARRAY_LENGTH_OFFSET);
_dbus_type_reader_recurse (&reader, &array);
while (_dbus_type_reader_get_current_type (&array) != DBUS_TYPE_INVALID)
{
DBusTypeReader sub;
DBusTypeReader variant;
unsigned char field_code;
_dbus_type_reader_recurse (&array, &sub);
_dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_BYTE);
_dbus_type_reader_read_basic (&sub, &field_code);
/* Unknown fields should be ignored */
if (field_code > DBUS_HEADER_FIELD_LAST)
goto next_field;
_dbus_type_reader_next (&sub);
_dbus_assert (_dbus_type_reader_get_current_type (&sub) == DBUS_TYPE_VARIANT);
_dbus_type_reader_recurse (&sub, &variant);
_dbus_header_cache_one (header, field_code, &variant);
next_field:
_dbus_type_reader_next (&array);
}
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,187
|
_dbus_header_copy (const DBusHeader *header,
DBusHeader *dest)
{
*dest = *header;
if (!_dbus_string_init_preallocated (&dest->data,
_dbus_string_get_length (&header->data)))
return FALSE;
if (!_dbus_string_copy (&header->data, 0, &dest->data, 0))
{
_dbus_string_free (&dest->data);
return FALSE;
}
/* Reset the serial */
_dbus_header_set_serial (dest, 0);
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_header_copy (const DBusHeader *header,
DBusHeader *dest)
{
*dest = *header;
if (!_dbus_string_init_preallocated (&dest->data,
_dbus_string_get_length (&header->data)))
return FALSE;
if (!_dbus_string_copy (&header->data, 0, &dest->data, 0))
{
_dbus_string_free (&dest->data);
return FALSE;
}
/* Reset the serial */
_dbus_header_set_serial (dest, 0);
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,188
|
_dbus_header_create (DBusHeader *header,
int message_type,
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *error_name)
{
unsigned char v_BYTE;
dbus_uint32_t v_UINT32;
DBusTypeWriter writer;
DBusTypeWriter array;
_dbus_assert (((interface || message_type != DBUS_MESSAGE_TYPE_SIGNAL) && member) ||
(error_name) ||
!(interface || member || error_name));
_dbus_assert (_dbus_string_get_length (&header->data) == 0);
if (!reserve_header_padding (header))
return FALSE;
_dbus_type_writer_init_values_only (&writer, header->byte_order,
&_dbus_header_signature_str, 0,
&header->data,
HEADER_END_BEFORE_PADDING (header));
v_BYTE = header->byte_order;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = message_type;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = 0; /* flags */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = DBUS_MAJOR_PROTOCOL_VERSION;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_UINT32 = 0; /* body length */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32,
&v_UINT32))
goto oom;
v_UINT32 = 0; /* serial */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32,
&v_UINT32))
goto oom;
if (!_dbus_type_writer_recurse (&writer, DBUS_TYPE_ARRAY,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&array))
goto oom;
/* Marshal all the fields (Marshall Fields?) */
if (path != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_PATH,
DBUS_TYPE_OBJECT_PATH,
&path))
goto oom;
}
if (destination != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_DESTINATION,
DBUS_TYPE_STRING,
&destination))
goto oom;
}
if (interface != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_INTERFACE,
DBUS_TYPE_STRING,
&interface))
goto oom;
}
if (member != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_MEMBER,
DBUS_TYPE_STRING,
&member))
goto oom;
}
if (error_name != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_ERROR_NAME,
DBUS_TYPE_STRING,
&error_name))
goto oom;
}
if (!_dbus_type_writer_unrecurse (&writer, &array))
goto oom;
correct_header_padding (header);
return TRUE;
oom:
_dbus_string_delete (&header->data, 0,
_dbus_string_get_length (&header->data) - header->padding);
correct_header_padding (header);
return FALSE;
}
|
DoS +Info
| 0
|
_dbus_header_create (DBusHeader *header,
int message_type,
const char *destination,
const char *path,
const char *interface,
const char *member,
const char *error_name)
{
unsigned char v_BYTE;
dbus_uint32_t v_UINT32;
DBusTypeWriter writer;
DBusTypeWriter array;
_dbus_assert (((interface || message_type != DBUS_MESSAGE_TYPE_SIGNAL) && member) ||
(error_name) ||
!(interface || member || error_name));
_dbus_assert (_dbus_string_get_length (&header->data) == 0);
if (!reserve_header_padding (header))
return FALSE;
_dbus_type_writer_init_values_only (&writer, header->byte_order,
&_dbus_header_signature_str, 0,
&header->data,
HEADER_END_BEFORE_PADDING (header));
v_BYTE = header->byte_order;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = message_type;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = 0; /* flags */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_BYTE = DBUS_MAJOR_PROTOCOL_VERSION;
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_BYTE,
&v_BYTE))
goto oom;
v_UINT32 = 0; /* body length */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32,
&v_UINT32))
goto oom;
v_UINT32 = 0; /* serial */
if (!_dbus_type_writer_write_basic (&writer, DBUS_TYPE_UINT32,
&v_UINT32))
goto oom;
if (!_dbus_type_writer_recurse (&writer, DBUS_TYPE_ARRAY,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&array))
goto oom;
/* Marshal all the fields (Marshall Fields?) */
if (path != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_PATH,
DBUS_TYPE_OBJECT_PATH,
&path))
goto oom;
}
if (destination != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_DESTINATION,
DBUS_TYPE_STRING,
&destination))
goto oom;
}
if (interface != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_INTERFACE,
DBUS_TYPE_STRING,
&interface))
goto oom;
}
if (member != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_MEMBER,
DBUS_TYPE_STRING,
&member))
goto oom;
}
if (error_name != NULL)
{
if (!write_basic_field (&array,
DBUS_HEADER_FIELD_ERROR_NAME,
DBUS_TYPE_STRING,
&error_name))
goto oom;
}
if (!_dbus_type_writer_unrecurse (&writer, &array))
goto oom;
correct_header_padding (header);
return TRUE;
oom:
_dbus_string_delete (&header->data, 0,
_dbus_string_get_length (&header->data) - header->padding);
correct_header_padding (header);
return FALSE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,189
|
_dbus_header_delete_field (DBusHeader *header,
int field)
{
DBusTypeReader reader;
DBusTypeReader realign_root;
if (_dbus_header_cache_known_nonexistent (header, field))
return TRUE; /* nothing to do */
/* Scan to the field we want, delete and realign, reappend
* padding. Field may turn out not to exist.
*/
if (!find_field_for_modification (header, field,
&reader, &realign_root))
return TRUE; /* nothing to do */
if (!reserve_header_padding (header))
return FALSE;
if (!_dbus_type_reader_delete (&reader,
&realign_root))
return FALSE;
correct_header_padding (header);
_dbus_header_cache_invalidate_all (header);
_dbus_assert (!_dbus_header_cache_check (header, field)); /* Expensive assertion ... */
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_header_delete_field (DBusHeader *header,
int field)
{
DBusTypeReader reader;
DBusTypeReader realign_root;
if (_dbus_header_cache_known_nonexistent (header, field))
return TRUE; /* nothing to do */
/* Scan to the field we want, delete and realign, reappend
* padding. Field may turn out not to exist.
*/
if (!find_field_for_modification (header, field,
&reader, &realign_root))
return TRUE; /* nothing to do */
if (!reserve_header_padding (header))
return FALSE;
if (!_dbus_type_reader_delete (&reader,
&realign_root))
return FALSE;
correct_header_padding (header);
_dbus_header_cache_invalidate_all (header);
_dbus_assert (!_dbus_header_cache_check (header, field)); /* Expensive assertion ... */
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,190
|
_dbus_header_get_flag (DBusHeader *header,
dbus_uint32_t flag)
{
const unsigned char *flags_p;
flags_p = _dbus_string_get_const_data_len (&header->data, FLAGS_OFFSET, 1);
return (*flags_p & flag) != 0;
}
|
DoS +Info
| 0
|
_dbus_header_get_flag (DBusHeader *header,
dbus_uint32_t flag)
{
const unsigned char *flags_p;
flags_p = _dbus_string_get_const_data_len (&header->data, FLAGS_OFFSET, 1);
return (*flags_p & flag) != 0;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,191
|
_dbus_header_get_message_type (DBusHeader *header)
{
int type;
type = _dbus_string_get_byte (&header->data, TYPE_OFFSET);
_dbus_assert (type != DBUS_MESSAGE_TYPE_INVALID);
return type;
}
|
DoS +Info
| 0
|
_dbus_header_get_message_type (DBusHeader *header)
{
int type;
type = _dbus_string_get_byte (&header->data, TYPE_OFFSET);
_dbus_assert (type != DBUS_MESSAGE_TYPE_INVALID);
return type;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,192
|
_dbus_header_get_serial (DBusHeader *header)
{
return _dbus_marshal_read_uint32 (&header->data,
SERIAL_OFFSET,
header->byte_order,
NULL);
}
|
DoS +Info
| 0
|
_dbus_header_get_serial (DBusHeader *header)
{
return _dbus_marshal_read_uint32 (&header->data,
SERIAL_OFFSET,
header->byte_order,
NULL);
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,193
|
_dbus_header_have_message_untrusted (int max_message_length,
DBusValidity *validity,
int *byte_order,
int *fields_array_len,
int *header_len,
int *body_len,
const DBusString *str,
int start,
int len)
{
dbus_uint32_t header_len_unsigned;
dbus_uint32_t fields_array_len_unsigned;
dbus_uint32_t body_len_unsigned;
_dbus_assert (start >= 0);
_dbus_assert (start < _DBUS_INT32_MAX / 2);
_dbus_assert (len >= 0);
_dbus_assert (start == (int) _DBUS_ALIGN_VALUE (start, 8));
*byte_order = _dbus_string_get_byte (str, start + BYTE_ORDER_OFFSET);
if (*byte_order != DBUS_LITTLE_ENDIAN && *byte_order != DBUS_BIG_ENDIAN)
{
*validity = DBUS_INVALID_BAD_BYTE_ORDER;
return FALSE;
}
_dbus_assert (FIELDS_ARRAY_LENGTH_OFFSET + 4 <= len);
fields_array_len_unsigned = _dbus_marshal_read_uint32 (str, start + FIELDS_ARRAY_LENGTH_OFFSET,
*byte_order, NULL);
if (fields_array_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH;
return FALSE;
}
_dbus_assert (BODY_LENGTH_OFFSET + 4 < len);
body_len_unsigned = _dbus_marshal_read_uint32 (str, start + BODY_LENGTH_OFFSET,
*byte_order, NULL);
if (body_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_INSANE_BODY_LENGTH;
return FALSE;
}
header_len_unsigned = FIRST_FIELD_OFFSET + fields_array_len_unsigned;
header_len_unsigned = _DBUS_ALIGN_VALUE (header_len_unsigned, 8);
/* overflow should be impossible since the lengths aren't allowed to
* be huge.
*/
_dbus_assert (max_message_length < _DBUS_INT32_MAX / 2);
if (body_len_unsigned + header_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_MESSAGE_TOO_LONG;
return FALSE;
}
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT32_MAX);
*body_len = body_len_unsigned;
*fields_array_len = fields_array_len_unsigned;
*header_len = header_len_unsigned;
*validity = DBUS_VALID;
_dbus_verbose ("have %d bytes, need body %u + header %u = %u\n",
len, body_len_unsigned, header_len_unsigned,
body_len_unsigned + header_len_unsigned);
return (body_len_unsigned + header_len_unsigned) <= (unsigned) len;
}
|
DoS +Info
| 0
|
_dbus_header_have_message_untrusted (int max_message_length,
DBusValidity *validity,
int *byte_order,
int *fields_array_len,
int *header_len,
int *body_len,
const DBusString *str,
int start,
int len)
{
dbus_uint32_t header_len_unsigned;
dbus_uint32_t fields_array_len_unsigned;
dbus_uint32_t body_len_unsigned;
_dbus_assert (start >= 0);
_dbus_assert (start < _DBUS_INT32_MAX / 2);
_dbus_assert (len >= 0);
_dbus_assert (start == (int) _DBUS_ALIGN_VALUE (start, 8));
*byte_order = _dbus_string_get_byte (str, start + BYTE_ORDER_OFFSET);
if (*byte_order != DBUS_LITTLE_ENDIAN && *byte_order != DBUS_BIG_ENDIAN)
{
*validity = DBUS_INVALID_BAD_BYTE_ORDER;
return FALSE;
}
_dbus_assert (FIELDS_ARRAY_LENGTH_OFFSET + 4 <= len);
fields_array_len_unsigned = _dbus_marshal_read_uint32 (str, start + FIELDS_ARRAY_LENGTH_OFFSET,
*byte_order, NULL);
if (fields_array_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH;
return FALSE;
}
_dbus_assert (BODY_LENGTH_OFFSET + 4 < len);
body_len_unsigned = _dbus_marshal_read_uint32 (str, start + BODY_LENGTH_OFFSET,
*byte_order, NULL);
if (body_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_INSANE_BODY_LENGTH;
return FALSE;
}
header_len_unsigned = FIRST_FIELD_OFFSET + fields_array_len_unsigned;
header_len_unsigned = _DBUS_ALIGN_VALUE (header_len_unsigned, 8);
/* overflow should be impossible since the lengths aren't allowed to
* be huge.
*/
_dbus_assert (max_message_length < _DBUS_INT32_MAX / 2);
if (body_len_unsigned + header_len_unsigned > (unsigned) max_message_length)
{
*validity = DBUS_INVALID_MESSAGE_TOO_LONG;
return FALSE;
}
_dbus_assert (body_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (fields_array_len_unsigned < (unsigned) _DBUS_INT32_MAX);
_dbus_assert (header_len_unsigned < (unsigned) _DBUS_INT32_MAX);
*body_len = body_len_unsigned;
*fields_array_len = fields_array_len_unsigned;
*header_len = header_len_unsigned;
*validity = DBUS_VALID;
_dbus_verbose ("have %d bytes, need body %u + header %u = %u\n",
len, body_len_unsigned, header_len_unsigned,
body_len_unsigned + header_len_unsigned);
return (body_len_unsigned + header_len_unsigned) <= (unsigned) len;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,194
|
_dbus_header_init (DBusHeader *header,
int byte_order)
{
if (!_dbus_string_init_preallocated (&header->data, 32))
return FALSE;
_dbus_header_reinit (header, byte_order);
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_header_init (DBusHeader *header,
int byte_order)
{
if (!_dbus_string_init_preallocated (&header->data, 32))
return FALSE;
_dbus_header_reinit (header, byte_order);
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,195
|
_dbus_header_reinit (DBusHeader *header,
int byte_order)
{
_dbus_string_set_length (&header->data, 0);
header->byte_order = byte_order;
header->padding = 0;
_dbus_header_cache_invalidate_all (header);
}
|
DoS +Info
| 0
|
_dbus_header_reinit (DBusHeader *header,
int byte_order)
{
_dbus_string_set_length (&header->data, 0);
header->byte_order = byte_order;
header->padding = 0;
_dbus_header_cache_invalidate_all (header);
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,196
|
_dbus_header_set_field_basic (DBusHeader *header,
int field,
int type,
const void *value)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
if (!reserve_header_padding (header))
return FALSE;
/* If the field exists we set, otherwise we append */
if (_dbus_header_cache_check (header, field))
{
DBusTypeReader reader;
DBusTypeReader realign_root;
if (!find_field_for_modification (header, field,
&reader, &realign_root))
_dbus_assert_not_reached ("field was marked present in cache but wasn't found");
if (!set_basic_field (&reader, field, type, value, &realign_root))
return FALSE;
}
else
{
DBusTypeWriter writer;
DBusTypeWriter array;
_dbus_type_writer_init_values_only (&writer,
header->byte_order,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&header->data,
FIELDS_ARRAY_LENGTH_OFFSET);
/* recurse into array without creating a new length, and jump to
* end of array.
*/
if (!_dbus_type_writer_append_array (&writer,
&_dbus_header_signature_str,
FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET,
&array))
_dbus_assert_not_reached ("recurse into ARRAY should not have used memory");
_dbus_assert (array.u.array.len_pos == FIELDS_ARRAY_LENGTH_OFFSET);
_dbus_assert (array.u.array.start_pos == FIRST_FIELD_OFFSET);
_dbus_assert (array.value_pos == HEADER_END_BEFORE_PADDING (header));
if (!write_basic_field (&array,
field, type, value))
return FALSE;
if (!_dbus_type_writer_unrecurse (&writer, &array))
_dbus_assert_not_reached ("unrecurse from ARRAY should not have used memory");
}
correct_header_padding (header);
/* We could be smarter about this (only invalidate fields after the
* one we modified, or even only if the one we modified changed
* length). But this hack is a start.
*/
_dbus_header_cache_invalidate_all (header);
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_header_set_field_basic (DBusHeader *header,
int field,
int type,
const void *value)
{
_dbus_assert (field <= DBUS_HEADER_FIELD_LAST);
if (!reserve_header_padding (header))
return FALSE;
/* If the field exists we set, otherwise we append */
if (_dbus_header_cache_check (header, field))
{
DBusTypeReader reader;
DBusTypeReader realign_root;
if (!find_field_for_modification (header, field,
&reader, &realign_root))
_dbus_assert_not_reached ("field was marked present in cache but wasn't found");
if (!set_basic_field (&reader, field, type, value, &realign_root))
return FALSE;
}
else
{
DBusTypeWriter writer;
DBusTypeWriter array;
_dbus_type_writer_init_values_only (&writer,
header->byte_order,
&_dbus_header_signature_str,
FIELDS_ARRAY_SIGNATURE_OFFSET,
&header->data,
FIELDS_ARRAY_LENGTH_OFFSET);
/* recurse into array without creating a new length, and jump to
* end of array.
*/
if (!_dbus_type_writer_append_array (&writer,
&_dbus_header_signature_str,
FIELDS_ARRAY_ELEMENT_SIGNATURE_OFFSET,
&array))
_dbus_assert_not_reached ("recurse into ARRAY should not have used memory");
_dbus_assert (array.u.array.len_pos == FIELDS_ARRAY_LENGTH_OFFSET);
_dbus_assert (array.u.array.start_pos == FIRST_FIELD_OFFSET);
_dbus_assert (array.value_pos == HEADER_END_BEFORE_PADDING (header));
if (!write_basic_field (&array,
field, type, value))
return FALSE;
if (!_dbus_type_writer_unrecurse (&writer, &array))
_dbus_assert_not_reached ("unrecurse from ARRAY should not have used memory");
}
correct_header_padding (header);
/* We could be smarter about this (only invalidate fields after the
* one we modified, or even only if the one we modified changed
* length). But this hack is a start.
*/
_dbus_header_cache_invalidate_all (header);
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,197
|
_dbus_header_set_serial (DBusHeader *header,
dbus_uint32_t serial)
{
/* we use this function to set the serial on outgoing
* messages, and to reset the serial in dbus_message_copy;
* this assertion should catch a double-set on outgoing.
*/
_dbus_assert (_dbus_header_get_serial (header) == 0 ||
serial == 0);
_dbus_marshal_set_uint32 (&header->data,
SERIAL_OFFSET,
serial,
header->byte_order);
}
|
DoS +Info
| 0
|
_dbus_header_set_serial (DBusHeader *header,
dbus_uint32_t serial)
{
/* we use this function to set the serial on outgoing
* messages, and to reset the serial in dbus_message_copy;
* this assertion should catch a double-set on outgoing.
*/
_dbus_assert (_dbus_header_get_serial (header) == 0 ||
serial == 0);
_dbus_marshal_set_uint32 (&header->data,
SERIAL_OFFSET,
serial,
header->byte_order);
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,198
|
_dbus_header_update_lengths (DBusHeader *header,
int body_len)
{
_dbus_marshal_set_uint32 (&header->data,
BODY_LENGTH_OFFSET,
body_len,
header->byte_order);
}
|
DoS +Info
| 0
|
_dbus_header_update_lengths (DBusHeader *header,
int body_len)
{
_dbus_marshal_set_uint32 (&header->data,
BODY_LENGTH_OFFSET,
body_len,
header->byte_order);
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
2,199
|
_dbus_marshal_header_test (void)
{
return TRUE;
}
|
DoS +Info
| 0
|
_dbus_marshal_header_test (void)
{
return TRUE;
}
|
@@ -1468,14 +1468,20 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
+ unsigned char byte_order;
+
if (header->byte_order == new_order)
return;
+ byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+ _dbus_assert (header->byte_order == byte_order);
+
_dbus_marshal_byteswap (&_dbus_header_signature_str,
0, header->byte_order,
new_order,
&header->data, 0);
+ _dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
header->byte_order = new_order;
}
|
CWE-20
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.