On Sat, Feb 25, 2023 at 09:28:13AM -0300, Crystal Kolipe wrote:
> On Sat, Feb 25, 2023 at 11:55:50AM +0100, Peter J. Philipp wrote:
> > I have found this function in tcpdump/util.c called fn_printn() that escapes
> > text.
> 
> Why would we want to use this function instead of just passing the string
> directly to vis?  The transformation it performs is not even uniquely
> invertible.

As promised I wrote a function called fn_print_vis() for inclusion in
tcpdump/util.c so that we can use this in future fixing of printf()'s.

Please give this some scrutiny and commit it to util if you like it.  Until
then I view this bug report as AWAITING RESPONSE :-).


/* returns -1 on error, 0 on success */

int
fn_print_vis(char *bp, int bplen)
{
        char *name, *cp;
        int i;

        if (cplen <= 0)
                return (-1);

        if (&bp[bplen] > snaplen)
                return (-1);

        name = calloc(bplen, 2);        /* big enough? */
        if (name == NULL)
                return (-1);

        cp = name;

        for (i = 0; i < bplen && bp[i] != '\0'; i++) {
                cp = vis(cp, bp[i], VIS_WHITE, 0);
        }

        printf("%s", name);
        free(name);

        return (0);
}

Best Regards,
-peter

Reply via email to