telnet: parse the WS= argument without sscanf

Closes #10596
This commit is contained in:
Daniel Stenberg 2023-02-23 18:20:16 +01:00
parent 0c28ba2faa
commit e4f93be9d5
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -841,10 +841,19 @@ static CURLcode check_telnet_options(struct Curl_easy *data)
case 2:
/* Window Size */
if(strncasecompare(option, "WS", 2)) {
if(sscanf(arg, "%hu%*[xX]%hu",
&tn->subopt_wsx, &tn->subopt_wsy) == 2)
char *p;
unsigned long x = strtoul(arg, &p, 10);
unsigned long y = 0;
if(Curl_raw_tolower(*p) == 'x') {
p++;
y = strtoul(p, NULL, 10);
if(x && y && (x <= 0xffff) && (y <= 0xffff)) {
tn->subopt_wsx = (unsigned short)x;
tn->subopt_wsy = (unsigned short)y;
tn->us_preferred[CURL_TELOPT_NAWS] = CURL_YES;
else {
}
}
if(!y) {
failf(data, "Syntax error in telnet option: %s", head->data);
result = CURLE_SETOPT_OPTION_SYNTAX;
}