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

Fix a bug in my IP handling. #118

Merged
merged 2 commits into from
Mar 23, 2022
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
8 changes: 7 additions & 1 deletion src/pacparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,17 @@ static JSClass global_class = {
};

// Set my (client's) IP address to a custom value.
void
int
pacparser_setmyip(const char *ip)
{
if (strlen(ip) > INET6_ADDRSTRLEN) {
fprintf(stderr, "pacparser_setmyip: IP too long: %s\n", ip);
return 0;
}

myip = malloc(strlen(ip) +1); // Allocate space just to be sure.
strcpy(myip, ip);
return 1;
}

// Decprecated: This function doesn't do anything.
Expand Down
3 changes: 2 additions & 1 deletion src/pacparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ void pacparser_cleanup(void);

/// @brief Sets my IP address.
/// @param ip Custom IP address.
/// @returns 1 on success and 0 on error.
///
/// Sets my IP address to a custom value. This is the IP address returned by
/// myIpAddress() javascript function.
void pacparser_setmyip(const char *ip // Custom IP address.
int pacparser_setmyip(const char *ip // Custom IP address.
);

/// @brief Type definition for pacparser_error_printer.
Expand Down
6 changes: 5 additions & 1 deletion src/pactester.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ int main(int argc, char* argv[])
}

if (client_ip)
pacparser_setmyip(client_ip);
if (!pacparser_setmyip(client_ip)) {
fprintf(stderr, "pactester.c: Error setting client IP\n");
pacparser_cleanup();
return 1;
}

char *proxy;

Expand Down