@@ -6411,16 +6411,12 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
6411
6411
}
6412
6412
else if (streq (p [0 ], "management-log-cache" ) && p [1 ] && !p [2 ])
6413
6413
{
6414
- int cache ;
6415
-
6416
6414
VERIFY_PERMISSION (OPT_P_GENERAL );
6417
- cache = atoi_warn ( p [1 ], msglevel );
6418
- if ( cache < 1 )
6415
+ if (! atoi_constrained ( p [1 ], & options -> management_log_history_cache ,
6416
+ p [ 0 ], 1 , INT_MAX , msglevel ) )
6419
6417
{
6420
- msg (msglevel , "--management-log-cache parameter is out of range" );
6421
6418
goto err ;
6422
6419
}
6423
- options -> management_log_history_cache = cache ;
6424
6420
}
6425
6421
#endif /* ifdef ENABLE_MANAGEMENT */
6426
6422
#ifdef ENABLE_PLUGIN
@@ -6969,16 +6965,11 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
6969
6965
}
6970
6966
else if (streq (p [0 ], "status - version ") && p [1 ] && !p [2 ])
6971
6967
{
6972
- int version ;
6973
-
6974
6968
VERIFY_PERMISSION (OPT_P_GENERAL );
6975
- version = atoi_warn (p [1 ], msglevel );
6976
- if (version < 1 || version > 3 )
6969
+ if (!atoi_constrained (p [1 ], & options -> status_file_version , p [0 ], 1 , 3 , msglevel ))
6977
6970
{
6978
- msg (msglevel , "--status-version must be 1 to 3" );
6979
6971
goto err ;
6980
6972
}
6981
- options -> status_file_version = version ;
6982
6973
}
6983
6974
else if (streq (p [0 ], "remap - usr1 ") && p [1 ] && !p [2 ])
6984
6975
{
@@ -7151,16 +7142,11 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
7151
7142
}
7152
7143
else if (streq (p [0 ], "shaper ") && p [1 ] && !p [2 ])
7153
7144
{
7154
- int shaper ;
7155
-
7156
7145
VERIFY_PERMISSION (OPT_P_SHAPER );
7157
- shaper = atoi_warn (p [1 ], msglevel );
7158
- if (shaper < SHAPER_MIN || shaper > SHAPER_MAX )
7146
+ if (!atoi_constrained (p [1 ], & options -> shaper , p [0 ], SHAPER_MIN , SHAPER_MAX , msglevel ))
7159
7147
{
7160
- msg (msglevel , "Bad shaper value, must be between %d and %d" , SHAPER_MIN , SHAPER_MAX );
7161
7148
goto err ;
7162
7149
}
7163
- options -> shaper = shaper ;
7164
7150
}
7165
7151
else if (streq (p [0 ], "port ") && p [1 ] && !p [2 ])
7166
7152
{
@@ -7739,7 +7725,11 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
7739
7725
else if (streq (p [0 ], "script - security ") && p [1 ] && !p [2 ])
7740
7726
{
7741
7727
VERIFY_PERMISSION (OPT_P_GENERAL );
7742
- script_security_set (atoi_warn (p [1 ], msglevel ));
7728
+ int security ;
7729
+ if (atoi_constrained (p [1 ], & security , p [0 ], SSEC_NONE , SSEC_PW_ENV , msglevel ))
7730
+ {
7731
+ script_security_set (security );
7732
+ }
7743
7733
}
7744
7734
else if (streq (p [0 ], "mssfix ") && !p [3 ])
7745
7735
{
@@ -7959,11 +7949,9 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
7959
7949
int real , virtual ;
7960
7950
7961
7951
VERIFY_PERMISSION (OPT_P_GENERAL );
7962
- real = atoi_warn (p [1 ], msglevel );
7963
- virtual = atoi_warn (p [2 ], msglevel );
7964
- if (real < 1 || virtual < 1 )
7952
+ if (!atoi_constrained (p [1 ], & real , "hash-size real" , 1 , INT_MAX , msglevel )
7953
+ || !atoi_constrained (p [2 ], & virtual , "hash-size virtual" , 1 , INT_MAX , msglevel ))
7965
7954
{
7966
- msg (msglevel , "--hash-size sizes must be >= 1 (preferably a power of 2)" );
7967
7955
goto err ;
7968
7956
}
7969
7957
options -> real_hash_size = real ;
@@ -7974,49 +7962,34 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
7974
7962
int cf_max , cf_per ;
7975
7963
7976
7964
VERIFY_PERMISSION (OPT_P_GENERAL );
7977
- cf_max = atoi_warn (p [1 ], msglevel );
7978
- cf_per = atoi_warn (p [2 ], msglevel );
7979
- if (cf_max < 0 || cf_per < 0 )
7965
+ if (!atoi_constrained (p [1 ], & cf_max , "connect-freq n" , 1 , INT_MAX , msglevel )
7966
+ || !atoi_constrained (p [2 ], & cf_per , "connect-freq seconds" , 1 , INT_MAX , msglevel ))
7980
7967
{
7981
- msg (msglevel , "--connect-freq parms must be > 0" );
7982
7968
goto err ;
7983
7969
}
7984
7970
options -> cf_max = cf_max ;
7985
7971
options -> cf_per = cf_per ;
7986
7972
}
7987
7973
else if (streq (p [0 ], "connect-freq-initial" ) && p [1 ] && p [2 ] && !p [3 ])
7988
7974
{
7989
- long cf_max , cf_per ;
7975
+ int cf_max , cf_per ;
7990
7976
7991
7977
VERIFY_PERMISSION (OPT_P_GENERAL );
7992
- char * e1 , * e2 ;
7993
- cf_max = strtol (p [1 ], & e1 , 10 );
7994
- cf_per = strtol (p [2 ], & e2 , 10 );
7995
- if (cf_max < 0 || cf_per < 0 || * e1 != '\0' || * e2 != '\0' )
7978
+ if (!atoi_constrained (p [1 ], & cf_max , "connect-freq-initial n" , 1 , INT_MAX , msglevel )
7979
+ || !atoi_constrained (p [2 ], & cf_per , "connect-freq-initial seconds" , 1 , INT_MAX , msglevel ))
7996
7980
{
7997
- msg (msglevel , "--connect-freq-initial parameters must be integers and >= 0" );
7998
7981
goto err ;
7999
7982
}
8000
7983
options -> cf_initial_max = cf_max ;
8001
7984
options -> cf_initial_per = cf_per ;
8002
7985
}
8003
7986
else if (streq (p [0 ], "max - clients ") && p [1 ] && !p [2 ])
8004
7987
{
8005
- int max_clients ;
8006
-
8007
7988
VERIFY_PERMISSION (OPT_P_GENERAL );
8008
- max_clients = atoi_warn (p [1 ], msglevel );
8009
- if (max_clients < 0 )
7989
+ if (!atoi_constrained (p [1 ], & options -> max_clients , p [0 ], 1 , MAX_PEER_ID , msglevel ))
8010
7990
{
8011
- msg (msglevel , "--max-clients must be at least 1" );
8012
7991
goto err ;
8013
7992
}
8014
- if (max_clients >= MAX_PEER_ID ) /* max peer-id value */
8015
- {
8016
- msg (msglevel , "--max-clients must be less than %d" , MAX_PEER_ID );
8017
- goto err ;
8018
- }
8019
- options -> max_clients = max_clients ;
8020
7993
}
8021
7994
else if (streq (p [0 ], "max-routes-per-client" ) && p [1 ] && !p [2 ])
8022
7995
{
@@ -8188,27 +8161,13 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8188
8161
}
8189
8162
else if (streq (p [0 ], "bcast - buffers ") && p [1 ] && !p [2 ])
8190
8163
{
8191
- int n_bcast_buf ;
8192
-
8193
8164
VERIFY_PERMISSION (OPT_P_GENERAL );
8194
- n_bcast_buf = atoi_warn (p [1 ], msglevel );
8195
- if (n_bcast_buf < 1 )
8196
- {
8197
- msg (msglevel , "--bcast-buffers parameter must be > 0" );
8198
- }
8199
- options -> n_bcast_buf = n_bcast_buf ;
8165
+ atoi_constrained (p [1 ], & options -> n_bcast_buf , p [0 ], 1 , INT_MAX , msglevel );
8200
8166
}
8201
8167
else if (streq (p [0 ], "tcp - queue - limit ") && p [1 ] && !p [2 ])
8202
8168
{
8203
- int tcp_queue_limit ;
8204
-
8205
8169
VERIFY_PERMISSION (OPT_P_GENERAL );
8206
- tcp_queue_limit = atoi_warn (p [1 ], msglevel );
8207
- if (tcp_queue_limit < 1 )
8208
- {
8209
- msg (msglevel , "--tcp-queue-limit parameter must be > 0" );
8210
- }
8211
- options -> tcp_queue_limit = tcp_queue_limit ;
8170
+ atoi_constrained (p [1 ], & options -> tcp_queue_limit , p [0 ], 1 , INT_MAX , msglevel );
8212
8171
}
8213
8172
#if PORT_SHARE
8214
8173
else if (streq (p [0 ], "port - share ") && p[1] && p[2] && !p[4])
@@ -8354,21 +8313,24 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8354
8313
int ageing_time , check_interval ;
8355
8314
8356
8315
VERIFY_PERMISSION (OPT_P_GENERAL );
8357
- ageing_time = atoi_warn (p [1 ], msglevel );
8316
+ if (!atoi_constrained (p [1 ], & ageing_time , "stale-routes-check age" , 1 , INT_MAX , msglevel ))
8317
+ {
8318
+ goto err ;
8319
+ }
8320
+
8358
8321
if (p [2 ])
8359
8322
{
8360
- check_interval = atoi_warn (p [2 ], msglevel );
8323
+ if (!atoi_constrained (p [2 ], & check_interval ,
8324
+ "stale-routes-check interval" , 1 , INT_MAX , msglevel ))
8325
+ {
8326
+ goto err ;
8327
+ }
8361
8328
}
8362
8329
else
8363
8330
{
8364
8331
check_interval = ageing_time ;
8365
8332
}
8366
8333
8367
- if (ageing_time < 1 || check_interval < 1 )
8368
- {
8369
- msg (msglevel , "--stale-routes-check aging time and check interval must be >= 1" );
8370
- goto err ;
8371
- }
8372
8334
options -> stale_routes_ageing_time = ageing_time ;
8373
8335
options -> stale_routes_check_interval = check_interval ;
8374
8336
}
@@ -8386,7 +8348,7 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8386
8348
else if (streq (p [0 ], "push - continuation ") && p [1 ] && !p [2 ])
8387
8349
{
8388
8350
VERIFY_PERMISSION (OPT_P_PULL_MODE );
8389
- options -> push_continuation = atoi_warn ( p [ 1 ] , msglevel );
8351
+ atoi_constrained ( p [ 1 ], & options -> push_continuation , p [ 0 ], 0 , 2 , msglevel );
8390
8352
}
8391
8353
else if (streq (p [0 ], "auth - user - pass ") && !p [2 ])
8392
8354
{
@@ -8505,33 +8467,23 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8505
8467
{
8506
8468
if (!streq (p [2 ], "default" ))
8507
8469
{
8508
- int offset = atoi_warn ( p [ 2 ], msglevel ) ;
8470
+ int offset ;
8509
8471
8510
- if (!( offset > -256 && offset < 256 ))
8472
+ if (!atoi_constrained ( p [ 2 ], & offset , "ip-win32 offset" , -256 , 256 , msglevel ))
8511
8473
{
8512
- msg (msglevel ,
8513
- "--ip-win32 dynamic [offset] [lease-time]: offset (%d) must be > -256 and < 256" ,
8514
- offset );
8515
8474
goto err ;
8516
8475
}
8517
-
8518
8476
to -> dhcp_masq_custom_offset = true;
8519
8477
to -> dhcp_masq_offset = offset ;
8520
8478
}
8521
8479
8522
8480
if (p [3 ])
8523
8481
{
8524
- const int min_lease = 30 ;
8525
- int lease_time ;
8526
- lease_time = atoi_warn (p [3 ], msglevel );
8527
- if (lease_time < min_lease )
8482
+ if (!atoi_constrained (p [3 ], & to -> dhcp_lease_time ,
8483
+ "ip-win32 lease time" , 30 , INT_MAX , msglevel ))
8528
8484
{
8529
- msg (msglevel ,
8530
- "--ip-win32 dynamic [offset] [lease-time]: lease time parameter (%d) must be at least %d seconds" ,
8531
- lease_time , min_lease );
8532
8485
goto err ;
8533
8486
}
8534
- to -> dhcp_lease_time = lease_time ;
8535
8487
}
8536
8488
}
8537
8489
}
@@ -8629,8 +8581,7 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8629
8581
}
8630
8582
else if (streq (p [1 ], "NBT ") && p [2 ] && !p [3 ])
8631
8583
{
8632
- int t ;
8633
- t = atoi_warn (p [2 ], msglevel );
8584
+ int t = atoi_warn (p [2 ], msglevel );
8634
8585
if (!(t == 1 || t == 2 || t == 4 || t == 8 ))
8635
8586
{
8636
8587
msg (msglevel , "--dhcp-option NBT: parameter (%d) must be 1, 2, 4, or 8" , t );
@@ -8704,15 +8655,11 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
8704
8655
}
8705
8656
else if (streq (p [0 ], "tap - sleep ") && p [1 ] && !p [2 ])
8706
8657
{
8707
- int s ;
8708
8658
VERIFY_PERMISSION (OPT_P_DHCPDNS );
8709
- s = atoi_warn (p [1 ], msglevel );
8710
- if (s < 0 || s >= 256 )
8659
+ if (!atoi_constrained (p [1 ], & options -> tuntap_options .tap_sleep , p [0 ], 0 , 255 , msglevel ))
8711
8660
{
8712
- msg (msglevel , "--tap-sleep parameter must be between 0 and 255" );
8713
8661
goto err ;
8714
8662
}
8715
- options -> tuntap_options .tap_sleep = s ;
8716
8663
}
8717
8664
else if (streq (p [0 ], "dhcp - renew ") && !p [1 ])
8718
8665
{
@@ -9152,30 +9099,19 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
9152
9099
VERIFY_PERMISSION (OPT_P_GENERAL );
9153
9100
if (p [1 ])
9154
9101
{
9155
- int replay_window ;
9156
-
9157
- replay_window = atoi_warn (p [1 ], msglevel );
9158
- if (!(MIN_SEQ_BACKTRACK <= replay_window && replay_window <= MAX_SEQ_BACKTRACK ))
9102
+ if (!atoi_constrained (p [1 ], & options -> replay_window , "replay-window windows size" ,
9103
+ MIN_SEQ_BACKTRACK , MAX_SEQ_BACKTRACK , msglevel ))
9159
9104
{
9160
- msg (msglevel , "replay-window window size parameter (%d) must be between %d and %d" ,
9161
- replay_window , MIN_SEQ_BACKTRACK , MAX_SEQ_BACKTRACK );
9162
9105
goto err ;
9163
9106
}
9164
- options -> replay_window = replay_window ;
9165
9107
9166
9108
if (p [2 ])
9167
9109
{
9168
- int replay_time ;
9169
-
9170
- replay_time = atoi_warn (p [2 ], msglevel );
9171
- if (!(MIN_TIME_BACKTRACK <= replay_time && replay_time <= MAX_TIME_BACKTRACK ))
9110
+ if (!atoi_constrained (p [2 ], & options -> replay_time , "replay-window time window" ,
9111
+ MIN_TIME_BACKTRACK , MAX_TIME_BACKTRACK , msglevel ))
9172
9112
{
9173
- msg (msglevel ,
9174
- "replay-window time window parameter (%d) must be between %d and %d" ,
9175
- replay_time , MIN_TIME_BACKTRACK , MAX_TIME_BACKTRACK );
9176
9113
goto err ;
9177
9114
}
9178
- options -> replay_time = replay_time ;
9179
9115
}
9180
9116
}
9181
9117
else
@@ -9771,7 +9707,7 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
9771
9707
else if (!p [2 ])
9772
9708
{
9773
9709
char * endp = NULL ;
9774
- int i = strtol (provider , & endp , 10 );
9710
+ long i = strtol (provider , & endp , 10 );
9775
9711
9776
9712
if (* endp == 0 )
9777
9713
{
@@ -9842,7 +9778,7 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
9842
9778
else if (streq (p [0 ], "pkcs11 - pin - cache ") && p [1 ] && !p [2 ])
9843
9779
{
9844
9780
VERIFY_PERMISSION (OPT_P_GENERAL );
9845
- options -> pkcs11_pin_cache_period = atoi_warn (p [1 ], msglevel );
9781
+ options -> pkcs11_pin_cache_period = positive_atoi (p [1 ], msglevel );
9846
9782
}
9847
9783
else if (streq (p [0 ], "pkcs11 - id ") && p [1 ] && !p [2 ])
9848
9784
{
0 commit comments