cake
/
libg1m
Archived
1
0
Fork 0

Made more checks.

This commit is contained in:
Thomas Touhey 2017-03-22 15:35:46 +01:00
parent 57e1a4a112
commit ee7365d000
2 changed files with 18 additions and 2 deletions

View File

@ -17,6 +17,7 @@
* along with libg1m; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#include <libg1m/internals.h>
#include <ctype.h>
/**
* g1m_decode_date:
@ -29,7 +30,15 @@
int g1m_decode_date(const char *c, time_t *t)
{
/* TODO: make checks on structure */
/* checks */
if (memchr(c, 0, 14)) return (g1m_error_op);
if (!isdigit(c[0]) || !isdigit(c[1]) || !isdigit(c[2])
|| !isdigit(c[3]) || c[4] != '.'
|| !isdigit(c[5]) || !isdigit(c[6]) || !isdigit(c[7])
|| !isdigit(c[8]) || c[9] != '.'
|| !isdigit(c[10]) || !isdigit(c[11]) || !isdigit(c[12])
|| !isdigit(c[13]))
return (g1m_error_op);
/* helper values */
const int two = '0' + '0' * 10;

View File

@ -17,6 +17,7 @@
* along with libg1m; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#include <libg1m/internals.h>
#include <ctype.h>
/**
* g1m_decode_version:
@ -29,7 +30,13 @@
int g1m_decode_version(const char *raw, g1m_version_t *version)
{
/* TODO: make checks on format */
/* checks */
if (memchr(raw, 0, 10)) return (g1m_error_op);
if (!isdigit(raw[0]) || !isdigit(raw[1]) || raw[2] != '.'
|| !isdigit(raw[3]) || !isdigit(raw[4]) || raw[5] != '.'
|| !isdigit(raw[6]) || !isdigit(raw[7])
|| !isdigit(raw[8]) || !isdigit(raw[9]))
return (g1m_error_op);
/* helper values */
const int two = '0' + '0' * 10;