mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Fix snprintf destination buffer sizes
Fixes snprintf truncated output compiler warnings.
Example:
--
../dmentrylibrary.c:31:38: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
31 | snprintf(buf, sizeof(buf), "%s/%s", folder_path, entry->d_name);
| ^
../dmentrylibrary.c:31:5: note: ‘snprintf’ output 2 or more bytes (assuming 257) into a destination of size 256
31 | snprintf(buf, sizeof(buf), "%s/%s", folder_path, entry->d_name);
--
Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
This commit is contained in:
parent
a377f7dfd2
commit
521e38a853
7 changed files with 22 additions and 20 deletions
|
|
@ -20,7 +20,7 @@ static int get_stats_json_folder(char *folder_path, int *file_count, unsigned lo
|
|||
struct stat stats;
|
||||
struct dirent *entry;
|
||||
DIR *dirp = NULL;
|
||||
char buf[256] = {0};
|
||||
char buf[264] = {0};
|
||||
int filecount = 0;
|
||||
unsigned long filesize = 0, filedate = 0;
|
||||
|
||||
|
|
@ -806,7 +806,7 @@ int load_json_dynamic_arrays(struct dmctx *ctx)
|
|||
if (strstr(ent->d_name, ".json")) {
|
||||
DMOBJ *dm_entryobj = NULL;
|
||||
json_object *json;
|
||||
char buf[32] = "";
|
||||
char buf[280] = "";
|
||||
snprintf(buf, sizeof(buf), "%s/%s", JSON_FOLDER_PATH, ent->d_name);
|
||||
json = json_object_from_file(buf);
|
||||
if (!json) continue;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ static int get_stats_library_folder(char *folder_path, int *file_count, unsigned
|
|||
struct stat stats;
|
||||
struct dirent *entry;
|
||||
DIR *dirp = NULL;
|
||||
char buf[256] = {0};
|
||||
char buf[264] = {0};
|
||||
int filecount = 0;
|
||||
unsigned long filesize = 0, filedate = 0;
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ int load_library_dynamic_arrays(struct dmctx *ctx)
|
|||
LIB_MAP_OBJ *root_dynamic_obj = NULL;
|
||||
LIB_MAP_OPERATE *root_dynamic_operate = NULL;
|
||||
DMOBJ *dm_entryobj = NULL;
|
||||
char buf[32] = "";
|
||||
char buf[280] = "";
|
||||
int i;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s/%s", LIBRARY_FOLDER_PATH, ent->d_name);
|
||||
|
|
|
|||
|
|
@ -322,7 +322,7 @@ static int get_vcf_date(char *refparam, struct dmctx *ctx, void *data, char *ins
|
|||
DIR *dir;
|
||||
struct dirent *d_file;
|
||||
struct stat attr;
|
||||
char path[128];
|
||||
char path[280];
|
||||
char date[sizeof "AAAA-MM-JJTHH:MM:SS.000Z"];
|
||||
|
||||
*value = "";
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ static int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ct
|
|||
static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
char line[256] = "", buf[1024] = "", buf_tmp[1024] = "", *pch = NULL, *spch = NULL;
|
||||
char line[256] = "", buf[1028] = "", buf_tmp[1024] = "", *pch = NULL, *spch = NULL;
|
||||
|
||||
*value = "";
|
||||
fp = fopen(DDNS_PROVIDERS_FILE, "r");
|
||||
|
|
|
|||
|
|
@ -933,7 +933,7 @@ static int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char
|
|||
|
||||
static int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
char buf[64], new[64], *pch, *destip;
|
||||
char buf[64], new[70], *pch, *destip;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
|
|
@ -978,7 +978,7 @@ static int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha
|
|||
|
||||
static int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
char buf[64], new[64], *pch, *srcip;
|
||||
char buf[64], new[70], *pch, *srcip;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
|
|
|
|||
|
|
@ -329,6 +329,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
|
|||
{
|
||||
struct uci_section *s = NULL, *stmp;
|
||||
char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8];
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
unsigned int ip[4], gw[4];
|
||||
unsigned int flags, refcnt, use, metric, prefix;
|
||||
char *iface, *str, *target, *name, *instance;
|
||||
|
|
@ -356,8 +357,8 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
|
|||
ip[1] = htonl(ip[1]);
|
||||
ip[2] = htonl(ip[2]);
|
||||
ip[3] = htonl(ip[3]);
|
||||
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, prefix);
|
||||
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
|
||||
if (strcmp(iface, dev) == 0 && strcmp(ipstr, target) == 0) {
|
||||
found = 1;
|
||||
break;
|
||||
|
|
@ -387,8 +388,8 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
|
|||
gw[1] = htonl(gw[1]);
|
||||
gw[2] = htonl(gw[2]);
|
||||
gw[3] = htonl(gw[3]);
|
||||
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, prefix);
|
||||
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
|
||||
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
|
||||
if (is_proc_route6_in_config(dev, ipstr, gwstr))
|
||||
continue;
|
||||
|
|
@ -926,6 +927,7 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam,
|
|||
{
|
||||
struct uci_section *s = NULL;
|
||||
char buf[512], dev[32], ipstr[INET6_ADDRSTRLEN + 8], gwstr[INET6_ADDRSTRLEN + 8];
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
unsigned int ip[4], gw[4], flags, refcnt, use, metric, prefix;
|
||||
char *source, *nexthop, *str, *iface = "";
|
||||
json_object *jobj;
|
||||
|
|
@ -952,8 +954,8 @@ static int get_RoutingRouteInformationInterfaceSetting_Interface(char *refparam,
|
|||
gw[1] = htonl(gw[1]);
|
||||
gw[2] = htonl(gw[2]);
|
||||
gw[3] = htonl(gw[3]);
|
||||
inet_ntop(AF_INET6, ip, buf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", buf, prefix);
|
||||
inet_ntop(AF_INET6, ip, ipbuf, INET6_ADDRSTRLEN);
|
||||
snprintf(ipstr, sizeof(ipstr), "%s/%u", ipbuf, prefix);
|
||||
inet_ntop(AF_INET6, gw, gwstr, INET6_ADDRSTRLEN);
|
||||
if((strcmp(source, ipstr) == 0) && (strcmp(nexthop, gwstr) == 0))
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
|
|||
list_for_each_entry(p, &dup_list, list) {
|
||||
char netfolderpath[256];
|
||||
char port_link[128];
|
||||
char iface_name[64];
|
||||
char iface_name[260];
|
||||
|
||||
port_link[0] = 0;
|
||||
iface_name[0] = 0;
|
||||
|
|
@ -245,14 +245,14 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
|
|||
continue;
|
||||
|
||||
if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) ==0) {
|
||||
char deviceClassFile[256];
|
||||
char deviceClassFile[270];
|
||||
char deviceClass[16];
|
||||
|
||||
snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", sysfsrep, ent->d_name);
|
||||
dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass));
|
||||
|
||||
if(strncmp(deviceClass, "09", 2) == 0){
|
||||
char hubpath[256];
|
||||
char hubpath[270];
|
||||
|
||||
snprintf(hubpath, sizeof(hubpath), "%s/%s", sysfsrep, ent->d_name);
|
||||
synchronize_usb_devices_with_dmmap_opt_recursively(hubpath, dmmap_package, dmmap_section, opt_name, inst_opt, 0, dup_list);
|
||||
|
|
@ -385,7 +385,7 @@ static int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, v
|
|||
{
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
char filename[128];
|
||||
char filename[276];
|
||||
char buffer[64];
|
||||
int nbre= 0;
|
||||
ssize_t rc;
|
||||
|
|
@ -823,14 +823,14 @@ static int get_number_devices(char *folderpath, int *nbre)
|
|||
|
||||
sysfs_foreach_file(folderpath, dir, ent) {
|
||||
if (regexec(®ex1, ent->d_name, 0, NULL, 0) == 0 || regexec(®ex2, ent->d_name, 0, NULL, 0) == 0) {
|
||||
char deviceClassFile[256];
|
||||
char deviceClassFile[270];
|
||||
char deviceClass[16];
|
||||
|
||||
snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", folderpath, ent->d_name);
|
||||
dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass));
|
||||
|
||||
if(strncmp(deviceClass, "09", 2) == 0){
|
||||
char hubpath[256];
|
||||
char hubpath[260];
|
||||
|
||||
snprintf(hubpath, sizeof(hubpath), "%s/%s", folderpath, ent->d_name);
|
||||
get_number_devices(hubpath, nbre);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue