Whamcloud - gitweb
git://git.whamcloud.com
/
fs
/
lustre-release.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
LU-5458: libcfs: protect kkuc_groups from write access
[fs/lustre-release.git]
/
lustre
/
utils
/
liblustreapi_json.c
diff --git
a/lustre/utils/liblustreapi_json.c
b/lustre/utils/liblustreapi_json.c
index
be9a1e8
..
10e8e76
100644
(file)
--- a/
lustre/utils/liblustreapi_json.c
+++ b/
lustre/utils/liblustreapi_json.c
@@
-41,7
+41,7
@@
#include <unistd.h>
#endif
#include <unistd.h>
#endif
-#include <lib
lustre
.h>
+#include <lib
cfs/libcfs
.h>
#include <lustre/lustreapi.h>
/** Quick-n'-dirty JSON string escape routine.
#include <lustre/lustreapi.h>
/** Quick-n'-dirty JSON string escape routine.
@@
-124,8
+124,7
@@
int llapi_json_write_list(struct llapi_json_item_list **json_items, FILE *fp)
list = *json_items;
item = list->ljil_items;
list = *json_items;
item = list->ljil_items;
- if (fprintf(fp, "{") < 0)
- return -errno;
+ fprintf(fp, "{");
for (i = 0; i < list->ljil_item_count; i++) {
if (item == NULL) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
for (i = 0; i < list->ljil_item_count; i++) {
if (item == NULL) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
@@
-136,34
+135,26
@@
int llapi_json_write_list(struct llapi_json_item_list **json_items, FILE *fp)
break;
}
break;
}
- if (fprintf(fp, "\"%s\": ", item->lji_key) < 0)
- return -errno;
+ fprintf(fp, "\"%s\": ", item->lji_key);
switch (item->lji_type) {
case LLAPI_JSON_INTEGER:
switch (item->lji_type) {
case LLAPI_JSON_INTEGER:
- if (fprintf(fp, "%d", item->lji_integer) < 0)
- return -errno;
+ fprintf(fp, "%d", item->lji_integer);
break;
case LLAPI_JSON_BIGNUM:
break;
case LLAPI_JSON_BIGNUM:
- if (fprintf(fp, LPU64, item->lji_u64) < 0)
- return -errno;
+ fprintf(fp, LPU64, item->lji_u64);
break;
case LLAPI_JSON_REAL:
break;
case LLAPI_JSON_REAL:
- if (fprintf(fp, "%f", item->lji_real) < 0)
- return -errno;
+ fprintf(fp, "%f", item->lji_real);
break;
case LLAPI_JSON_STRING:
if (llapi_json_escape_string(&escaped_string,
break;
case LLAPI_JSON_STRING:
if (llapi_json_escape_string(&escaped_string,
-
item->lji_string) < 0) {
+ item->lji_string) < 0) {
if (escaped_string != NULL)
free(escaped_string);
return -errno;
}
if (escaped_string != NULL)
free(escaped_string);
return -errno;
}
- if (fprintf(fp, "\"%s\"", escaped_string) < 0) {
- if (escaped_string != NULL)
- free(escaped_string);
- return -errno;
- }
+ fprintf(fp, "\"%s\"", escaped_string);
if (escaped_string != NULL)
free(escaped_string);
if (escaped_string != NULL)
free(escaped_string);
@@
-172,19
+163,16
@@
int llapi_json_write_list(struct llapi_json_item_list **json_items, FILE *fp)
llapi_err_noerrno(LLAPI_MSG_ERROR,
"Invalid item type: %d", item->lji_type);
/* Ensure valid JSON */
llapi_err_noerrno(LLAPI_MSG_ERROR,
"Invalid item type: %d", item->lji_type);
/* Ensure valid JSON */
- if (fprintf(fp, "\"\"") < 0)
- return -errno;
+ fprintf(fp, "\"\"");
break;
}
if (i < list->ljil_item_count - 1)
break;
}
if (i < list->ljil_item_count - 1)
- if (fprintf(fp, ", ") < 0)
- return -errno;
+ fprintf(fp, ", ");
item = item->lji_next;
}
item = item->lji_next;
}
- if (fprintf(fp, "}\n") < 0)
- return -errno;
+ fprintf(fp, "}\n");
return 0;
}
return 0;
}
@@
-269,6
+257,7
@@
int llapi_json_add_item(struct llapi_json_item_list **json_items,
{
struct llapi_json_item_list *list;
struct llapi_json_item *new_item;
{
struct llapi_json_item_list *list;
struct llapi_json_item *new_item;
+ size_t len;
if (json_items == NULL || *json_items == NULL)
return -EINVAL;
if (json_items == NULL || *json_items == NULL)
return -EINVAL;
@@
-282,11
+271,12
@@
int llapi_json_add_item(struct llapi_json_item_list **json_items,
if (new_item == NULL)
return -ENOMEM;
if (new_item == NULL)
return -ENOMEM;
- new_item->lji_key = calloc(1, strlen(key) + 1);
+ len = strlen(key) + 1;
+ new_item->lji_key = calloc(len, sizeof(char));
if (new_item->lji_key == NULL)
return -ENOMEM;
if (new_item->lji_key == NULL)
return -ENOMEM;
- str
ncpy(new_item->lji_key, key, strlen(key)
);
+ str
lcpy(new_item->lji_key, key, len
);
new_item->lji_type = type;
new_item->lji_next = NULL;
new_item->lji_type = type;
new_item->lji_next = NULL;
@@
-301,11
+291,11
@@
int llapi_json_add_item(struct llapi_json_item_list **json_items,
new_item->lji_real = *(double *)val;
break;
case LLAPI_JSON_STRING:
new_item->lji_real = *(double *)val;
break;
case LLAPI_JSON_STRING:
- new_item->lji_string = calloc(1, strlen((char *)val) + 1);
+ len = strlen((char *)val) + 1;
+ new_item->lji_string = calloc(len, sizeof(char));
if (new_item->lji_string == NULL)
return -ENOMEM;
if (new_item->lji_string == NULL)
return -ENOMEM;
- strncpy(new_item->lji_string,
- (char *)val, strlen((char *)val));
+ strlcpy(new_item->lji_string, (char *)val, len);
break;
default:
llapi_err_noerrno(LLAPI_MSG_ERROR, "Unknown JSON type: %d",
break;
default:
llapi_err_noerrno(LLAPI_MSG_ERROR, "Unknown JSON type: %d",