-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ioctl] Incorrect conversion between integer types #3522
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b802d81
fix code scan
huof6829 f12ae84
add path clean
huof6829 52d3038
Merge branch 'iotexproject:master' into fix_code_scan
huof6829 846af4c
add escapeString
huof6829 93a987c
add filepath.join
huof6829 7de85f0
add full path
huof6829 66d0dc5
add path clean
huof6829 faba562
Merge branch 'master' into fix_code_scan
huof6829 353c071
just fix: Incorrect conversion between integer types
huof6829 bcd65a8
Merge branch 'master' into fix_code_scan
raullenchai 0a9cefc
Merge branch 'master' into fix_code_scan
Liuhaai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ func isExist(path string) bool { | |
} | ||
|
||
func rename(oldPath string, newPath string, c chan bool) { | ||
if isExist(_givenPath + "/" + oldPath) { | ||
if isExist(oldPath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if err := os.Rename(oldPath, newPath); err != nil { | ||
log.Println("Rename file failed: ", err) | ||
} | ||
|
@@ -127,7 +127,7 @@ func rename(oldPath string, newPath string, c chan bool) { | |
} | ||
|
||
func share(args []string) error { | ||
_givenPath = args[0] | ||
_givenPath = filepath.Clean(args[0]) | ||
if len(_givenPath) == 0 { | ||
return output.NewError(output.ReadFileError, "failed to get directory", nil) | ||
} | ||
|
@@ -186,7 +186,7 @@ func share(args []string) error { | |
case "list": | ||
payload := make(map[string]bool) | ||
for _, ele := range _fileList { | ||
payload[ele] = isReadOnly(_givenPath + "/" + ele) | ||
payload[ele] = isReadOnly(filepath.Join(_givenPath, ele)) | ||
} | ||
response.Payload = payload | ||
if err := conn.WriteJSON(&response); err != nil { | ||
|
@@ -197,57 +197,95 @@ func share(args []string) error { | |
|
||
t := request.Payload | ||
getPayload := reflect.ValueOf(t).Index(0).Interface().(map[string]interface{}) | ||
getPayloadPath := getPayload["path"].(string) | ||
upload, err := os.ReadFile(_givenPath + "/" + getPayloadPath) | ||
getPayloadPath, err := cleanPath(getPayload["path"].(string)) | ||
if err != nil { | ||
log.Println("clean file path failed: ", err) | ||
break | ||
} | ||
getPayloadPath = filepath.Join(_givenPath, getPayloadPath) | ||
upload, err := os.ReadFile(getPayloadPath) | ||
if err != nil { | ||
log.Println("read file failed: ", err) | ||
break | ||
} | ||
payload["content"] = string(upload) | ||
payload["readonly"] = isReadOnly(_givenPath + "/" + getPayloadPath) | ||
payload["readonly"] = isReadOnly(getPayloadPath) | ||
response.Payload = payload | ||
if err := conn.WriteJSON(&response); err != nil { | ||
log.Println("send get response: ", err) | ||
break | ||
} | ||
log.Println("share: " + _givenPath + "/" + getPayloadPath) | ||
log.Println("share: " + easpcapeString(getPayloadPath)) | ||
|
||
case "rename": | ||
c := make(chan bool) | ||
t := request.Payload | ||
renamePayload := reflect.ValueOf(t).Index(0).Interface().(map[string]interface{}) | ||
oldPath := renamePayload["oldPath"].(string) | ||
newPath := renamePayload["newPath"].(string) | ||
go rename(oldPath, newPath, c) | ||
oldRenamePath, err := cleanPath(renamePayload["oldPath"].(string)) | ||
if err != nil { | ||
log.Println("clean file path failed: ", err) | ||
break | ||
} | ||
newRenamePath, err := cleanPath(renamePayload["newPath"].(string)) | ||
if err != nil { | ||
log.Println("clean file path failed: ", err) | ||
break | ||
} | ||
oldRenamePath = filepath.Join(_givenPath, oldRenamePath) | ||
newRenamePath = filepath.Join(_givenPath, newRenamePath) | ||
go rename(oldRenamePath, newRenamePath, c) | ||
response.Payload = <-c | ||
if err := conn.WriteJSON(&response); err != nil { | ||
log.Println("send get response: ", err) | ||
break | ||
} | ||
log.Println("rename: " + _givenPath + "/" + oldPath + " to " + _givenPath + "/" + newPath) | ||
log.Println("rename: " + easpcapeString(oldRenamePath) + " to " + easpcapeString(newRenamePath)) | ||
|
||
case "set": | ||
t := request.Payload | ||
setPayload := reflect.ValueOf(t).Index(0).Interface().(map[string]interface{}) | ||
setPath := setPayload["path"].(string) | ||
content := setPayload["content"].(string) | ||
err := os.WriteFile(_givenPath+"/"+setPath, []byte(content), 0777) | ||
setPath, err := cleanPath(setPayload["path"].(string)) | ||
if err != nil { | ||
log.Println("clean file path failed: ", err) | ||
break | ||
} | ||
setPath = filepath.Join(_givenPath, setPath) | ||
if err := os.MkdirAll(filepath.Dir(setPath), 0755); err != nil { | ||
log.Println("mkdir failed: ", err) | ||
break | ||
} | ||
if err := os.WriteFile(setPath, []byte(content), 0644); err != nil { | ||
log.Println("set file failed: ", err) | ||
break | ||
} | ||
if err := conn.WriteJSON(&response); err != nil { | ||
log.Println("send set response: ", err) | ||
break | ||
} | ||
log.Println("set: " + _givenPath + "/" + setPath) | ||
log.Println("set: " + easpcapeString(setPath)) | ||
|
||
default: | ||
log.Println("Don't support this IDE yet. Can not handle websocket method: " + request.Key) | ||
log.Println("Don't support this IDE yet. Can not handle websocket method: " + easpcapeString(request.Key)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. printf |
||
|
||
} | ||
} | ||
}) | ||
log.Fatal(http.ListenAndServe(*_addr, nil)) | ||
|
||
return nil | ||
} | ||
|
||
func cleanPath(path string) (string, error) { | ||
path = filepath.Clean(filepath.Join("/", path)) | ||
real, err := filepath.Rel("/", path) | ||
if err != nil { | ||
return "", err | ||
} | ||
return real, nil | ||
} | ||
|
||
func easpcapeString(str string) string { | ||
escaped := strings.Replace(str, "\n", "", -1) | ||
return strings.Replace(escaped, "\r", "", -1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open a new PR for this