slimtoolkit/slim · error

error parsing UID field - %s (%v)

Error message

error parsing UID field - %s (%v)

What it means

sysidentity.ParsePasswdRecord parses a line from /etc/passwd split into ':'-separated fields; field index 2 is the UID. If strconv.Atoi cannot convert that field to an integer, the parser returns this error together with the partially filled record. It indicates a malformed passwd entry rather than a library bug.

Source

Thrown at pkg/sysidentity/sysidentity.go:330

	parts := strings.Split(line, ":")
	if len(parts) != 7 {
		return record, errors.New("unexpected field count")
	}

	record.Username = parts[0]
	record.Password = parts[1]
	record.Info = parts[4]
	record.Home = parts[5]
	record.Shell = strings.TrimSpace(parts[6])

	if _, found := NoLoginShells[record.Shell]; found {
		record.NoLoginShell = true
	}

	var err error
	record.UID, err = strconv.Atoi(parts[2])
	if err != nil {
		return record, fmt.Errorf("error parsing UID field - %s (%v)", parts[2], err)
	}

	record.GID, err = strconv.Atoi(parts[3])
	if err != nil {
		return record, fmt.Errorf("error parsing GID field - %s (%v)", parts[3], err)
	}

	return record, nil
}

const (
	HasShadowFileRecord = "x"
)

func (ref PasswdRecord) UsesShadow() bool {
	if ref.Password == HasShadowFileRecord {
		return true
	}

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Open /etc/passwd and fix or remove the line whose UID field is non-numeric
  2. Validate the file: awk -F: '$3 !~ /^[0-9]+$/{print}' /etc/passwd
  3. Restore the file from a package-managed backup (e.g. 'pam-auth-update' base or rpm -V setup / dpkg -V passwd)
  4. If records come from a name-service switch source, fix the upstream directory entry

Example fix

// before (bad /etc/passwd line)
svc:x::1000::/home/svc:/bin/sh
// after
svc:x:1500:1500::/home/svc:/bin/sh
Defensive patterns

Strategy: validation

Validate before calling

// pre-validate /etc/passwd lines
func validPasswdLine(line string) bool {
    parts := strings.Split(line, ":")
    if len(parts) < 4 { return false }
    _, err1 := strconv.Atoi(parts[2])
    return err1 == nil
}

Try / catch

rec, err := sysidentity.ParsePasswdRecord(line)
if err != nil {
    log.Warnf("skipping malformed passwd entry: %v", err)
    continue
}

Prevention

When it happens

Trigger: ReadPasswdData -> ParsePasswdRecord on a passwd line whose third field is not a decimal number (empty or contains letters/spaces).

Common situations: Hand-edited or corrupted /etc/passwd; leftover comment or placeholder lines like 'user:x::...'; LDAP/sssd-generated entries with non-numeric UIDs; trailing whitespace or invisible characters.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/f8c972160afad707. Report an issue: GitHub.