Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uwsgi_opt_set_int: use strtol() and warn on non-numeric data #2032

Merged
merged 2 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions check/check_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ START_TEST(test_uwsgi_opt_set_int)

uwsgi_opt_set_int("", "60", &result);
ck_assert(result == 60);

// When used with "optional_argument", value will be passed as NULL
uwsgi_opt_set_int("", NULL, &result);
ck_assert(result == 1);
}
END_TEST

Expand Down
6 changes: 5 additions & 1 deletion core/uwsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4138,7 +4138,11 @@ void uwsgi_opt_safe_fd(char *opt, char *value, void *foobar) {
void uwsgi_opt_set_int(char *opt, char *value, void *key) {
int *ptr = (int *) key;
if (value) {
*ptr = atoi((char *) value);
char *endptr;
*ptr = (int)strtol(value, &endptr, 10);
if (*endptr) {
uwsgi_log("[WARNING] non-numeric value \"%s\" for option \"%s\" - using %d !\n", value, opt, *ptr);
}
}
else {
*ptr = 1;
Expand Down