diff options
-rw-r--r-- | drivers/isdn/gigaset/ev-layer.c | 80 |
1 files changed, 20 insertions, 60 deletions
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c index a230ba707ff0..a14187605f5e 100644 --- a/drivers/isdn/gigaset/ev-layer.c +++ b/drivers/isdn/gigaset/ev-layer.c | |||
@@ -385,64 +385,18 @@ static const struct zsau_resp_t { | |||
385 | {NULL, ZSAU_UNKNOWN} | 385 | {NULL, ZSAU_UNKNOWN} |
386 | }; | 386 | }; |
387 | 387 | ||
388 | /* | ||
389 | * Get integer from char-pointer | ||
390 | */ | ||
391 | static int isdn_getnum(char *p) | ||
392 | { | ||
393 | int v = -1; | ||
394 | |||
395 | gig_dbg(DEBUG_EVENT, "string: %s", p); | ||
396 | |||
397 | while (*p >= '0' && *p <= '9') | ||
398 | v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0'); | ||
399 | if (*p) | ||
400 | v = -1; /* invalid Character */ | ||
401 | return v; | ||
402 | } | ||
403 | |||
404 | /* | ||
405 | * Get integer from char-pointer | ||
406 | */ | ||
407 | static int isdn_gethex(char *p) | ||
408 | { | ||
409 | int v = 0; | ||
410 | int c; | ||
411 | |||
412 | gig_dbg(DEBUG_EVENT, "string: %s", p); | ||
413 | |||
414 | if (!*p) | ||
415 | return -1; | ||
416 | |||
417 | do { | ||
418 | if (v > (INT_MAX - 15) / 16) | ||
419 | return -1; | ||
420 | c = *p; | ||
421 | if (c >= '0' && c <= '9') | ||
422 | c -= '0'; | ||
423 | else if (c >= 'a' && c <= 'f') | ||
424 | c -= 'a' - 10; | ||
425 | else if (c >= 'A' && c <= 'F') | ||
426 | c -= 'A' - 10; | ||
427 | else | ||
428 | return -1; | ||
429 | v = v * 16 + c; | ||
430 | } while (*++p); | ||
431 | |||
432 | return v; | ||
433 | } | ||
434 | |||
435 | /* retrieve CID from parsed response | 388 | /* retrieve CID from parsed response |
436 | * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535 | 389 | * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535 |
437 | */ | 390 | */ |
438 | static int cid_of_response(char *s) | 391 | static int cid_of_response(char *s) |
439 | { | 392 | { |
440 | int cid; | 393 | unsigned long cid; |
394 | int rc; | ||
441 | 395 | ||
442 | if (s[-1] != ';') | 396 | if (s[-1] != ';') |
443 | return 0; /* no CID separator */ | 397 | return 0; /* no CID separator */ |
444 | cid = isdn_getnum(s); | 398 | rc = strict_strtoul(s, 10, &cid); |
445 | if (cid < 0) | 399 | if (rc) |
446 | return 0; /* CID not numeric */ | 400 | return 0; /* CID not numeric */ |
447 | if (cid < 1 || cid > 65535) | 401 | if (cid < 1 || cid > 65535) |
448 | return -1; /* CID out of range */ | 402 | return -1; /* CID out of range */ |
@@ -612,21 +566,27 @@ void gigaset_handle_modem_response(struct cardstate *cs) | |||
612 | case RT_ZCAU: | 566 | case RT_ZCAU: |
613 | event->parameter = -1; | 567 | event->parameter = -1; |
614 | if (curarg + 1 < params) { | 568 | if (curarg + 1 < params) { |
615 | i = isdn_gethex(argv[curarg]); | 569 | unsigned long type, value; |
616 | j = isdn_gethex(argv[curarg + 1]); | 570 | |
617 | if (i >= 0 && i < 256 && j >= 0 && j < 256) | 571 | i = strict_strtoul(argv[curarg++], 16, &type); |
618 | event->parameter = (unsigned) i << 8 | 572 | j = strict_strtoul(argv[curarg++], 16, &value); |
619 | | j; | 573 | |
620 | curarg += 2; | 574 | if (i == 0 && type < 256 && |
575 | j == 0 && value < 256) | ||
576 | event->parameter = (type << 8) | value; | ||
621 | } else | 577 | } else |
622 | curarg = params - 1; | 578 | curarg = params - 1; |
623 | break; | 579 | break; |
624 | case RT_NUMBER: | 580 | case RT_NUMBER: |
581 | event->parameter = -1; | ||
625 | if (curarg < params) { | 582 | if (curarg < params) { |
626 | event->parameter = isdn_getnum(argv[curarg]); | 583 | unsigned long res; |
627 | ++curarg; | 584 | int rc; |
628 | } else | 585 | |
629 | event->parameter = -1; | 586 | rc = strict_strtoul(argv[curarg++], 10, &res); |
587 | if (rc == 0) | ||
588 | event->parameter = res; | ||
589 | } | ||
630 | gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter); | 590 | gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter); |
631 | break; | 591 | break; |
632 | } | 592 | } |