low level - C, write system call, writing int -
low level - C, write system call, writing int -
i found source in jon erickson's book, hacking: fine art of exploitation,
userid = getuid(); // real user id // writing info if(write(fd, &userid, 4) == -1) // write user id before note info fatal("in main() while writing userid file"); write(fd, "\n", 1); // terminate line
i tried compile code, , found on file write, userid (which write in code above) not right; wrote unusual character (i think not of import write here). problem trying pass int
function required char *
, because of result on file want write false.
so bug, right?
the write()
function expects void *
buffer; writes arbitrary binary data. if need conversion string, utilize printf()
.
you don't show declaration of userid
, write()
line should written as:
if (write(fd, &userid, sizeof(userid)) != sizeof(userid))
this observe short writes (unlikely problem integer type) , other problems, , works correctly regardless of type of userid
. original version of line arguably buggy, therefore. otherwise, bug seems in expectations rather code per se.
c low-level
Comments
Post a Comment