mirror of
https://github.com/curl/curl.git
synced 2026-08-26 11:43:32 +03:00
strparse: switch to curl_off_t as base data type
- add hex and octal parsers to the Curl_str_* family - make curlx_strtoofft use these parsers - remove all use of strtol() and strtoul() in library code - generally use Curl_str_* more than strtoofft, for stricter parsing - supports 64-bit universally, instead of 'long' which differs in size between platforms Extended the unit test 1664 to verify hex and octal parsing. Closes #16336
This commit is contained in:
parent
876db1070b
commit
b4538ec522
46 changed files with 538 additions and 497 deletions
31
lib/cookie.c
31
lib/cookie.c
|
|
@ -80,7 +80,6 @@ Example set of cookies:
|
|||
#include "sendf.h"
|
||||
#include "slist.h"
|
||||
#include "share.h"
|
||||
#include "strtoofft.h"
|
||||
#include "strcase.h"
|
||||
#include "curl_get_line.h"
|
||||
#include "curl_memrchr.h"
|
||||
|
|
@ -89,6 +88,7 @@ Example set of cookies:
|
|||
#include "fopen.h"
|
||||
#include "strdup.h"
|
||||
#include "llist.h"
|
||||
#include "strparse.h"
|
||||
|
||||
/* The last 3 #include files should be in this order */
|
||||
#include "curl_printf.h"
|
||||
|
|
@ -708,21 +708,22 @@ parse_cookie_header(struct Curl_easy *data,
|
|||
* client should discard the cookie. A value of zero means the
|
||||
* cookie should be discarded immediately.
|
||||
*/
|
||||
CURLofft offt;
|
||||
int rc;
|
||||
const char *maxage = valuep;
|
||||
offt = curlx_strtoofft((*maxage == '\"') ?
|
||||
&maxage[1] : &maxage[0], NULL, 10,
|
||||
&co->expires);
|
||||
switch(offt) {
|
||||
case CURL_OFFT_FLOW:
|
||||
if(*maxage == '\"')
|
||||
maxage++;
|
||||
rc = Curl_str_number(&maxage, &co->expires, CURL_OFF_T_MAX);
|
||||
|
||||
switch(rc) {
|
||||
case STRE_OVERFLOW:
|
||||
/* overflow, used max value */
|
||||
co->expires = CURL_OFF_T_MAX;
|
||||
break;
|
||||
case CURL_OFFT_INVAL:
|
||||
default:
|
||||
/* negative or otherwise bad, expire */
|
||||
co->expires = 1;
|
||||
break;
|
||||
case CURL_OFFT_OK:
|
||||
case STRE_OK:
|
||||
if(!co->expires)
|
||||
/* already expired */
|
||||
co->expires = 1;
|
||||
|
|
@ -915,16 +916,8 @@ parse_netscape(struct Cookie *co,
|
|||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
char *endp;
|
||||
const char *p;
|
||||
/* make sure curlx_strtoofft won't read past the current field */
|
||||
for(p = ptr; p < &ptr[len] && ISDIGIT(*p); ++p)
|
||||
;
|
||||
if(p == ptr || p != &ptr[len] ||
|
||||
curlx_strtoofft(ptr, &endp, 10, &co->expires) || endp != &ptr[len])
|
||||
return CERR_RANGE;
|
||||
}
|
||||
if(Curl_str_number(&ptr, &co->expires, CURL_OFF_T_MAX))
|
||||
return CERR_RANGE;
|
||||
break;
|
||||
case 5:
|
||||
co->name = Curl_memdup0(ptr, len);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue