Skip to contentSkip to conversation

Typo in example code of process_vm_readv

DISCUSSION Ville Ylenius 2 participants 2 messages Aug 16, 2014 – Aug 17, 2014 1 message not in the archive Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

Hi,

there is a small typo in the example code of the man page of "process_vm_readv" (http://man7.org/linux/man-pages/man2/process_vm_readv.2.html):

       #include <sys/uio.h>

       int
       main(void)
       {
           struct iovec local[2];
           struct iovec remote[1];
           char buf1[10];
           char buf2[10];
           ssize_t nread;
           pid_t pid = 10;             /* PID of remote process */

           local[0].iov_base = buf1;
           local[0].iov_len = 10;
           local[1].iov_base = buf2;
           local[1].iov_len = 10;
           remote[0].iov_base = (void *) 0x10000;
           remote[1].iov_len = 20;                     /**** <---- TYPO: 1 --> 0 ****/

           nread = process_vm_readv(pid, local, 2, remote, 1, 0);
           if (nread != 20)
               return 1;
           else
               return 0;
       }

There is no two objects in "remote"-array so program corrupts other variables memory.

Please change

remote[1].iov_len = 20;

to

remote[0].iov_len = 20;

Thank you!

- Ville Ylenius
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to a message not in the archive
Quoted 36 lines · Ville Ylenius

Hi,

there is a small typo in the example code of the man page of "process_vm_readv"
(http://man7.org/linux/man-pages/man2/process_vm_readv.2.html):

        #include <sys/uio.h>

        int
        main(void)
        {
            struct iovec local[2];
            struct iovec remote[1];
            char buf1[10];
            char buf2[10];
            ssize_t nread;
            pid_t pid = 10;             /* PID of remote process */

            local[0].iov_base = buf1;
            local[0].iov_len = 10;
            local[1].iov_base = buf2;
            local[1].iov_len = 10;
            remote[0].iov_base = (void *) 0x10000;
            remote[1].iov_len = 20;                     /**** <---- TYPO: 1 --> 0 ****/

            nread = process_vm_readv(pid, local, 2, remote, 1, 0);
            if (nread != 20)
                return 1;
            else
                return 0;
        }

There is no two objects in "remote"-array so program corrupts other variables memory.

Quoted 7 lines

Please change

remote[1].iov_len = 20;

to

remote[0].iov_len = 20;

Thanks, Ville. Fixed now.

Cheers,

Michael

Signature · 7 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html