int test_strisdigit_s() { bool rc; uint32_t len; char str[LEN]; /*--------------------------------------------------*/ len = 5; rc = strisdigit_s(NULL, len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ len = 0; rc = strisdigit_s("1234", len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ len = 99999; rc = strisdigit_s("1234", len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ len = 9; rc = strisdigit_s("", len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ strcpy(str, "123456789"); len = 4; rc = strisdigit_s(str, len); if (rc != true) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ strcpy(str, "1"); len = strlen(str); rc = strisdigit_s(str, len); if (rc != true) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ strcpy(str, "12"); len = strlen(str); rc = strisdigit_s(str, len); if (rc != true) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ strcpy(str, "1abcd"); len = strlen(str); rc = strisdigit_s(str, len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ strcpy(str, "abcd"); len = strlen(str); rc = strisdigit_s(str, len); if (rc != false) { printf("%s %u Error rc=%u \n", __FUNCTION__, __LINE__, rc ); } /*--------------------------------------------------*/ return (0); }
/* * This function takes in the list of headers that were in the server's * response, it walks through the headers looking for a Retry-After response * header. If one is found, the value is parsed and saved away in the EST * context. This value can be in one of two formats, both are represented as * an ASCII string. The first format can be a count of the number of seconds * the client should wait before retrying the request. The second format is a * time/date stamp of the point in time at which the client should retry the * request. The result of this function is the setting of the retry_after * values in the context. If no retry-after header was received, or was * received and could not be parsed, the values will be zero, otherwise, they * are set to the value received. * * NOTE: The EST client currently does not support the time/date format * response and will not process a response in this format. */ static EST_ERROR est_io_parse_http_retry_after_resp (EST_CTX *ctx, HTTP_HEADER *hdrs, int hdr_cnt) { EST_ERROR rv = EST_ERR_INVALID_RETRY_VALUE; int i; int cmp_result, diff; int rc; long long int temp_ll; int found = 0; /* * Initialize assuming there was no retry-after header. */ ctx->retry_after_delay = 0; ctx->retry_after_date = 0; for (i = 0; i < hdr_cnt; i++) { cmp_result = strcasecmp_s(hdrs[i].name, sizeof(EST_HTTP_HDR_RETRY_AFTER), EST_HTTP_HDR_RETRY_AFTER, &diff); if (cmp_result == EOK && !diff) { EST_LOG_INFO("Retry-After value = %s", hdrs[i].value); found = 1; /* * Determine whether or not the value is a date/time string * or is an integer representing the number of seconds * that the client must wait. */ if (isalpha(*(char *)hdrs[i].value)) { #ifdef RETRY_AFTER_DELAY_TIME_SUPPORT int rc; /* * Convert the date/time string into a time_t */ rc = parsedate(hdrs[i].value, &ctx->retry_after_date); if (rc != PARSEDATE_OK) { EST_LOG_ERR("Retry-After value could not be parsed"); } #else /* * This format is not currently supported. */ EST_LOG_ERR("Retry-After value not in the correct format"); #endif } else { /* * make sure it's all digits, make sure it's no larger than a * four byte integer, and cache away the value returned for * the retry delay. */ rc = strisdigit_s(hdrs[i].value, 10); // max of 10 decimal places if (rc) { temp_ll = atoll(hdrs[i].value); if (temp_ll <= INT_MAX) { ctx->retry_after_delay = (int) temp_ll; rv = EST_ERR_CA_ENROLL_RETRY; } else { EST_LOG_ERR("Retry-After value too large"); } } else { EST_LOG_ERR("Retry-After value could not be parsed"); } } } } if (found == 0) { EST_LOG_ERR("Retry-After header missing"); } return rv; }