1
1

Initial dump from Zyxel

This commit is contained in:
2026-04-17 17:00:52 +02:00
commit 81fec250f4
23116 changed files with 5231237 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$
include $(TOPDIR)/rules.mk
#These lines concatanate the package name and list the URL location from which the package source code is to be downloaded
PKG_NAME:=libzcmd_tool
PKG_VERSION:=1.0
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
#PKG_SOURCE_URL:=http://www.cs.uh.edu/~vivekian/downloads/
PKG_SOURCE_URL:=@ZyXEL_SITE/public/ZyXEL
DL_DIR:=$(TOPDIR)/dl/public/zyxel
PKG_CAT:=zcat
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
export CONFIG_ZYXEL_MEMORY_LEAK_DETECT
#These lines describe what your package does and its place in the menu config
PKG_BUILD_DEPENDS:=zcfg
define Package/libzcmd_tool
SECTION:=net
CATEGORY:=Zyxel Packages
TITLE:= ZyXEL Configuration Management Daemon Tool
DESCRIPTION:=
#DEPENDS:=zcfg +libjson +libzos
#DEPENDS:=zcfg
endef
define Package/libzcmd_tool/config
select PACKAGE_libjson if PACKAGE_zcfg
select PACKAGE_libzos if PACKAGE_zcfg
endef
#Disable Dependencies Check
define CheckDependencies
endef
#For the compile rules you need to specify the cross compiler which needs to be used :
#These lines describe where your binary images are to be installed ¡V its the equivalent to make install
# This particular package is a library and the installation rules reflect it
define Package/libzcmd_tool/compile
$(MAKE) -C $(PKG_BUILD_DIR)
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_BUILD_DIR)/*.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libzcmd_tool.so $(1)/usr/lib/
endef
define Package/libzcmd_tool/install
$(INSTALL_DIR) $(1)/lib
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME).so $(1)/lib
# $(INSTALL_DIR) $(1)/lib/public
# $(INSTALL_BIN) $(PKG_BUILD_DIR)/libzcmd_tool.so $(1)/lib/public
# ln -s /lib/public/libzcmd_tool.so $(1)/lib/libzcmd_tool.so
endef
$(eval $(call BuildPackage,libzcmd_tool))
@@ -0,0 +1,25 @@
Index: libzcmd_tool-1.0/Makefile
===================================================================
--- libzcmd_tool-1.0.orig/Makefile 2013-12-13 17:32:16.000000000 +0800
+++ libzcmd_tool-1.0/Makefile 2015-06-08 14:55:38.423241417 +0800
@@ -1,5 +1,4 @@
CURRENT_DIR = $(shell pwd)
-COMMON_ZCFG_INCLUDE_DIR = $(CURRENT_DIR)/../../../private/apps/zcfg/include
.PHONY : libzcmdtool
@@ -9,13 +8,8 @@
$(CC) -shared -o libzcmd_tool.so zcmd_tool.o
zcmd_tool.o : zcmd_tool.c
- $(CC) -c -fPIC zcmd_tool.c -Wall -L$(USRLIBDIR) -I$(TOOLCHAIN)/include -I. -I$(COMMON_ZCFG_INCLUDE_DIR) -ljson -std=gnu99
-
-install:
- install -m 755 libzcmd_tool.so $(INSTALL_DIR)/lib/public
- install -m 666 zcmd_tool.h $(COMMON_ZCFG_INCLUDE_DIR)
+ $(CC) -c -fPIC zcmd_tool.c -Wall -L$(USRLIBDIR) -I$(TOOLCHAIN)/include -I. -ljson -std=gnu99
clean:
rm -rf *.o
rm -rf *.so
- rm -rf $(COMMON_ZCFG_INCLUDE_DIR)/zcmd_tool.h
@@ -0,0 +1,29 @@
Index: libzcmd_tool-1.0/Makefile
===================================================================
--- libzcmd_tool-1.0.orig/Makefile
+++ libzcmd_tool-1.0/Makefile
@@ -1,14 +1,18 @@
+OBJS = zcmd_tool.o
CURRENT_DIR = $(shell pwd)
-.PHONY : libzcmdtool
+LDFLAGS += -L$(USRLIBDIR) -ljson
+CFLAGS += -I$(TOOLCHAIN)/include -I. -std=gnu99
-all: clean libzcmdtool
+.PHONY : libzcmd_tool
-libzcmdtool : zcmd_tool.o
- $(CC) -shared -o libzcmd_tool.so zcmd_tool.o
+all: clean libzcmd_tool
-zcmd_tool.o : zcmd_tool.c
- $(CC) -c -fPIC zcmd_tool.c -Wall -L$(USRLIBDIR) -I$(TOOLCHAIN)/include -I. -ljson -std=gnu99
+.c.o:
+ $(CC) $(CFLAGS) -Wall -fPIC -c $< -o $@
+
+libzcmd_tool : $(OBJS)
+ $(CC) $(LDFLAGS) -shared -o libzcmd_tool.so $(OBJS)
clean:
rm -rf *.o
@@ -0,0 +1,54 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2016-03-23 15:19:27.585448308 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2016-03-23 15:24:09.278845141 +0800
@@ -12,6 +12,10 @@
typedef union value_s {
bool bool_val;
+ int8_t int8_val;
+ int16_t int16_val;
+ int32_t int32_val;
+ int64_t int64_val;
uint8_t uint8_val;
uint16_t uint16_val;
uint32_t uint32_val;
@@ -66,8 +70,37 @@
setValue = json_object_new_boolean(v.bool_val);
json_object_object_add(jobj, paramName, setValue);
break;
- case json_type_ulong:
+
case json_type_int:
+ if( len > redundantSpace ) {
+ pos = pos + redundantSpace;
+ redundantSpace = BOUNDARY - len;
+ }
+ else {
+ redundantSpace = redundantSpace - len;
+ }
+
+ if(len == 8) {
+ memcpy(&v.int64_val, rqst_struct+pos, len);
+ setValue = json_object_new_int(v.int64_val);
+ }
+ else if(len == 4) {
+ memcpy(&v.int32_val, rqst_struct+pos, len);
+ setValue = json_object_new_int(v.int32_val);
+ }
+ else if(len == 2) {
+ memcpy(&v.int16_val, rqst_struct+pos, len);
+ setValue = json_object_new_int(v.int16_val);
+ }
+ else {
+ memcpy(&v.int8_val, rqst_struct+pos, len);
+ setValue = json_object_new_int((int)v.int8_val);
+ }
+
+ pos = pos + len;
+ json_object_object_add(jobj, paramName, setValue);
+ break;
+ case json_type_ulong:
case json_type_uint32:
case json_type_uint16:
case json_type_uint8:
@@ -0,0 +1,55 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2016-10-26 21:13:44.223112308 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2016-10-26 21:03:55.069092000 +0800
@@ -137,9 +137,10 @@
case json_type_base64:
case json_type_hex:
//zcfgLog(ZCFG_LOG_DEBUG, "type_string\n");
- v.str_val = (char *)malloc(len+1);
+ v.str_val = (char *)calloc(len+1, 1);
if(v.str_val == NULL) {
printf("%s : malloc fail\n", __FUNCTION__);
+ free(jobj);
return;
}
memcpy(v.str_val, rqst_struct+pos, len);
@@ -196,7 +197,7 @@
*objStruct = (void *)malloc(objInfo->size);
if(*objStruct == NULL){
zcfgLog(ZCFG_LOG_ERR, "Malloc fail in %s\n", __FUNCTION__);
- free(*objStruct);
+ //free(*objStruct);
return ZCFG_INTERNAL_ERROR;
}
@@ -205,6 +206,10 @@
/* With the information of each parameter, we can fill up data structure
from json string. */
jobj = json_tokener_parse(jstr);
+ if(is_error(jobj)){
+ free(*objStruct);
+ return ZCFG_INTERNAL_ERROR;
+ }
GET_PAMAMETERS_IN_OBJECT(objInfo, paramInfo, paramName) {
type = paramInfo->type;
@@ -214,6 +219,7 @@
if(tmpJobj == NULL) {
zcfgLog(ZCFG_LOG_ERR, "Can't get value for parameter %s\n", paramName);
free(*objStruct);
+ json_object_put(jobj);
return ZCFG_INTERNAL_ERROR;
}
@@ -275,8 +281,8 @@
case json_type_hex:
//zcfgLog(ZCFG_LOG_DEBUG, "json_type_string\n");
//zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
- v.str_val = (char *)malloc(len+1);
- strcpy(v.str_val, json_object_get_string(tmpJobj));
+ v.str_val = (char *)calloc(len+1, 1);
+ strncpy(v.str_val, json_object_get_string(tmpJobj), len);
memcpy(*objStruct+pos, v.str_val, len);
free(v.str_val);
@@ -0,0 +1,31 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2017-06-23 11:47:17.735989809 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2017-06-23 11:41:22.391559800 +0800
@@ -190,7 +190,8 @@
value_t v;
//zcfgLog(ZCFG_LOG_DEBUG, "Enter function %s\n", __FUNCTION__);
-
+ if(!objStruct || !jstr)
+ return ZCFG_INTERNAL_ERROR;
/* Get the object information in shared memory by using oid. */
objInfo = GET_OBJ_INFO_BY_OID(rdmObjId);;
@@ -208,6 +209,8 @@
jobj = json_tokener_parse(jstr);
if(is_error(jobj)){
free(*objStruct);
+ *objStruct = 0;
+
return ZCFG_INTERNAL_ERROR;
}
@@ -219,6 +222,7 @@
if(tmpJobj == NULL) {
zcfgLog(ZCFG_LOG_ERR, "Can't get value for parameter %s\n", paramName);
free(*objStruct);
+ *objStruct = 0;
json_object_put(jobj);
return ZCFG_INTERNAL_ERROR;
}
@@ -0,0 +1,48 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2017-08-22 15:16:59.484648680 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2017-08-22 15:19:42.646676685 +0800
@@ -285,23 +285,28 @@
case json_type_hex:
//zcfgLog(ZCFG_LOG_DEBUG, "json_type_string\n");
//zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
- v.str_val = (char *)calloc(len+1, 1);
- strncpy(v.str_val, json_object_get_string(tmpJobj), len);
- memcpy(*objStruct+pos, v.str_val, len);
- free(v.str_val);
+ if(strlen(json_object_get_string(tmpJobj)) <= len){
+ v.str_val = (char *)calloc(len+1, 1);
+ strncpy(v.str_val, json_object_get_string(tmpJobj), len);
+ memcpy(*objStruct+pos, v.str_val, len);
+ free(v.str_val);
- pos = pos + len;
+ pos = pos + len;
- if(len > redundantSpace) {
- len = len - redundantSpace;
- if((len % BOUNDARY) != 0)
- redundantSpace = BOUNDARY - (len % BOUNDARY);
- else
- redundantSpace = 0;
- }
- else {
- redundantSpace = redundantSpace - len;
- }
+ if(len > redundantSpace) {
+ len = len - redundantSpace;
+ if((len % BOUNDARY) != 0)
+ redundantSpace = BOUNDARY - (len % BOUNDARY);
+ else
+ redundantSpace = 0;
+ }
+ else {
+ redundantSpace = redundantSpace - len;
+ }
+ }else{
+ zcfgLog(ZCFG_LOG_ERR, "Input value was too long!!\n");
+ return ZCFG_INVALID_PARAM_VALUE_LENGTH;
+ }
break;
default :
zcfgLog(ZCFG_LOG_ERR, "Default type %d\n", type);
@@ -0,0 +1,31 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2018-01-11 18:41:18.090920936 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2018-01-11 18:41:51.837413600 +0800
@@ -74,7 +74,7 @@
case json_type_int:
if( len > redundantSpace ) {
pos = pos + redundantSpace;
- redundantSpace = BOUNDARY - len;
+ redundantSpace = (len > BOUNDARY) ? (BOUNDARY*2)-len : BOUNDARY-len;
}
else {
redundantSpace = redundantSpace - len;
@@ -106,7 +106,7 @@
case json_type_uint8:
if( len > redundantSpace ) {
pos = pos + redundantSpace;
- redundantSpace = BOUNDARY - len;
+ redundantSpace = (len > BOUNDARY) ? (BOUNDARY*2)-len : BOUNDARY-len;
}
else {
redundantSpace = redundantSpace - len;
@@ -254,7 +254,7 @@
//zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
if( len > redundantSpace ) {
pos = pos + redundantSpace;
- redundantSpace = BOUNDARY - len;
+ redundantSpace = (len > BOUNDARY) ? (BOUNDARY*2)-len : BOUNDARY-len;
}
else {
redundantSpace = redundantSpace - len;
@@ -0,0 +1,14 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2020-04-23 06:21:02.656906437 +0000
+++ libzcmd_tool-1.0/zcmd_tool.c 2020-04-23 06:25:24.868004524 +0000
@@ -305,6 +305,9 @@
}
}else{
zcfgLog(ZCFG_LOG_ERR, "Input value was too long!!\n");
+ free(*objStruct);
+ *objStruct = 0;
+ json_object_put(jobj);
return ZCFG_INVALID_PARAM_VALUE_LENGTH;
}
break;
@@ -0,0 +1,199 @@
Index: libzcmd_tool-1.0/Makefile
===================================================================
--- libzcmd_tool-1.0.orig/Makefile 2020-09-04 10:43:24.803099307 +0800
+++ libzcmd_tool-1.0/Makefile 2020-09-04 10:43:24.863099307 +0800
@@ -1,6 +1,10 @@
OBJS = zcmd_tool.o
CURRENT_DIR = $(shell pwd)
+ifeq ($(CONFIG_ZYXEL_MEMORY_LEAK_DETECT),y)
+CFLAGS += -DZCFG_MEMORY_LEAK_DETECT
+endif
+
LDFLAGS += -L$(USRLIBDIR) -ljson
CFLAGS += -I$(TOOLCHAIN)/include -I. -std=gnu99
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2020-09-04 10:43:24.851099307 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2020-09-04 10:44:13.303099307 +0800
@@ -23,6 +23,12 @@
char *str_val;
}value_t;
+// remove this file data in leakage information.
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+#undef json_object_new_object
+#undef json_object_new_string
+#endif
+
/*
* Function Name: zcmdStructToJString
* Description: This function is used to transform the requested structure into json string.
@@ -321,3 +327,152 @@
return ZCFG_SUCCESS;
}
+
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+zcfgRet_t _zcmdJStringToStruct(void **objStruct, const char *jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr, const char *fileName, int line)
+{
+ uint8_t type;
+ uint32_t len;
+ struct json_object *jobj = NULL;
+ struct json_object *tmpJobj = NULL;
+ int pos = 0;
+ int redundantSpace = 0;
+ objInfo_t *objInfo;
+ value_t v;
+
+ //printf("fileName=%s line=%d rdmObjId=%d\n", fileName, line, rdmObjId);
+
+ //zcfgLog(ZCFG_LOG_DEBUG, "Enter function %s\n", __FUNCTION__);
+ if(!objStruct || !jstr)
+ return ZCFG_INTERNAL_ERROR;
+ /* Get the object information in shared memory by using oid. */
+ objInfo = GET_OBJ_INFO_BY_OID(rdmObjId);;
+
+ *objStruct = (void *)malloc(objInfo->size);
+
+ if(*objStruct == NULL){
+ zcfgLog(ZCFG_LOG_ERR, "Malloc fail in %s\n", __FUNCTION__);
+ //free(*objStruct);
+ return ZCFG_INTERNAL_ERROR;
+ }
+
+ memset(*objStruct, 0, objInfo->size);
+
+ /* With the information of each parameter, we can fill up data structure
+ from json string. */
+ jobj = json_tokener_parse(jstr);
+ if(is_error(jobj)){
+ free(*objStruct);
+ *objStruct = 0;
+ return ZCFG_INTERNAL_ERROR;
+ }
+
+ GET_PAMAMETERS_IN_OBJECT(objInfo, paramInfo, paramName) {
+ type = paramInfo->type;
+ len = paramInfo->len;
+ tmpJobj = json_object_object_get(jobj, paramName);
+
+ if(tmpJobj == NULL) {
+ zcfgLog(ZCFG_LOG_ERR, "Can't get value for parameter %s\n", paramName);
+ free(*objStruct);
+ *objStruct = 0;
+ json_object_put(jobj);
+ return ZCFG_INTERNAL_ERROR;
+ }
+
+ switch (type) {
+ case json_type_boolean:
+ //zcfgLog(ZCFG_LOG_DEBUG, "json_type_boolean\n");
+ //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
+ v.bool_val = json_object_get_boolean(tmpJobj);
+
+ if( len > redundantSpace ) {
+ pos = pos + redundantSpace;
+ redundantSpace = BOUNDARY - len;
+ }
+ else {
+ redundantSpace = redundantSpace - len;
+ }
+
+ memcpy(*objStruct+pos, &v.bool_val, sizeof(bool));
+
+ pos = pos + len;
+ break;
+ case json_type_ulong:
+ case json_type_int:
+ case json_type_uint32:
+ case json_type_uint16:
+ case json_type_uint8:
+ //zcfgLog(ZCFG_LOG_DEBUG, "json_type_int\n");
+ //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
+ if( len > redundantSpace ) {
+ pos = pos + redundantSpace;
+ redundantSpace = (len > BOUNDARY) ? (BOUNDARY*2)-len : BOUNDARY-len;
+ }
+ else {
+ redundantSpace = redundantSpace - len;
+ }
+
+ if(len == 8) {
+ v.ulong_val = json_object_get_int(tmpJobj);
+ memcpy(*objStruct+pos, &v.ulong_val, sizeof(uint64_t));
+ }
+ else if(len == 4) {
+ v.uint32_val = json_object_get_int(tmpJobj);
+ memcpy(*objStruct+pos, &v.uint32_val, sizeof(int));
+ }
+ else if(len == 2) {
+ v.uint16_val = json_object_get_int(tmpJobj);
+ memcpy(*objStruct+pos, &v.uint16_val, sizeof(unsigned short));
+ }
+ else {
+ v.uint8_val = (unsigned char)json_object_get_int(tmpJobj);
+ memcpy(*objStruct+pos, &v.uint8_val, sizeof(unsigned char));
+ }
+
+ pos = pos + len;
+ break;
+ case json_type_string:
+ case json_type_time:
+ case json_type_base64:
+ case json_type_hex:
+ //zcfgLog(ZCFG_LOG_DEBUG, "json_type_string\n");
+ //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
+ if(strlen(json_object_get_string(tmpJobj)) <= len){
+ v.str_val = (char *)calloc(len+1, 1);
+ strncpy(v.str_val, json_object_get_string(tmpJobj), len);
+ memcpy(*objStruct+pos, v.str_val, len);
+ free(v.str_val);
+
+ pos = pos + len;
+
+ if(len > redundantSpace) {
+ len = len - redundantSpace;
+ if((len % BOUNDARY) != 0)
+ redundantSpace = BOUNDARY - (len % BOUNDARY);
+ else
+ redundantSpace = 0;
+ }
+ else {
+ redundantSpace = redundantSpace - len;
+ }
+ }else{
+ zcfgLog(ZCFG_LOG_ERR, "Input value was too long!!\n");
+ free(*objStruct);
+ *objStruct = 0;
+ json_object_put(jobj);
+ return ZCFG_INVALID_PARAM_VALUE_LENGTH;
+ }
+ break;
+ default :
+ zcfgLog(ZCFG_LOG_ERR, "Default type %d\n", type);
+ break;
+ }
+ }
+ json_object_put(jobj);
+
+ recordZcfgAllocData(objStruct, fileName, line, objInfo->size);
+
+ return ZCFG_SUCCESS;
+}
+#endif
Index: libzcmd_tool-1.0/zcmd_tool.h
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.h 2013-03-06 17:47:53.000000000 +0800
+++ libzcmd_tool-1.0/zcmd_tool.h 2020-09-04 10:43:24.863099307 +0800
@@ -4,4 +4,9 @@
void zcmdStructToJString(void *, char **, zcfg_offset_t, void *);
/*Used to parse json string and fill up the requested structure*/
zcfgRet_t zcmdJStringToStruct(void **, const char *, zcfg_offset_t, void *);
+
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+zcfgRet_t _zcmdJStringToStruct(void **, const char *, zcfg_offset_t, void *, const char *, int);
+#endif
+
#endif
@@ -0,0 +1,330 @@
Index: libzcmd_tool-1.0/zcmd_tool.c
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.c 2021-02-05 14:49:39.641789083 +0800
+++ libzcmd_tool-1.0/zcmd_tool.c 2021-02-05 14:55:45.702018914 +0800
@@ -4,6 +4,7 @@
#include "zcmd_schema.h"
#include "zcmd_tool.h"
#include "zcfg_debug.h"
+#include "zos_api.h"
extern void *paramNameShmAddr;
@@ -34,7 +35,11 @@
* Description: This function is used to transform the requested structure into json string.
*
*/
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+void _zcmdStructToJString(void *rqst_struct, char **jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr, const char *fileName, int line)
+#else
void zcmdStructToJString(void *rqst_struct, char **jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr)
+#endif
{
uint8_t type;
uint32_t len;
@@ -143,10 +148,10 @@
case json_type_base64:
case json_type_hex:
//zcfgLog(ZCFG_LOG_DEBUG, "type_string\n");
- v.str_val = (char *)calloc(len+1, 1);
+ v.str_val = (char *)ZOS_MALLOC(len+1);
if(v.str_val == NULL) {
printf("%s : malloc fail\n", __FUNCTION__);
- free(jobj);
+ json_object_put(jobj);
return;
}
memcpy(v.str_val, rqst_struct+pos, len);
@@ -165,7 +170,7 @@
//zcfgLog(ZCFG_LOG_DEBUG, "Key %s value %s\n", paramName, v.str_val);
setValue = json_object_new_string(v.str_val);
json_object_object_add(jobj, paramName, setValue);
- free(v.str_val);
+ ZOS_FREE(v.str_val);
break;
default :
zcfgLog(ZCFG_LOG_DEBUG, "Default type %d\n", type);
@@ -174,17 +179,27 @@
}
requestStr = json_object_to_json_string(jobj);
- *jstr = (char *)malloc(strlen(requestStr)+1);
+ *jstr = (char *)ZOS_MALLOC(strlen(requestStr)+1);
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+ recordZcfgAllocData(*jstr, fileName, line, 0);
+#endif
+
strcpy(*jstr, requestStr);
json_object_put(jobj);
+
+
}
/*
* Function Name: zcmdJStringToStruct
* Description: Used to parse json string to fill up the object structure
*
*/
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+zcfgRet_t _zcmdJStringToStruct(void **objStruct, const char *jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr, const char *fileName, int line)
+#else
zcfgRet_t zcmdJStringToStruct(void **objStruct, const char *jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr)
+#endif
{
uint8_t type;
uint32_t len;
@@ -201,10 +216,9 @@
/* Get the object information in shared memory by using oid. */
objInfo = GET_OBJ_INFO_BY_OID(rdmObjId);;
- *objStruct = (void *)malloc(objInfo->size);
+ *objStruct = (void *)ZOS_MALLOC(objInfo->size);
if(*objStruct == NULL){
zcfgLog(ZCFG_LOG_ERR, "Malloc fail in %s\n", __FUNCTION__);
- //free(*objStruct);
return ZCFG_INTERNAL_ERROR;
}
@@ -214,9 +228,7 @@
from json string. */
jobj = json_tokener_parse(jstr);
if(is_error(jobj)){
- free(*objStruct);
- *objStruct = 0;
-
+ ZOS_FREE(*objStruct);
return ZCFG_INTERNAL_ERROR;
}
@@ -227,8 +239,7 @@
if(tmpJobj == NULL) {
zcfgLog(ZCFG_LOG_ERR, "Can't get value for parameter %s\n", paramName);
- free(*objStruct);
- *objStruct = 0;
+ ZOS_FREE(*objStruct);
json_object_put(jobj);
return ZCFG_INTERNAL_ERROR;
}
@@ -292,10 +303,10 @@
//zcfgLog(ZCFG_LOG_DEBUG, "json_type_string\n");
//zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
if(strlen(json_object_get_string(tmpJobj)) <= len){
- v.str_val = (char *)calloc(len+1, 1);
+ v.str_val = (char *)ZOS_MALLOC(len+1);
strncpy(v.str_val, json_object_get_string(tmpJobj), len);
memcpy(*objStruct+pos, v.str_val, len);
- free(v.str_val);
+ ZOS_FREE(v.str_val);
pos = pos + len;
@@ -311,8 +322,7 @@
}
}else{
zcfgLog(ZCFG_LOG_ERR, "Input value was too long!!\n");
- free(*objStruct);
- *objStruct = 0;
+ ZOS_FREE(*objStruct);
json_object_put(jobj);
return ZCFG_INVALID_PARAM_VALUE_LENGTH;
}
@@ -324,155 +334,10 @@
}
json_object_put(jobj);
-
- return ZCFG_SUCCESS;
-}
-
#ifdef ZCFG_MEMORY_LEAK_DETECT
-zcfgRet_t _zcmdJStringToStruct(void **objStruct, const char *jstr, zcfg_offset_t rdmObjId, void *schemaShmAddr, const char *fileName, int line)
-{
- uint8_t type;
- uint32_t len;
- struct json_object *jobj = NULL;
- struct json_object *tmpJobj = NULL;
- int pos = 0;
- int redundantSpace = 0;
- objInfo_t *objInfo;
- value_t v;
-
- //printf("fileName=%s line=%d rdmObjId=%d\n", fileName, line, rdmObjId);
-
- //zcfgLog(ZCFG_LOG_DEBUG, "Enter function %s\n", __FUNCTION__);
- if(!objStruct || !jstr)
- return ZCFG_INTERNAL_ERROR;
- /* Get the object information in shared memory by using oid. */
- objInfo = GET_OBJ_INFO_BY_OID(rdmObjId);;
-
- *objStruct = (void *)malloc(objInfo->size);
-
- if(*objStruct == NULL){
- zcfgLog(ZCFG_LOG_ERR, "Malloc fail in %s\n", __FUNCTION__);
- //free(*objStruct);
- return ZCFG_INTERNAL_ERROR;
- }
-
- memset(*objStruct, 0, objInfo->size);
-
- /* With the information of each parameter, we can fill up data structure
- from json string. */
- jobj = json_tokener_parse(jstr);
- if(is_error(jobj)){
- free(*objStruct);
- *objStruct = 0;
- return ZCFG_INTERNAL_ERROR;
- }
-
- GET_PAMAMETERS_IN_OBJECT(objInfo, paramInfo, paramName) {
- type = paramInfo->type;
- len = paramInfo->len;
- tmpJobj = json_object_object_get(jobj, paramName);
-
- if(tmpJobj == NULL) {
- zcfgLog(ZCFG_LOG_ERR, "Can't get value for parameter %s\n", paramName);
- free(*objStruct);
- *objStruct = 0;
- json_object_put(jobj);
- return ZCFG_INTERNAL_ERROR;
- }
-
- switch (type) {
- case json_type_boolean:
- //zcfgLog(ZCFG_LOG_DEBUG, "json_type_boolean\n");
- //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
- v.bool_val = json_object_get_boolean(tmpJobj);
-
- if( len > redundantSpace ) {
- pos = pos + redundantSpace;
- redundantSpace = BOUNDARY - len;
- }
- else {
- redundantSpace = redundantSpace - len;
- }
-
- memcpy(*objStruct+pos, &v.bool_val, sizeof(bool));
-
- pos = pos + len;
- break;
- case json_type_ulong:
- case json_type_int:
- case json_type_uint32:
- case json_type_uint16:
- case json_type_uint8:
- //zcfgLog(ZCFG_LOG_DEBUG, "json_type_int\n");
- //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
- if( len > redundantSpace ) {
- pos = pos + redundantSpace;
- redundantSpace = (len > BOUNDARY) ? (BOUNDARY*2)-len : BOUNDARY-len;
- }
- else {
- redundantSpace = redundantSpace - len;
- }
-
- if(len == 8) {
- v.ulong_val = json_object_get_int(tmpJobj);
- memcpy(*objStruct+pos, &v.ulong_val, sizeof(uint64_t));
- }
- else if(len == 4) {
- v.uint32_val = json_object_get_int(tmpJobj);
- memcpy(*objStruct+pos, &v.uint32_val, sizeof(int));
- }
- else if(len == 2) {
- v.uint16_val = json_object_get_int(tmpJobj);
- memcpy(*objStruct+pos, &v.uint16_val, sizeof(unsigned short));
- }
- else {
- v.uint8_val = (unsigned char)json_object_get_int(tmpJobj);
- memcpy(*objStruct+pos, &v.uint8_val, sizeof(unsigned char));
- }
-
- pos = pos + len;
- break;
- case json_type_string:
- case json_type_time:
- case json_type_base64:
- case json_type_hex:
- //zcfgLog(ZCFG_LOG_DEBUG, "json_type_string\n");
- //zcfgLog(ZCFG_LOG_DEBUG, "Name %s length %d\n", paramName, len);
- if(strlen(json_object_get_string(tmpJobj)) <= len){
- v.str_val = (char *)calloc(len+1, 1);
- strncpy(v.str_val, json_object_get_string(tmpJobj), len);
- memcpy(*objStruct+pos, v.str_val, len);
- free(v.str_val);
-
- pos = pos + len;
-
- if(len > redundantSpace) {
- len = len - redundantSpace;
- if((len % BOUNDARY) != 0)
- redundantSpace = BOUNDARY - (len % BOUNDARY);
- else
- redundantSpace = 0;
- }
- else {
- redundantSpace = redundantSpace - len;
- }
- }else{
- zcfgLog(ZCFG_LOG_ERR, "Input value was too long!!\n");
- free(*objStruct);
- *objStruct = 0;
- json_object_put(jobj);
- return ZCFG_INVALID_PARAM_VALUE_LENGTH;
- }
- break;
- default :
- zcfgLog(ZCFG_LOG_ERR, "Default type %d\n", type);
- break;
- }
- }
- json_object_put(jobj);
-
- recordZcfgAllocData(objStruct, fileName, line, objInfo->size);
+ recordZcfgAllocData(*objStruct, fileName, line, 0);
+#endif
return ZCFG_SUCCESS;
}
-#endif
+
Index: libzcmd_tool-1.0/zcmd_tool.h
===================================================================
--- libzcmd_tool-1.0.orig/zcmd_tool.h 2021-02-05 14:49:39.641789083 +0800
+++ libzcmd_tool-1.0/zcmd_tool.h 2021-02-05 14:49:39.657789083 +0800
@@ -1,12 +1,19 @@
#ifndef _ZCMD_TOOL_H
#define _ZCMD_TOOL_H
+
+#ifdef ZCFG_MEMORY_LEAK_DETECT
+#define zcmdStructToJString(rqst_struct, jstr, oid, schema) _zcmdStructToJString(rqst_struct, jstr, oid, schema, __FILE__, __LINE__)
+#define zcmdJStringToStruct(objStruct, jstr, oid, schema) _zcmdJStringToStruct(objStruct, jstr, oid, schema, __FILE__, __LINE__)
+
+void _zcmdStructToJString(void *, char **, zcfg_offset_t, void *, const char *, int);
+zcfgRet_t _zcmdJStringToStruct(void **, const char *, zcfg_offset_t, void *, const char *, int);
+#else
+
/*Used to transform the requested structure to json string*/
void zcmdStructToJString(void *, char **, zcfg_offset_t, void *);
/*Used to parse json string and fill up the requested structure*/
zcfgRet_t zcmdJStringToStruct(void **, const char *, zcfg_offset_t, void *);
-
-#ifdef ZCFG_MEMORY_LEAK_DETECT
-zcfgRet_t _zcmdJStringToStruct(void **, const char *, zcfg_offset_t, void *, const char *, int);
#endif
+
#endif
Index: libzcmd_tool-1.0/Makefile
===================================================================
--- libzcmd_tool-1.0.orig/Makefile 2021-02-05 14:49:39.641789083 +0800
+++ libzcmd_tool-1.0/Makefile 2021-02-05 14:53:57.136082433 +0800
@@ -5,7 +5,7 @@
CFLAGS += -DZCFG_MEMORY_LEAK_DETECT
endif
-LDFLAGS += -L$(USRLIBDIR) -ljson
+LDFLAGS += -L$(USRLIBDIR) -ljson -lzos
CFLAGS += -I$(TOOLCHAIN)/include -I. -std=gnu99
.PHONY : libzcmd_tool