Skip to content

fix(dde-open): Fix dde open crash issue#143

Merged
robertkill merged 1 commit into
linuxdeepin:masterfrom
robertkill:master
Jul 22, 2025
Merged

fix(dde-open): Fix dde open crash issue#143
robertkill merged 1 commit into
linuxdeepin:masterfrom
robertkill:master

Conversation

@robertkill
Copy link
Copy Markdown
Contributor

@robertkill robertkill commented Jul 22, 2025

Fix the null pointer dereference crash caused by special character file names

Log: as title
pms: BUG-325569

Summary by Sourcery

Prevent dde-open from crashing on special-character filenames by adding nil checks and fallback handling, and add debug logging for the URI scheme

Bug Fixes:

  • Add nil checks for gFile and parsed URLs to avoid null pointer dereferences
  • Fallback to opening the raw argument when URL parsing yields nil

Enhancements:

  • Log the URI scheme at debug level during argument processing

Fix the null pointer dereference crash caused by special character file names

Log: as title
pms: BUG-325569
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

关键摘要:

  • url.Parse失败后,gFile可能为nil,直接调用gFile.GetUriScheme()会导致空指针异常。
  • switch scheme语句中,case "file":分支中,如果unil,应该处理这种情况,而不是直接调用openFile(u.Path)

是否建议立即修改:

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jul 22, 2025

Reviewer's Guide

Implement nil-pointer guards and fallback logic around URL and file handling to prevent crashes on special-character filenames, and surface the resolved scheme via debug logging.

Sequence diagram for improved file opening logic in dde-open

sequenceDiagram
    participant Main as main()
    participant URL as url.Parse
    participant GFile as gio.FileNewForCommandlineArg
    participant Logger as logger
    participant OpenFile as openFile

    Main->>URL: Parse(arg)
    alt url.Parse returns error
        Main->>GFile: FileNewForCommandlineArg(arg)
        alt gFile != nil
            Main->>GFile: GetUriScheme()
            Main->>Logger: Debugf("scheme: %q", scheme)
        else gFile == nil
            Main->>Logger: Warningf("failed to parse url %q: %v", arg, err)
        end
        alt scheme == ""
            Main->>Logger: Warningf("failed to parse url %q: %v", arg, err)
        end
    else url.Parse succeeds
        Main->>URL: Get scheme
        Main->>Logger: Debugf("scheme: %q", scheme)
    end
    alt scheme == "file"
        alt u != nil
            Main->>OpenFile: openFile(u.Path)
        else u == nil
            Main->>OpenFile: openFile(arg)
        end
    else scheme == ""
        Main->>OpenFile: openFile(arg)
    end
Loading

Class diagram for updated file and URL handling in dde-open

classDiagram
    class main {
        +main()
    }
    class gio {
        +FileNewForCommandlineArg(arg)
    }
    class gFile {
        +GetUriScheme()
    }
    class url {
        +Parse(arg)
        +Scheme
        +Path
    }
    class logger {
        +Warningf(format, ...)
        +Debugf(format, ...)
    }
    class openFile {
        +openFile(path)
    }
    main --> url : uses
    main --> gio : uses
    gio --> gFile : returns
    main --> logger : logs
    main --> openFile : calls
Loading

File-Level Changes

Change Details Files
Guard against null pointer dereferences for gFile and URL
  • Wrap gFile.GetUriScheme() call inside if gFile != nil
  • Wrap openFile call in if u != nil, fallback to openFile(arg) when u is nil
dde-open/main.go
Add debug logging for resolved scheme
  • Insert logger.Debugf to log the scheme value after resolution
dde-open/main.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @robertkill - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `dde-open/main.go:69` </location>
<code_context>
 	switch scheme {
 	case "file":
-		err = openFile(u.Path)
+		if u != nil {
+			err = openFile(u.Path)
+		} else {
+			// 如果u为nil,说明url.Parse失败了,应该作为普通文件路径处理
+			err = openFile(arg)
+		}

 	case "":
</code_context>

<issue_to_address>
The check for u != nil after url.Parse may be redundant.

Go's url.Parse always returns a non-nil *url.URL, so this check can be removed to simplify the code.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
	switch scheme {
	case "file":
		if u != nil {
			err = openFile(u.Path)
		} else {
			// 如果u为nil,说明url.Parse失败了,应该作为普通文件路径处理
			err = openFile(arg)
		}

	case "":
=======
	switch scheme {
	case "file":
		err = openFile(u.Path)

	case "":
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dde-open/main.go
Comment on lines 67 to 76
switch scheme {
case "file":
err = openFile(u.Path)
if u != nil {
err = openFile(u.Path)
} else {
// 如果u为nil,说明url.Parse失败了,应该作为普通文件路径处理
err = openFile(arg)
}

case "":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The check for u != nil after url.Parse may be redundant.

Go's url.Parse always returns a non-nil *url.URL, so this check can be removed to simplify the code.

Suggested change
switch scheme {
case "file":
err = openFile(u.Path)
if u != nil {
err = openFile(u.Path)
} else {
// 如果u为nil,说明url.Parse失败了,应该作为普通文件路径处理
err = openFile(arg)
}
case "":
switch scheme {
case "file":
err = openFile(u.Path)
case "":

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, robertkill

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@robertkill robertkill merged commit 56fe375 into linuxdeepin:master Jul 22, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants