History log of /curl/src/var.c (Results 1 – 7 of 7)
Revision Date Author Comments
# ef4bd8d6 07-Feb-2024 Daniel Stenberg

curl: when allocating variables, add the name into the struct

This saves the name from being an extra separate allocation.

Closes #12891


# 0f0edc28 05-Feb-2024 Daniel Stenberg

curl: exit on config file parser errors

Like when trying to import an environment variable that does not exist.

Also fix a bug for reading env variables when there is a default valu

curl: exit on config file parser errors

Like when trying to import an environment variable that does not exist.

Also fix a bug for reading env variables when there is a default value
set.

Bug: https://curl.se/mail/archive-2024-02/0008.html
Reported-by: Brett Buddin

Add test 462 to verify.

Closes #12862

show more ...


# bc8509a7 07-Nov-2023 Sam James

misc: fix -Walloc-size warnings

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:

```
src/tool_operate.c: In function ‘add_per_transfer’:
src/tool_operat

misc: fix -Walloc-size warnings

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:

```
src/tool_operate.c: In function ‘add_per_transfer’:
src/tool_operate.c:213:5: warning: allocation of insufficient size ‘1’ for type ‘struct per_transfer’ with size ‘480’ [-Walloc-size]
213 | p = calloc(sizeof(struct per_transfer), 1);
| ^
src/var.c: In function ‘addvariable’:
src/var.c:361:5: warning: allocation of insufficient size ‘1’ for type ‘struct var’ with size ‘32’ [-Walloc-size]
361 | p = calloc(sizeof(struct var), 1);
| ^
```

The calloc prototype is:
```
void *calloc(size_t nmemb, size_t size);
```

So, just swap the number of members and size arguments to match the
prototype, as we're initialising 1 struct of size `sizeof(struct
...)`. GCC then sees we're not doing anything wrong.

Closes #12292

show more ...


# aacbeae7 20-Aug-2023 Jay Satiro

tool: change some fopen failures from warnings to errors

- Error on missing input file for --data, --data-binary,
--data-urlencode, --header, --variable, --write-out.

Prior to

tool: change some fopen failures from warnings to errors

- Error on missing input file for --data, --data-binary,
--data-urlencode, --header, --variable, --write-out.

Prior to this change if a user of the curl tool specified an input file
for one of the above options and that file could not be opened then it
would be treated as zero length data instead of an error. For example, a
POST using `--data @filenametypo` would cause a zero length POST which
is probably not what the user intended.

Closes https://github.com/curl/curl/pull/11677

show more ...


# 70f1b540 19-Aug-2023 Emanuele Torre

tool/var: also error when expansion result starts with NUL

Expansions whose output starts with NUL were being expanded to the empty
string, and not being recognised as values that contai

tool/var: also error when expansion result starts with NUL

Expansions whose output starts with NUL were being expanded to the empty
string, and not being recognised as values that contain a NUL byte, and
should error.

Closes #11694

show more ...


# c17bf311 02-Aug-2023 Daniel Stenberg

tool/var: free memory on OOM

Coverity detected this memory leak in OOM situation

Follow-up to 2e160c9c652504e

Closes #11575


# 2e160c9c 31-Jul-2023 Daniel Stenberg

tool: add "variable" support

Add support for command line variables. Set variables with --variable
name=content or --variable name@file (where "file" can be stdin if set
to a single

tool: add "variable" support

Add support for command line variables. Set variables with --variable
name=content or --variable name@file (where "file" can be stdin if set
to a single dash (-)).

Variable content is expanded in option parameters using "{{name}}"
(without the quotes) if the option name is prefixed with
"--expand-". This gets the contents of the variable "name" inserted, or
a blank if the name does not exist as a variable. Insert "{{" verbatim
in the string by prefixing it with a backslash, like "\\{{".

Import an environment variable with --variable %name. It makes curl exit
with an error if the environment variable is not set. It can also rather
get a default value if the variable does not exist, using =content or
@file like shown above.

Example: get the USER environment variable into the URL:

--variable %USER
--expand-url = "https://example.com/api/{{USER}}/method"

When expanding variables, curl supports a set of functions that can make
the variable contents more convenient to use. It can trim leading and
trailing white space with "trim", output the contents as a JSON quoted
string with "json", URL encode it with "url" and base 64 encode it with
"b64". To apply functions to a variable expansion, add them colon
separated to the right side of the variable. They are then performed in
a left to right order.

Example: get the contents of a file called $HOME/.secret into a variable
called "fix". Make sure that the content is trimmed and percent-encoded
sent as POST data:

--variable %HOME=/home/default
--expand-variable fix@{{HOME}}/.secret
--expand-data "{{fix:trim:url}}"
https://example.com/

Documented. Many new test cases.

Co-brainstormed-by: Emanuele Torre
Assisted-by: Jat Satiro
Closes #11346

show more ...