CLASSERT (sizeof(ifr.ifr_name) >= IFNAMSIZ);
- strcpy(ifr.ifr_name, name);
+ if (strlen(name) > sizeof(ifr.ifr_name)-1)
+ return -E2BIG;
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
rc = libcfs_sock_ioctl(SIOCGIFFLAGS, (unsigned long)&ifr);
if (rc != 0) {
*up = 1;
- strcpy(ifr.ifr_name, name);
+ if (strlen(name) > sizeof(ifr.ifr_name)-1)
+ return -E2BIG;
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
ifr.ifr_addr.sa_family = AF_INET;
rc = libcfs_sock_ioctl(SIOCGIFADDR, (unsigned long)&ifr);
val = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
*ip = ntohl(val);
- strcpy(ifr.ifr_name, name);
+ if (strlen(name) > sizeof(ifr.ifr_name)-1)
+ return -E2BIG;
+ strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+
ifr.ifr_addr.sa_family = AF_INET;
rc = libcfs_sock_ioctl(SIOCGIFNETMASK, (unsigned long)&ifr);
line[0]='\0';
for ( i = 1 ; i < argc ; i++ ) {
- strcat(line, argv[i]);
+ if (strlen(argv[i]) > sizeof(line)-strlen(line)-1)
+ return -E2BIG;
+ strncat(line, argv[i], sizeof(line)-strlen(line)-1);
}
switch ( process(line, &next, top_level, &result, &prev) ) {
if (sched == NULL)
return -ENOMEM;
- strncpy(sched->ws_name, name, CFS_WS_NAME_LEN);
+ if (strlen(name) > sizeof(sched->ws_name)-1) {
+ LIBCFS_FREE(sched, sizeof(*sched));
+ return -E2BIG;
+ }
+ strncpy(sched->ws_name, name, sizeof(sched->ws_name));
+
sched->ws_cptab = cptab;
sched->ws_cpt = cpt;
grp_ndl_hash[LST_NODE_HASHSIZE]));
grp->grp_ref = 1;
- if (name != NULL)
- strcpy(grp->grp_name, name);
+ if (name != NULL) {
+ if (strlen(name) > sizeof(grp->grp_name)-1) {
+ LIBCFS_FREE(grp, offsetof(lstcon_group_t,
+ grp_ndl_hash[LST_NODE_HASHSIZE]));
+ return -E2BIG;
+ }
+ strncpy(grp->grp_name, name, sizeof(grp->grp_name));
+ }
CFS_INIT_LIST_HEAD(&grp->grp_link);
CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
return -ENOMEM;
}
- strcpy(bat->bat_name, name);
+ if (strlen(name) > sizeof(bat->bat_name)-1) {
+ LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
+ LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
+ LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
+ return -E2BIG;
+ }
+ strncpy(bat->bat_name, name, sizeof(bat->bat_name));
bat->bat_hdr.tsb_index = 0;
bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
console_session.ses_feats_updated = 0;
console_session.ses_timeout = (timeout <= 0) ?
LST_CONSOLE_TIMEOUT : timeout;
- strcpy(console_session.ses_name, name);
+
+ if (strlen(name) > sizeof(console_session.ses_name)-1)
+ return -E2BIG;
+ strncpy(console_session.ses_name, name,
+ sizeof(console_session.ses_name));
rc = lstcon_batch_add(LST_DEFAULT_BATCH);
if (rc != 0)
/* If we are dumping raw (which means no conversion step to ASCII)
* then dump directly to any supplied filename, otherwise this is
* just a temp file and we dump to the real file at convert time. */
- if (argc > 1 && raw)
- strcpy(filename, argv[1]);
- else
- sprintf(filename, "%s"CFS_TIME_T".%u",
- LIBCFS_DEBUG_FILE_PATH_DEFAULT, time(NULL), getpid());
+ if (argc > 1 && raw) {
+ if (strlen(argv[1]) > sizeof(filename)-1) {
+ fprintf(stderr, "File name too long: %s\n", argv[1]);
+ return 1;
+ }
+ strncpy(filename, argv[1], sizeof(filename));
+ } else {
+ if (snprintf(filename, sizeof(filename), "%s"CFS_TIME_T".%u",
+ LIBCFS_DEBUG_FILE_PATH_DEFAULT, time(NULL),
+ getpid()) >=
+ sizeof(filename)) {
+ fprintf(stderr, "File name too long\n");
+ return 1;
+ }
+ }
if (stat(filename, &st) == 0 && S_ISREG(st.st_mode))
unlink(filename);
OBD_ALLOC_PTR(mml);
if (!mml)
GOTO(out_close, rc = -ENOMEM);
- strcpy(mml->mml_marker.cm_comment, comment);
- strcpy(mml->mml_marker.cm_tgtname, devname);
+ if (strlcpy(mml->mml_marker.cm_comment, comment,
+ sizeof(mml->mml_marker.cm_comment)) >=
+ sizeof(mml->mml_marker.cm_comment))
+ GOTO(out_close, rc = -E2BIG);
+ if (strlcpy(mml->mml_marker.cm_tgtname, devname,
+ sizeof(mml->mml_marker.cm_tgtname)) >=
+ sizeof(mml->mml_marker.cm_tgtname))
+ GOTO(out_close, rc = -E2BIG);
/* Modify mostly means cancel */
mml->mml_marker.cm_flags = flags;
mml->mml_marker.cm_canceltime = flags ? cfs_time_current_sec() : 0;
if (desc == NULL)
GOTO(fail, rc = -ENOMEM);
- strncpy(desc->pd_name, conf->nc_name, NRS_POL_NAME_MAX);
+ if (strlcpy(desc->pd_name, conf->nc_name, sizeof(desc->pd_name)) >=
+ sizeof(desc->pd_name)) {
+ OBD_FREE_PTR(desc);
+ GOTO(fail, rc = -E2BIG);
+ }
desc->pd_ops = conf->nc_ops;
desc->pd_compat = conf->nc_compat;
desc->pd_compat_svc_name = conf->nc_compat_svc_name;
if (conf == NULL)
return NULL;
- strcpy(conf->sc_fsname, fsname);
+ if (strlcpy(conf->sc_fsname, fsname, sizeof(conf->sc_fsname)) >=
+ sizeof(conf->sc_fsname)) {
+ OBD_FREE_PTR(conf);
+ return NULL;
+ }
sptlrpc_rule_set_init(&conf->sc_rset);
CFS_INIT_LIST_HEAD(&conf->sc_tgts);
cfs_list_add(&conf->sc_list, &sptlrpc_confs);
}
/* search for file directory pathname */
- strcpy(parent, name);
+ if (strlen(name) > sizeof(parent)-1) {
+ rc = -E2BIG;
+ goto free;
+ }
+ strncpy(parent, name, sizeof(parent));
ptr = strrchr(parent, '/');
if (ptr == NULL) {
if (getcwd(parent, sizeof(parent)) == NULL) {
param.obduuid = tmp;
}
for (token = buf; token && *token; token = next) {
- char *uuid;
- if (c == 'm')
- uuid =
- param.mdtuuid[param.num_mdts++].uuid;
- else
- uuid =
- param.obduuid[param.num_obds++].uuid;
+ struct obd_uuid *puuid;
+ if (c == 'm') {
+ puuid =
+ ¶m.mdtuuid[param.num_mdts++];
+ } else {
+ puuid =
+ ¶m.obduuid[param.num_obds++];
+ }
p = strchr(token, ',');
next = 0;
if (p) {
*p = 0;
next = p+1;
}
- strcpy((char *)uuid, token);
+ if (strlen(token) > sizeof(puuid->uuid)-1)
+ GOTO(err_free, ret = -E2BIG);
+ strncpy(puuid->uuid, token,
+ sizeof(puuid->uuid));
}
err_free:
if (buf)
hur->hur_request.hr_flags = 0;
/* All remaining args are files, add them */
- if (nbfile != 0)
- strcpy(some_file, argv[optind]);
+ if (nbfile != 0) {
+ if (strlen(argv[optind]) > sizeof(some_file)-1) {
+ free(hur);
+ return -E2BIG;
+ }
+ strncpy(some_file, argv[optind], sizeof(some_file));
+ }
for (i = 0; i < nbfile; i++) {
hur->hur_user_item[i].hui_extent.length = -1;
return rc;
}
} else if (fsname) {
- strcpy(fs, fsname);
+ if (strlen(fsname) > sizeof(fs)-1) {
+ if (fp != NULL)
+ fclose(fp);
+ return -E2BIG;
+ }
+ strncpy(fs, fsname, sizeof(fs));
}
if (fp == NULL) {
tmp += strlen(obd_type) + 1;
if (strcmp(tmp, fs))
continue;
- strcpy(dev, tmp);
+ if (strlen(tmp) > sizeof(dev)-1) {
+ fclose(fp);
+ return -E2BIG;
+ }
+ strncpy(dev, tmp, sizeof(dev));
tmp = strchr(dev, ' ');
if (tmp != NULL)
*tmp = '\0';
" a Lustre filesystem", name);
return rc;
}
- strcpy(fsname, rname);
+ if (strlen(rname) > sizeof(fsname)-1)
+ return -E2BIG;
+ strncpy(fsname, rname, sizeof(fsname));
} else {
/* name is FSNAME */
- strcpy(fsname, name);
+ if (strlen(name) > sizeof(fsname)-1)
+ return -E2BIG;
+ strncpy(fsname, name, sizeof(fsname));
rc = poolpath(fsname, NULL, pathname);
}
if (rc != 0) {
#include <signal.h>
#include <string.h>
#include <stdlib.h>
-
+#include <errno.h>
#define TRACK_BY_GID 0
#define TRACK_BY_PPID 1
#define LEN_CLIENT 1024
/* size of output of llstat command we read at a time */
-#define MAX 1024
-
-/* max strlen of outfile we get on command line */
-#define LEN_OUT 1024
+#define LLSTAT_READ_SIZE 1024
/* Length of command given on command line */
#define COMM_LEN 4096
-pid_t llstat[1024];
/* print usage */
void print_usage()
pid_t fork_llstat_command(char* llstat_file,char* stats_path)
{
- char truncate_command[100];
- char llstat_command[LEN_LLSTAT];
- pid_t pid_llstat_command;
- FILE *fp_popen, *fp_out;
- char buffer[MAX];
- int ret;
+ char truncate_command[100];
+ char llstat_command[LEN_LLSTAT];
+ pid_t pid_llstat_command;
+ FILE *fp_popen, *fp_out;
+ char buffer[LLSTAT_READ_SIZE];
+ int ret;
/* Truncating llstat output file as it will be opened in while
* loop to append output */
"\"%s\"n", llstat_command);
exit(1);
}
- while (fgets(buffer, 1024, fp_popen) != NULL) {
- /* Following code should be in while loop as llstat
- * will keep on sending output each second and will
- * not exit on itself. It will be killed when we finsh
- * with our command so we must make the output file
- * consistent after writing each 1024 bytes chunk */
-
- /* opening file where llstat will write its output */
- fp_out = fopen(llstat_file, "a");
- if (!fp_out) {
- fprintf(stderr, "Error: Couldn't open llstat"
- "outfile file: %s\n",
- llstat_file);
- exit(1);
- }
- /* fgets reads the popen output and fprintf writes it to
- * output file */
-
- if (fputs(buffer, fp_out) == EOF) {
- fprintf(stderr, "Error: Couldn't write output"
- "of llstat to out file\n");
- exit(1);
- }
-
- /* closing file opened for storing llstat's output */
- if (fclose(fp_out)) {
- fprintf(stderr, "Error: Couldn't close llstat"
- "outfile: %s\n", llstat_file);
- exit(1);
- }
- }
+ while (fgets(buffer, LLSTAT_READ_SIZE, fp_popen) != NULL) {
+ /* Following code should be in while loop as llstat
+ * will keep on sending output each second and will
+ * not exit on itself. It will be killed when we finsh
+ * with our command so we must make the output file
+ * consistent after writing each 1024 bytes chunk */
+
+ /* opening file where llstat will write its output */
+ fp_out = fopen(llstat_file, "a");
+ if (!fp_out) {
+ fprintf(stderr, "Error: Couldn't open llstat"
+ "outfile file: %s\n",
+ llstat_file);
+ exit(1);
+ }
+ /* fgets reads the popen output and fprintf writes it to
+ * output file */
+
+ if (fputs(buffer, fp_out) == EOF) {
+ fprintf(stderr, "Error: Couldn't write output"
+ "of llstat to out file\n");
+ exit(1);
+ }
+
+ /* closing file opened for storing llstat's output */
+ if (fclose(fp_out)) {
+ fprintf(stderr, "Error: Couldn't close llstat"
+ "outfile: %s\n", llstat_file);
+ exit(1);
+ }
+ }
/* closing popen for llstat */
if (pclose(fp_popen) < 0) {
fprintf(stderr, "Error: Couldn't pclos"
while ((c = getopt(argc, argv, "l:g:c:i:a:h")) != 1)
switch (c) {
case 'l':
- strcpy(llstat_file, optarg);
- if (strlen(llstat_file) > LEN_OUT) {
+ if (strlen(optarg) > sizeof(llstat_file)-1) {
fprintf(stderr, "length of outfile file"
" is too long\n");
exit(1);
- }
+ }
+ strncpy(llstat_file, optarg,
+ sizeof(llstat_file));
break;
/* When any value is written to vfs_track_gid, then VFS
* write_track_xid writes given <gid> in vfs_track_gid
* here. */
case 'g':
- strcpy(gid_string, optarg);
+ if (strlen(optarg) > sizeof(gid_string)-1)
+ return -E2BIG;
+ strncpy(gid_string, optarg, sizeof(gid_string));
get_command_from_argv(optind, argc, argv, "",
command);
gid = atoi(gid_string);
/* As listparam_display is used to show param name (with type),
* here "if (only_path)" is ignored.*/
if (popt->po_show_path) {
- strcpy(filename, glob_info.gl_pathv[i]);
+ if (strlen(glob_info.gl_pathv[i]) >
+ sizeof(filename)-1) {
+ free(buf);
+ return -E2BIG;
+ }
+ strncpy(filename, glob_info.gl_pathv[i],
+ sizeof(filename));
valuename = display_name(filename, 0);
}
char *valuename = NULL;
if (popt->po_show_path) {
- strcpy(filename, glob_info.gl_pathv[i]);
+ if (strlen(glob_info.gl_pathv[i]) > sizeof(filename)-1)
+ return -E2BIG;
+ strncpy(filename, glob_info.gl_pathv[i],
+ sizeof(filename));
valuename = display_name(filename, 0);
if (valuename)
printf("%s=%s\n", valuename, value);
p = calloc(1, sizeof(*p));
if (!p)
return -ENOMEM;
- strcpy(p->pc_log.pcl_pfid, pfid);
- strcpy(p->pc_log.pcl_tfid, tfid);
- strcpy(p->pc_log.pcl_name, name);
+ if (strlen(pfid) > sizeof(p->pc_log.pcl_pfid)-1)
+ goto out_err;
+ strncpy(p->pc_log.pcl_pfid, pfid, sizeof(p->pc_log.pcl_pfid));
+ if (strlen(tfid) > sizeof(p->pc_log.pcl_tfid)-1)
+ goto out_err;
+ strncpy(p->pc_log.pcl_tfid, tfid, sizeof(p->pc_log.pcl_tfid));
+ if (strlen(name) > sizeof(p->pc_log.pcl_name)-1)
+ goto out_err;
+ strncpy(p->pc_log.pcl_name, name, sizeof(p->pc_log.pcl_name));
p->pc_next = parents;
parents = p;
return 0;
+
+out_err:
+ free(p);
+ return -E2BIG;
}
void lr_cascade_move(const char *fid, const char *dest, struct lr_info *info)
memset(&mkop, 0, sizeof(mkop));
mkop.mo_ldd = *ldd;
mkop.mo_ldd.ldd_flags &= ~LDD_F_UPDATE;
- strcpy(mkop.mo_device, source);
+ if (strlen(source) > sizeof(mkop.mo_device)-1) {
+ fatal();
+ fprintf(stderr, "Device name too long: %s\n", source);
+ return -E2BIG;
+ }
+ strncpy(mkop.mo_device, source, sizeof(mkop.mo_device));
ret = osd_prepare_lustre(&mkop,
default_mountopts, sizeof(default_mountopts),
return NULL;
}
strcat(buf, "/");
- strcat(buf, devname);
+ if (strlen(devname) > sizeof(buf)-strlen(buf)-1) {
+ free(path);
+ return NULL;
+ }
+ strncat(buf, devname, sizeof(buf)-strlen(buf)-1);
} else {
- strcpy(buf, devname);
+ if (strlen(devname) > sizeof(buf)-1) {
+ free(path);
+ return NULL;
+ }
+ strncpy(buf, devname, sizeof(buf));
}
/* truncate filename before calling realpath */
ptr = strrchr(buf, '/');
ostname, fsname);
return -EINVAL;
} else {
- strcpy(real_ostname, ostname);
+ if (strlen(ostname) > sizeof(real_ostname)-1)
+ return -E2BIG;
+ strncpy(real_ostname, ostname, sizeof(real_ostname));
}
/* real_ostname is fsname-????? */
ptr = real_ostname + strlen(fsname) + 1;
}
obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
- if (data.ioc_u32_1 == 0) {
- fprintf(stderr, "received invalid userid!\n");
- return EPROTO;
- }
+ if (data.ioc_u32_1 == 0) {
+ fprintf(stderr, "received invalid userid!\n");
+ return -EPROTO;
+ }
- if (lcfg_get_devname() != NULL)
- strcpy(devname, lcfg_get_devname());
- else
- sprintf(devname, "dev %d", cur_device);
+ if (lcfg_get_devname() != NULL) {
+ if (strlen(lcfg_get_devname()) > sizeof(devname)-1) {
+ fprintf(stderr, "Dev name too long\n");
+ return -E2BIG;
+ }
+ strncpy(devname, lcfg_get_devname(), sizeof(devname));
+ } else {
+ if (snprintf(devname, sizeof(devname), "dev %d", cur_device) >=
+ sizeof(devname)) {
+ fprintf(stderr, "Dev name too long\n");
+ return -E2BIG;
+ }
+ }
if (argc == 2)
/* -n means bare name */
}
obd_ioctl_unpack(&data, buf, sizeof(rawbuf));
- if (data.ioc_u32_1 != id) {
- fprintf(stderr, "No changelog user '%s'. Blocking user"
- " is '"CHANGELOG_USER_PREFIX"%d'.\n", argv[1],
- data.ioc_u32_1);
- return ENOENT;
- }
+ if (data.ioc_u32_1 != id) {
+ fprintf(stderr, "No changelog user '%s'. Blocking user"
+ " is '"CHANGELOG_USER_PREFIX"%d'.\n", argv[1],
+ data.ioc_u32_1);
+ return -ENOENT;
+ }
- if (lcfg_get_devname() != NULL)
- strcpy(devname, lcfg_get_devname());
- else
- sprintf(devname, "dev %d", cur_device);
+ if (lcfg_get_devname() != NULL) {
+ if (strlen(lcfg_get_devname()) > sizeof(devname)-1) {
+ fprintf(stderr, "Dev name too long\n");
+ return -E2BIG;
+ }
+ strncpy(devname, lcfg_get_devname(), sizeof(devname));
+ } else {
+ if (snprintf(devname, sizeof(devname), "dev %d", cur_device) >=
+ sizeof(devname)) {
+ fprintf(stderr, "Dev name too long\n");
+ return -E2BIG;
+ }
+ }
printf("%s: Deregistered changelog user '"CHANGELOG_USER_PREFIX"%d'\n",
devname, data.ioc_u32_1);