Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Undefined behaviour when calling ioctl() multiple times

Open
#1,632 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java

Research direction

Start with the LibC interface and getWindowSize() reproduction in the issue, then run the loop on the stated macOS, Apple M1, and GraalVM setup. Inspect how the winsize argument is represented and passed through JNA during repeated ioctl() calls. Done means repeated calls no longer return errors or terminate with SIGSEGV, illegal instructions, or heap corruption.

Written by the indexing model from the issue text.

Description

JNA version: 5.15.0
JVM: GraalVM CE 17.0.9+9.1 (build 17.0.9+9-jvmci-23.0-b22)
OS: macOS 14.7
CPU: Apple M1 (64-bit)

public interface LibC extends Library {
    LibC libC = Native.load("c", LibC.class);
    int TIOCGWINSZ = 0x40087468; // this is definitely correct, I've checked it with C
    
    int ioctl(int fd, int request, winsize winsize);  
}

public static int getWindowSize() {
    val ttysize = new winsize();

    val returnCode = libC.ioctl(0, TIOCGWINSZ, ttysize);
    if (returnCode != 0) {
        throw new RuntimeException("There was a problem calling ioctl(): " + returnCode);
    }

    return ttysize.ws_col;
}

 for (int i = 0; i < 100; i++) {
      System.out.println(getWindowSize());
}

running this code results in either:

  1. ioctl() returning -1
  2. SIGSEGV
  3. Illegal instruction: 4
  4. Heap corruption detected
Dominant language
Java
Stars
8.9k
Forks
1.7k
Avg merge
1d 13h
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from java-native-access/jna

All issues in java-native-access/jna

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.