Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MB-2899 - parsing config using safe_strtoul functions

Change-Id: I32acf0c94a4a8f0b2b9cc0c6e0518739fb71c09b
Reviewed-on: http://review.membase.org/3741
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information...
commit 1d2c2fe32a441f144aa90993b0085a9225eec5e0 1 parent 1ad35f7
Steve Yen authored November 18, 2010 chiyoung committed November 19, 2010

Showing 1 changed file with 42 additions and 20 deletions. Show diff stats Hide diff stats

  1. 62  cproxy_config.c
62  cproxy_config.c
@@ -612,6 +612,10 @@ void cproxy_parse_behavior_key_val_str(char *key_val,
612 612
 void cproxy_parse_behavior_key_val(char *key,
613 613
                                    char *val,
614 614
                                    proxy_behavior *behavior) {
  615
+    uint32_t ms = 0;
  616
+    uint32_t x = 0;
  617
+    bool ok = false;
  618
+
615 619
     assert(behavior != NULL);
616 620
 
617 621
     if (key != NULL &&
@@ -620,18 +624,18 @@ void cproxy_parse_behavior_key_val(char *key,
620 624
         val = trimstr(val);
621 625
 
622 626
         if (wordeq(key, "cycle")) {
623  
-            behavior->cycle = strtol(val, NULL, 10);
  627
+            ok = safe_strtoul(val, &behavior->cycle);
624 628
         } else if (wordeq(key, "downstream_max") ||
625 629
                    wordeq(key, "concurrency")) {
626  
-            behavior->downstream_max = strtol(val, NULL, 10);
  630
+            ok = safe_strtoul(val, &behavior->downstream_max);
627 631
         } else if (wordeq(key, "downstream_conn_max")) {
628  
-            behavior->downstream_conn_max = strtol(val, NULL, 10);
  632
+            ok = safe_strtoul(val, &behavior->downstream_conn_max);
629 633
         } else if (wordeq(key, "weight") ||
630 634
                    wordeq(key, "downstream_weight")) {
631  
-            behavior->downstream_weight = strtol(val, NULL, 10);
  635
+            ok = safe_strtoul(val, &behavior->downstream_weight);
632 636
         } else if (wordeq(key, "retry") ||
633 637
                    wordeq(key, "downstream_retry")) {
634  
-            behavior->downstream_retry = strtol(val, NULL, 10);
  638
+            ok = safe_strtoul(val, &behavior->downstream_retry);
635 639
         } else if (wordeq(key, "protocol") ||
636 640
                    wordeq(key, "downstream_protocol")) {
637 641
             if (wordeq(val, "ascii") ||
@@ -639,11 +643,13 @@ void cproxy_parse_behavior_key_val(char *key,
639 643
                 wordeq(val, "membase-ascii")) {
640 644
                 behavior->downstream_protocol =
641 645
                     proxy_downstream_ascii_prot;
  646
+                ok = true;
642 647
             } else if (wordeq(val, "binary") ||
643 648
                        wordeq(val, "memcached-binary") ||
644 649
                        wordeq(val, "membase-binary")) {
645 650
                 behavior->downstream_protocol =
646 651
                     proxy_downstream_binary_prot;
  652
+                ok = true;
647 653
             } else {
648 654
                 if (settings.verbose > 1) {
649 655
                     moxi_log_write("unknown behavior prot: %s\n", val);
@@ -652,89 +658,105 @@ void cproxy_parse_behavior_key_val(char *key,
652 658
         } else if (wordeq(key, "timeout") ||
653 659
                    wordeq(key, "downstream_timeout") ||
654 660
                    wordeq(key, "downstream_conn_timeout")) {
655  
-            int ms = strtol(val, NULL, 10);
  661
+            ok = safe_strtoul(val, &ms);
656 662
             behavior->downstream_timeout.tv_sec  = floor(ms / 1000.0);
657 663
             behavior->downstream_timeout.tv_usec = (ms % 1000) * 1000;
658 664
         } else if (wordeq(key, "downstream_conn_queue_timeout")) {
659  
-            int ms = strtol(val, NULL, 10);
  665
+            ok = safe_strtoul(val, &ms);
660 666
             behavior->downstream_conn_queue_timeout.tv_sec  = floor(ms / 1000.0);
661 667
             behavior->downstream_conn_queue_timeout.tv_usec = (ms % 1000) * 1000;
662 668
         } else if (wordeq(key, "wait_queue_timeout")) {
663  
-            int ms = strtol(val, NULL, 10);
  669
+            ok = safe_strtoul(val, &ms);
664 670
             behavior->wait_queue_timeout.tv_sec  = floor(ms / 1000.0);
665 671
             behavior->wait_queue_timeout.tv_usec = (ms % 1000) * 1000;
666 672
         } else if (wordeq(key, "connect_timeout")) {
667  
-            int ms = strtol(val, NULL, 10);
  673
+            ok = safe_strtoul(val, &ms);
668 674
             behavior->connect_timeout.tv_sec  = floor(ms / 1000.0);
669 675
             behavior->connect_timeout.tv_usec = (ms % 1000) * 1000;
670 676
         } else if (wordeq(key, "auth_timeout")) {
671  
-            int ms = strtol(val, NULL, 10);
  677
+            ok = safe_strtoul(val, &ms);
672 678
             behavior->auth_timeout.tv_sec  = floor(ms / 1000.0);
673 679
             behavior->auth_timeout.tv_usec = (ms % 1000) * 1000;
674 680
         } else if (wordeq(key, "time_stats")) {
675  
-            behavior->time_stats = strtol(val, NULL, 10);
  681
+            ok = safe_strtoul(val, &x);
  682
+            behavior->time_stats = x;
676 683
         } else if (wordeq(key, "connect_max_errors")) {
677  
-            behavior->connect_max_errors = strtol(val, NULL, 10);
  684
+            ok = safe_strtoul(val, &behavior->connect_max_errors);
678 685
         } else if (wordeq(key, "connect_retry_interval")) {
679  
-            behavior->connect_retry_interval = strtol(val, NULL, 10);
  686
+            ok = safe_strtoul(val, &behavior->connect_retry_interval);
680 687
         } else if (wordeq(key, "front_cache_max")) {
681  
-            behavior->front_cache_max = strtol(val, NULL, 10);
  688
+            ok = safe_strtoul(val, &behavior->front_cache_max);
682 689
         } else if (wordeq(key, "front_cache_lifespan")) {
683  
-            behavior->front_cache_lifespan = strtol(val, NULL, 10);
  690
+            ok = safe_strtoul(val, &behavior->front_cache_lifespan);
684 691
         } else if (wordeq(key, "front_cache_spec")) {
685 692
             if (strlen(val) < sizeof(behavior->front_cache_spec)) {
686 693
                 strcpy(behavior->front_cache_spec, val);
  694
+                ok = true;
687 695
             }
688 696
         } else if (wordeq(key, "front_cache_unspec")) {
689 697
             if (strlen(val) < sizeof(behavior->front_cache_unspec)) {
690 698
                 strcpy(behavior->front_cache_unspec, val);
  699
+                ok = true;
691 700
             }
692 701
         } else if (wordeq(key, "key_stats_max")) {
693  
-            behavior->key_stats_max = strtol(val, NULL, 10);
  702
+            ok = safe_strtoul(val, &behavior->key_stats_max);
694 703
         } else if (wordeq(key, "key_stats_lifespan")) {
695  
-            behavior->key_stats_lifespan = strtol(val, NULL, 10);
  704
+            ok = safe_strtoul(val, &behavior->key_stats_lifespan);
696 705
         } else if (wordeq(key, "key_stats_spec")) {
697 706
             if (strlen(val) < sizeof(behavior->key_stats_spec)) {
698 707
                 strcpy(behavior->key_stats_spec, val);
  708
+                ok = true;
699 709
             }
700 710
         } else if (wordeq(key, "key_stats_unspec")) {
701 711
             if (strlen(val) < sizeof(behavior->key_stats_unspec)) {
702 712
                 strcpy(behavior->key_stats_unspec, val);
  713
+                ok = true;
703 714
             }
704 715
         } else if (wordeq(key, "optimize_set")) {
705 716
             if (strlen(val) < sizeof(behavior->optimize_set)) {
706 717
                 strcpy(behavior->optimize_set, val);
  718
+                ok = true;
707 719
             }
708 720
         } else if (wordeq(key, "usr")) {
709 721
             if (strlen(val) < sizeof(behavior->usr)) {
710 722
                 strcpy(behavior->usr, val);
  723
+                ok = true;
711 724
             }
712 725
         } else if (wordeq(key, "pwd")) {
713 726
             if (strlen(val) < sizeof(behavior->pwd)) {
714 727
                 strcpy(behavior->pwd, val);
  728
+                ok = true;
715 729
             }
716 730
         } else if (wordeq(key, "host")) {
717 731
             if (strlen(val) < sizeof(behavior->host)) {
718 732
                 strcpy(behavior->host, val);
  733
+                ok = true;
719 734
             }
720 735
         } else if (wordeq(key, "port")) {
721  
-            behavior->port = strtol(val, NULL, 10);
  736
+            ok = safe_strtol(val, &behavior->port);
722 737
         } else if (wordeq(key, "bucket")) {
723 738
             if (strlen(val) < sizeof(behavior->bucket)) {
724 739
                 strcpy(behavior->bucket, val);
  740
+                ok = true;
725 741
             }
726 742
         } else if (wordeq(key, "port_listen")) {
727  
-            behavior->port_listen = strtol(val, NULL, 10);
  743
+            ok = safe_strtol(val, &behavior->port_listen);
728 744
         } else if (wordeq(key, "default_bucket_name")) {
729 745
             if (strlen(val) < sizeof(behavior->default_bucket_name)) {
730 746
                 strcpy(behavior->default_bucket_name, val);
  747
+                ok = true;
731 748
             }
732 749
         } else {
733 750
             if (settings.verbose > 1) {
734  
-                moxi_log_write("unknown behavior key: %s\n", key);
  751
+                moxi_log_write("ERROR: unknown behavior key: %s\n", key);
735 752
             }
736 753
         }
737 754
     }
  755
+
  756
+    if (ok == false) {
  757
+        moxi_log_write("ERROR: config error in key: %s value: %s\n",
  758
+                       key, val);
  759
+    }
738 760
 }
739 761
 
740 762
 /**

0 notes on commit 1d2c2fe

Please sign in to comment.
Something went wrong with that request. Please try again.