X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Futils%2Fl_getidentity.c;h=9f357a453c4b6cf5082dab092225f165ca8296e4;hb=dd2a3f8fa0e95c707121855c6d5acf01b2e1c855;hp=3729f3fffcb3143ae82512f3e4c20595ed941ca7;hpb=41998544b8a34b3c385f2a6adb7ebc01ba496182;p=fs%2Flustre-release.git diff --git a/lustre/utils/l_getidentity.c b/lustre/utils/l_getidentity.c index 3729f3f..9f357a4 100644 --- a/lustre/utils/l_getidentity.c +++ b/lustre/utils/l_getidentity.c @@ -27,7 +27,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Intel Corporation. + * Copyright (c) 2011, 2014, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -48,7 +48,9 @@ #include #include -#include +#include +#include +#include #include #include @@ -128,8 +130,7 @@ int get_groups_local(struct identity_downcall_data *data, return -1; } - memset(pw_name, 0, namelen); - strncpy(pw_name, pw->pw_name, namelen - 1); + strlcpy(pw_name, pw->pw_name, namelen); groups = data->idd_groups; /* Allocate array of size maxgroups instead of handling two @@ -225,13 +226,18 @@ int parse_perm(__u32 *perm, __u32 *noperm, char *str) *noperm = 0; start = str; while (1) { - memset(name, 0, sizeof(name)); - end = strchr(start, ','); - if (!end) - end = str + strlen(str); - if (start >= end) - break; - strncpy(name, start, end - start); + size_t len; + memset(name, 0, sizeof(name)); + end = strchr(start, ','); + if (end == NULL) + end = str + strlen(str); + if (start >= end) + break; + len = end - start; + if (len >= sizeof(name)) + return -E2BIG; + strncpy(name, start, len); + name[len] = '\0'; for (pt = perm_types; pt->name; pt++) { if (!strcasecmp(name, pt->name)) { *perm |= pt->bit; @@ -258,9 +264,12 @@ int parse_perm(__u32 *perm, __u32 *noperm, char *str) return 0; } -int parse_perm_line(struct identity_downcall_data *data, char *line) +static int +parse_perm_line(struct identity_downcall_data *data, char *line, size_t size) { - char uid_str[256], nid_str[256], perm_str[256]; + char uid_str[size]; + char nid_str[size]; + char perm_str[size]; lnet_nid_t nid; __u32 perm, noperm; int rc, i; @@ -271,7 +280,7 @@ int parse_perm_line(struct identity_downcall_data *data, char *line) return -1; } - rc = sscanf(line, "%s %s %s", nid_str, uid_str, perm_str); + rc = sscanf(line, "%s %s %s", nid_str, uid_str, perm_str); if (rc != 3) { errlog("can't parse line %s\n", line); return -1; @@ -351,8 +360,8 @@ int parse_perm_line(struct identity_downcall_data *data, char *line) int get_perms(struct identity_downcall_data *data) { - FILE *fp; - char line[1024]; + FILE *fp; + char line[PATH_MAX]; fp = fopen(PERM_PATHNAME, "r"); if (fp == NULL) { @@ -366,11 +375,11 @@ int get_perms(struct identity_downcall_data *data) } } - while (fgets(line, 1024, fp)) { + while (fgets(line, sizeof(line), fp)) { if (comment_line(line)) continue; - if (parse_perm_line(data, line)) { + if (parse_perm_line(data, line, sizeof(line))) { errlog("parse line %s failed!\n", line); data->idd_err = EINVAL; fclose(fp);