argument checking in rig_set_conf, patch from Zhang Bo + edit

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2593 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.9
Stéphane Fillod, F8CFE 2009-01-25 14:25:46 +00:00
rodzic 48ea7c9263
commit 03cc4f3787
1 zmienionych plików z 150 dodań i 128 usunięć

Wyświetl plik

@ -7,13 +7,13 @@
* \file src/conf.c * \file src/conf.c
* \brief Rig configuration interface * \brief Rig configuration interface
* \author Stephane Fillod * \author Stephane Fillod
* \date 2000-2006 * \date 2000-2009
*/ */
/* /*
* Hamlib Interface - configuration interface * Hamlib Interface - configuration interface
* Copyright (c) 2000-2006 by Stephane Fillod * Copyright (c) 2000-2009 by Stephane Fillod
* *
* $Id: conf.c,v 1.17 2008-05-08 12:40:04 fillods Exp $ * $Id: conf.c,v 1.18 2009-01-25 14:25:46 fillods Exp $
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -116,7 +116,6 @@ static const struct confparams frontend_cfg_params[] = {
/* /*
* frontend_set_conf * frontend_set_conf
* assumes rig!=NULL, val!=NULL * assumes rig!=NULL, val!=NULL
* TODO: check format of val before doing atoi().
*/ */
static int frontend_set_conf(RIG *rig, token_t token, const char *val) static int frontend_set_conf(RIG *rig, token_t token, const char *val)
{ {
@ -129,44 +128,65 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
switch(token) { switch(token) {
case TOK_PATHNAME: case TOK_PATHNAME:
strcpy(rs->rigport.pathname, val); strncpy(rs->rigport.pathname, val, FILPATHLEN-1);
break; break;
case TOK_WRITE_DELAY: case TOK_WRITE_DELAY:
rs->rigport.write_delay = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.write_delay = val_i;
break; break;
case TOK_POST_WRITE_DELAY: case TOK_POST_WRITE_DELAY:
rs->rigport.post_write_delay = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.post_write_delay = val_i;
break; break;
case TOK_TIMEOUT: case TOK_TIMEOUT:
rs->rigport.timeout = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.timeout = val_i;
break; break;
case TOK_RETRY: case TOK_RETRY:
rs->rigport.retry = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.retry = val_i;
break; break;
case TOK_SERIAL_SPEED: case TOK_SERIAL_SPEED:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL)
return -RIG_EINVAL; return -RIG_EINVAL;
rs->rigport.parm.serial.rate = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.parm.serial.rate = val_i;
break; break;
case TOK_DATA_BITS: case TOK_DATA_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL)
return -RIG_EINVAL; return -RIG_EINVAL;
rs->rigport.parm.serial.data_bits = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.parm.serial.data_bits = val_i;
break; break;
case TOK_STOP_BITS: case TOK_STOP_BITS:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL)
return -RIG_EINVAL; return -RIG_EINVAL;
rs->rigport.parm.serial.stop_bits = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
rs->rigport.parm.serial.stop_bits = val_i;
break; break;
case TOK_PARITY: case TOK_PARITY:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL)
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strncmp(val, "None", 8)) if (!strcmp(val, "None"))
rs->rigport.parm.serial.parity = RIG_PARITY_NONE; rs->rigport.parm.serial.parity = RIG_PARITY_NONE;
else if (!strncmp(val, "Odd", 8)) else if (!strcmp(val, "Odd"))
rs->rigport.parm.serial.parity = RIG_PARITY_ODD; rs->rigport.parm.serial.parity = RIG_PARITY_ODD;
else if (!strncmp(val, "Even", 8)) else if (!strcmp(val, "Even"))
rs->rigport.parm.serial.parity = RIG_PARITY_EVEN; rs->rigport.parm.serial.parity = RIG_PARITY_EVEN;
else else
return -RIG_EINVAL; return -RIG_EINVAL;
@ -174,11 +194,11 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
case TOK_HANDSHAKE: case TOK_HANDSHAKE:
if (rs->rigport.type.rig != RIG_PORT_SERIAL) if (rs->rigport.type.rig != RIG_PORT_SERIAL)
return -RIG_EINVAL; return -RIG_EINVAL;
if (!strncmp(val, "None", 8)) if (!strcmp(val, "None"))
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
else if (!strncmp(val, "XONXOFF", 8)) else if (!strcmp(val, "XONXOFF"))
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF;
else if (!strncmp(val, "Hardware", 8)) else if (!strcmp(val, "Hardware"))
rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; rs->rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE;
else else
return -RIG_EINVAL; return -RIG_EINVAL;
@ -211,7 +231,9 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val)
break; break;
case TOK_ITU_REGION: case TOK_ITU_REGION:
val_i = atoi(val); if (1 != sscanf(val, "%d", &val_i)){
return -RIG_EINVAL;//value format error
}
switch(val_i) { switch(val_i) {
case RIG_ITU_REGION1: case RIG_ITU_REGION1:
rs->itu_region = val_i; rs->itu_region = val_i;