!40 [sync] PR-39: fix some review issues
From: @openeuler-sync-bot Reviewed-by: @nlgwcy Signed-off-by: @nlgwcy
This commit is contained in:
commit
05022d4e54
148
0005-fix-some-review-issues.patch
Normal file
148
0005-fix-some-review-issues.patch
Normal file
@ -0,0 +1,148 @@
|
||||
From 569ff66dc15ad3dca45e8297c7ab5b5425901f97 Mon Sep 17 00:00:00 2001
|
||||
From: kwb0523 <kwb0523@163.com>
|
||||
Date: Wed, 13 Sep 2023 11:11:32 +0800
|
||||
Subject: [PATCH] fix some review issues
|
||||
|
||||
1.fix segment fault triggered by unsupported command operations
|
||||
2.fix incorrect use of securec function parameters
|
||||
3.remove redundant cmd option 'V'
|
||||
---
|
||||
bwmcli.c | 37 +++++++++++++++++++++++--------------
|
||||
1 file changed, 23 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/bwmcli.c b/bwmcli.c
|
||||
index 8ea17d6..b878fc7 100644
|
||||
--- a/bwmcli.c
|
||||
+++ b/bwmcli.c
|
||||
@@ -315,7 +315,7 @@ static bool CheckCgrpV1PathLegal(const char *cgrpPath, char *trustedPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
- int ret = snprintf_s(trustedPath, PATH_MAX + 1, PATH_MAX + 1, "%s/%s", trustedCgrpPath, "net_cls.classid");
|
||||
+ int ret = snprintf_s(trustedPath, PATH_MAX + 1, PATH_MAX, "%s/%s", trustedCgrpPath, "net_cls.classid");
|
||||
if (ret < 0 || stat(trustedPath, &st) < 0 || (st.st_mode & S_IFMT) != S_IFREG) {
|
||||
BWM_LOG_ERR("CgrpV1Prio get realPath failed. ret: %d\n", ret);
|
||||
return false;
|
||||
@@ -348,7 +348,7 @@ static int CgrpV1Prio(const char *cgrpPath, int prio, int op)
|
||||
|
||||
switch (op) {
|
||||
case PRIO_SET:
|
||||
- ret = snprintf_s(buf, BUF_SIZE, BUF_SIZE, "%u\n", (__u32)prio);
|
||||
+ ret = snprintf_s(buf, BUF_SIZE, BUF_SIZE - 1, "%u\n", (__u32)prio);
|
||||
if (ret < 0) {
|
||||
BWM_LOG_ERR("CgrpV1Prio snprintf_s prio failed. ret: %d.\n", ret);
|
||||
(void)close(fd);
|
||||
@@ -501,7 +501,7 @@ end:
|
||||
static int NetdevEnabledSub(const char *format, const char *ethdev)
|
||||
{
|
||||
int ret;
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, format, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, format, ethdev);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ static int DisableSpecificNetdevice(const char *ethdev, const void *unused)
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_disableSeq) / sizeof(struct TcCmd); i++) {
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, g_disableSeq[i].cmdStr, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, g_disableSeq[i].cmdStr, ethdev);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
BWM_LOG_ERR("Invalid net device: %s\n", ethdev);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -574,7 +574,7 @@ static bool execute_cmd(const char *format, const char *ethdev, const char *sear
|
||||
{
|
||||
int ret;
|
||||
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, format, ethdev, search);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, format, ethdev, search);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
g_cmdBuf[MAX_CMD_LEN - 1] = '\0';
|
||||
BWM_LOG_ERR("Invalid cmd: %s\n", g_cmdBuf);
|
||||
@@ -652,7 +652,7 @@ static int EnableSpecificNetdevice(const char *ethdev, const void *unused)
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_enableSeq) / sizeof(struct TcCmd); i++) {
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, g_enableSeq[i].cmdStr, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, g_enableSeq[i].cmdStr, ethdev);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
BWM_LOG_ERR("Invalid net device: %s\n", ethdev);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -817,7 +817,12 @@ static int GetCfgsInfo(char *cfg, int cfgLen)
|
||||
struct CfgOption *option;
|
||||
|
||||
option = FindOptions(cfg);
|
||||
- return option->op.getCfg(cfg);
|
||||
+ if (option->op.getCfg) {
|
||||
+ return option->op.getCfg(cfg);
|
||||
+ }
|
||||
+
|
||||
+ (void)fprintf(stderr, "invalid operation: %s can't support get operation\n", option->name);
|
||||
+ return EXIT_FAIL;
|
||||
}
|
||||
|
||||
static int SetCfgsInfo(char *cfg, int cfgLen, char *args, int argsLen)
|
||||
@@ -825,7 +830,12 @@ static int SetCfgsInfo(char *cfg, int cfgLen, char *args, int argsLen)
|
||||
struct CfgOption *option;
|
||||
|
||||
option = FindOptions(cfg);
|
||||
- return option->op.setCfg(cfg, args);
|
||||
+ if (option->op.setCfg) {
|
||||
+ return option->op.setCfg(cfg, args);
|
||||
+ }
|
||||
+
|
||||
+ (void)fprintf(stderr, "invalid operation: %s can't support set operation\n", option->name);
|
||||
+ return EXIT_FAIL;
|
||||
}
|
||||
|
||||
static int BreakMultiArgs(char *args, char arg1[], char arg2[], int mutilArgs)
|
||||
@@ -919,7 +929,7 @@ static int CfgsInfo(int argc, char *const *argv, int isSet)
|
||||
char option[PATH_MAX + 1] = {0};
|
||||
char args[PRIO_LEN] = {0};
|
||||
|
||||
- rc = strncpy_s(option, PATH_MAX + 1, optarg, PATH_MAX + 1);
|
||||
+ rc = strncpy_s(option, PATH_MAX + 1, optarg, PATH_MAX);
|
||||
if (rc != EOK || option[PATH_MAX] != '\0') {
|
||||
(void)fprintf(stderr, "invalid option, too long: %s\n", optarg);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -934,7 +944,7 @@ static int CfgsInfo(int argc, char *const *argv, int isSet)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- rc = strncpy_s(args, PRIO_LEN, argv[optind], strlen(argv[optind]));
|
||||
+ rc = strncpy_s(args, PRIO_LEN, argv[optind], PRIO_LEN - 1);
|
||||
if (rc != EOK || args[PRIO_LEN - 1] != '\0') {
|
||||
(void)fprintf(stderr, "invalid args, too long: %s\n", argv[optind]);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -974,9 +984,9 @@ static int ChangeNetdeviceStatus(int argc, char *const *argv, int enable)
|
||||
}
|
||||
|
||||
if (optarg != NULL) {
|
||||
- rc = strncpy_s(ethdev, NAME_MAX + 1, optarg, NAME_MAX + 1);
|
||||
+ rc = strncpy_s(ethdev, NAME_MAX + 1, optarg, NAME_MAX);
|
||||
} else {
|
||||
- rc = strncpy_s(ethdev, NAME_MAX + 1, argv[optind], NAME_MAX + 1);
|
||||
+ rc = strncpy_s(ethdev, NAME_MAX + 1, argv[optind], NAME_MAX);
|
||||
optind++;
|
||||
}
|
||||
|
||||
@@ -1266,7 +1276,7 @@ int main(int argc, char **argv)
|
||||
return EXIT_FAIL_OPTION;
|
||||
}
|
||||
|
||||
- while ((opt = getopt_long(argc, argv, "vVhe::d::p:s:", g_longOptions, &longindex)) != -1) {
|
||||
+ while ((opt = getopt_long(argc, argv, "vhe::d::p:s:", g_longOptions, &longindex)) != -1) {
|
||||
hasOptions = 1;
|
||||
isSet = 1;
|
||||
enable = 1;
|
||||
@@ -1274,7 +1284,6 @@ int main(int argc, char **argv)
|
||||
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
- case 'V':
|
||||
BWM_LOG_INFO("version: %s\n", BWM_VERSION);
|
||||
break;
|
||||
case 'p':
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: oncn-bwm
|
||||
Version: 1.1
|
||||
Release: 4
|
||||
Release: 5
|
||||
Summary: Pod bandwidth management in mixed deployment scenarios of online and offline services
|
||||
License: GPL-2.0
|
||||
URL: https://gitee.com/src-openeuler/oncn-bwm
|
||||
@ -18,6 +18,7 @@ Patch9001: 0001-adapt-libbpf-0.8.1.patch
|
||||
Patch9002: 0002-clean-code-and-use-securec-function.patch
|
||||
Patch9003: 0003-add-proc-file-interface.patch
|
||||
Patch9004: 0004-fix-offline-packets-block.patch
|
||||
Patch9005: 0005-fix-some-review-issues.patch
|
||||
|
||||
%description
|
||||
Pod bandwidth management in mixed deployment scenarios of online and offline services
|
||||
@ -112,6 +113,12 @@ depmod -a
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Sep 13 2023 JofDiamonds <kwb0523@163.com> - 1.1-5
|
||||
- fix some review issues:
|
||||
1.fix segment fault triggered by unsupported command operations
|
||||
2.fix incorrect use of securec function parameters
|
||||
3.remove redundant cmd option 'V'
|
||||
|
||||
* Sat May 20 2023 JofDiamonds <kwb0523@163.com> - 1.1-4
|
||||
- fix offline packets block
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user