mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-16 19:40:57 +01:00
better error handling for sscanf output in pbp import
This commit is contained in:
@@ -392,18 +392,23 @@ pcp_ks_bundle_t *pcp_import_pub_pbp(PCPCTX *ptx, Buffer *blob) {
|
|||||||
date[19] = '\0';
|
date[19] = '\0';
|
||||||
struct tm c;
|
struct tm c;
|
||||||
c.tm_isdst = -1;
|
c.tm_isdst = -1;
|
||||||
if(sscanf(date, "%4d-%2d-%2dT%2d:%2d:%2d", &c.tm_year, &c.tm_mon, &c.tm_mday, &c.tm_hour, &c.tm_min, &c.tm_sec)) {
|
int tmok = sscanf(date, "%4d-%2d-%2dT%2d:%2d:%2d",
|
||||||
|
&c.tm_year, &c.tm_mon, &c.tm_mday, &c.tm_hour, &c.tm_min, &c.tm_sec);
|
||||||
|
|
||||||
|
if(tmok <= 0 || c.tm_hour >= 24 || c.tm_mon >= 59 || c.tm_sec >= 59) {
|
||||||
|
/* check returned tm values, which will look like this when input
|
||||||
|
was no string: 30867--12305-0 4229688:8:21790784
|
||||||
|
or: sscanf failed altogether.
|
||||||
|
*/
|
||||||
fatal(ptx, "Failed to parse creation time in PBP public key file\n");
|
fatal(ptx, "Failed to parse creation time in PBP public key file\n");
|
||||||
free(date);
|
free(date);
|
||||||
ucfree(b, sizeof(pbp_pubkey_t));
|
ucfree(b, sizeof(pbp_pubkey_t));
|
||||||
goto errimp2;
|
goto errimp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.tm_mon -= 1;
|
c.tm_mon -= 1;
|
||||||
c.tm_year -= 1900;
|
c.tm_year -= 1900;
|
||||||
|
|
||||||
buffer_fwd_offset(blob, 46);
|
|
||||||
memcpy(b->name, buffer_get(blob), buffer_left(blob));
|
|
||||||
|
|
||||||
/* parse the name */
|
/* parse the name */
|
||||||
parts = strtok (b->name, "<>");
|
parts = strtok (b->name, "<>");
|
||||||
pnum = 0;
|
pnum = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user