Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 13:35

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: PutDString and nul bytes
PostPosted: 09 Apr 2011 15:04 

Joined: 09 Apr 2011 14:41
Posts: 1
Hi Luigi,

I encountered an issue when trying to use PutDString.
I would like to write a blob of data to a memoryfile.

Apparently, the GetDString and PutDString show a different behavior.
Code:
PutDString VAR LENGTH [FILENUM]


example :

GetDString NAME 0x100
SetDString NAME 0x100 MEMORY_FILE



When writing a VAR that has NUL bytes embedded (because the input had them in the first place), data is padded with NUL bytes after the first \x00.

if input is :
01 02 03 04 05 00 01 02 03 04 etc.
output is (unfortunately) :
01 02 03 04 05 00 00 00 00 00 etc.

Here is the reason:
Code:
    if(size > datasz) { // fill with zeroes, I avoided to use myfputc(0x00, fd);
        size -= datasz;
        myalloc(&buff, size, &buffsz);
        memset(buff, 0, size);
        if(myfw(fd, buff, size) < 0) return(-1);
    }



on the other hand, GetDString does not seem to bother:
Code:
    myalloc(&buff, size + 1, &buffsz);
    myfr(fd, buff, size);
    buff[size] = 0;



My question is, would it be possible to bypass the datasz check?
If backward compatibility is a concern, how about having an additional arg to toggle the behavior?


Top
 Profile  
 
 
 Post subject: Re: PutDString and nul bytes
PostPosted: 10 Apr 2011 05:47 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
the variables are strings so when there is a NULL delimiter they get truncated.
the only exception is the set VARIABLE binary "blahblah\x00blah\x0d\x0a" command that allows to store the variable including any byte.
I should check your specific case to know what solution would be better (exist many ways to do the same thing) anyway let me know if the set/binary command is ok


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: