microsoft / microsoft/wmi

[Bug?] Invalid queries are not filling the err variable

Open
#156 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
58
Forks
23
PR merge metrics
No merged PRs in 30d

Description

Hi there,

I happened to notice that an invalid queries like:

  • SELECT * FROM ThisDoesNotExist (invalid class)
  • SELECT ThisDoesNotExist FROM Win32_OperatingSystem (invalid Property)

Which are correctly failing with an error in WmiExplorer:

Image

Image

And are producing EventViewer's Errors 5858 in the Microsoft > Windows > WMI Activity > Operational are silently ignored.

Example:

package cim

import (
	"log"
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_ClassDoesNotExist(t *testing.T) {
	sm := NewWmiSessionManager()
	defer sm.Close()
	defer sm.Dispose()
	session, err := sm.GetLocalSession("root\\cimv2")
	if err != nil {
		log.Printf("Could not get session %v", err)
		return
	}
	_, err = session.Connect()
	if err != nil {
		log.Printf("Could not connect session %v", err)
		return
	}
	defer session.Close()
	defer session.Dispose()

	query := "SELECT * FROM ThisDoesNotExist"
	_, err = session.QueryInstances(query)

	assert.Error(t, err)

	query = "SELECT DoesNotExist FROM Win32_OperatingSystem"
	_, err = session.QueryInstances(query)

	assert.Error(t, err)

}

The expected behavior is that such failures should fill the err variable to let programmers deal with invalid queries.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Test_ClassDoesNotExist reproducer and trace session.QueryInstances for how invalid WMI queries are handled. Run the test with both invalid queries; done means each failure populates err so callers can detect it.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.