test for -1 (EOF) sscanf result

This commit is contained in:
bol-van 2021-12-27 12:54:07 +03:00
parent 606063dd48
commit 2a3b9cf982
3 changed files with 6 additions and 8 deletions

View File

@ -184,7 +184,7 @@ static void parse_params(int argc, char *argv[])
case 4:
i = sscanf(optarg,"%u-%u",&plen1,&plen2);
if (i == 1) plen2 = plen1;
if (!i || plen2<plen1 || !plen1 || !plen2)
if (i<=0 || plen2<plen1 || !plen1 || !plen2)
{
fprintf(stderr, "invalid parameter for prefix-length : %s\n", optarg);
exit(1);
@ -245,17 +245,15 @@ int main(int argc, char **argv)
{
// we have subnet ip6/y
// output it as is
*s = d;
if (sscanf(s + 1, "%u", &zct) && zct!=128)
if (sscanf(s + 1, "%u", &zct)==1 && zct!=128)
{
if (zct<128) printf("%s\n", str);
if (zct<128) printf("%s/%u\n", str, zct);
continue;
}
}
else if (d=='-')
{
*s = d;
if (inet_pton(AF_INET6, s+1, &a)) printf("%s\n", str);
if (inet_pton(AF_INET6, s+1, &a)) printf("%s-%s\n", str, s+1);
continue;
}
if (ipct >= iplist_size)

View File

@ -204,7 +204,7 @@ static void *t_resolver(void *arg)
bool mask_needed = false;
if (s_mask)
{
if (sscanf(s_mask, "%u", &mask))
if (sscanf(s_mask, "%u", &mask)==1)
{
switch (family)
{

View File

@ -348,7 +348,7 @@ void parse_params(int argc, char *argv[])
case 13: /* uid */
params.gid=0x7FFFFFFF; // default git. drop gid=0
params.droproot = true;
if (!sscanf(optarg,"%u:%u",&params.uid,&params.gid))
if (sscanf(optarg,"%u:%u",&params.uid,&params.gid)<1)
{
fprintf(stderr, "--uid should be : uid[:gid]\n");
exit_clean(1);