microsoft / microsoft/WSL

`int getlogin_r(char *buf, size_t len)` broken

Open
#888 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature wsl2
Dominant language
C++
Stars
33.7k
Forks
1.8k
Avg merge
3d 17h
Merged PRs (30d)
116

Description

Please use the following bug reporting template to help produce actionable and reproducible issues:

  • A brief description
    Attempting to use the function to get the login id of the user running the executable returns garbled strings, with a different return value each time.
  • Expected results
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(){
        size_t len = 10;
        char buf[len];
        size_t ret = getlogin_r(buf, len);
        puts(buf);
        return 0;
}

should print out my username, with ret set to 0 to indicate success.

  • Actual results (with terminal output if applicable)

The value of ret is 2, indicating an error.
Depending on the C compiler used, it outputs garbage strings.
If compiled with GCC or Clang, it prints out a single "unknown char" box.
If compiled with TCC, it prints out a string the size of one's username, composed of aforementioned boxes and random numbers, letters, and symbols.

  • Your Windows build number

14393

  • Steps / commands required to reproduce the error

gcc test.c -o test && ./test

  • Strace of the failing command

Command doesn't fail in this sense.

  • Required packages and commands to install

sudo apt-get install build-essential

image

Contributor guide

Open the contributing guide

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 by running the reported gcc test.c -o test && ./test reproduction and inspect the getlogin_r(char *buf, size_t len) entry point used by test.c. Confirm the behavior across the stated compilers, then make the call return 0 and populate buf with the current username without garbled output.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.