Skip to content

%.* is not a supported debug specifier #35688

Closed

Description

@mmomtchev
  • Version: v14.13.1
  • Platform: Linux
  • Subsystem: http2

What steps will reproduce the bug?

(example from #35475)
NODE_DEBUG_NATIVE=HTTP2SESSION node

const http2 = require('http2');
const tls = require('tls');
const stream = require('stream');

const options = {
    ALPNProtocols: ['h2'],
    host: 'nghttp2.org',
    servername: 'nghttp2.org',
    port: 443
};

const socket = tls.connect(options, async () => {
    console.log('TLS Connected!');

    const proxy = new stream.Duplex({
        read(...args) {
            const x = socket.read();
            console.log('read', JSON.stringify(x));
            if (x !== null)
            this.push(x);
        },

        final(...args) {
            socket.end(...args);
        },

        write(...args) {
            socket.write(...args);
        },

        destroy(...args) {
            socket.destroy(...args);
        }
    });

    await new Promise(resolve => setTimeout(resolve, 2000));

    const session = http2.connect('https://nghttp2.org', {
        createConnection: () => socket
    });

    session.once('remoteSettings', () => {
        console.log('HTTP2 Received remote settings!');
    });

    session.once('connect', () => {
        console.log('HTTP2 Connected!');
    });

});

Additional information

master is not affected

Activity

  1. mmomtchev commented on Oct 16, 2020

    @mmomtchev
    ContributorAuthor

    switch (*p) {
    doesn't seem to support %.* as a format specifier, yet there are a few examples in the code? @addaleax?
    Currently the % eats the length specifier then the second argument triggers the CHECK_NOT_NULL

  2. changed the title [-]Segfault with NODE_DEBUG_NATIVE=HTTP2SESSION[/-] [+]%.* is not a supported debug specifier[/+] on Oct 17, 2020
  3. addaleax commented on Oct 17, 2020

    @addaleax
    Member

    @mmomtchev Yeah, length specifiers make sense for a printf that is mainly intended to handle C strings, but it’s not important for a type-aware C++ variant like the one that we have. I think it would be just fine here to replace Debug(session, "Error '%.*s'", len, message); with Debug(session, "Error '%s'", std::string(message, len));.

  4. mmomtchev commented on Oct 17, 2020

    @mmomtchev
    ContributorAuthor

    Yes, in fact, there are 3 different sprintfs used through out the code: this one, from debug_utils-inl.h, the V8 one and the OS-provided one - and all the other examples are for the other two which support it

  5. added
    http2Issues and PRs related to the http2 subsystem.
    inspectorIssues and PRs related to the V8 inspector protocol.
    on Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    http2Issues and PRs related to the http2 subsystem.inspectorIssues and PRs related to the V8 inspector protocol.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions