Forum OpenACS Q&A: Problems with ns_uuencode patch to AOLserver

I've been working on an AOLserver 4 distribution for OpenACS on Windows. I was going to apply Vinod's patch to make ns_uuencode work for binary content, but the patch itself seems to have some bugs. (But please correct me if I'm wrong.) I got the patch from SourceForge - is that the correct version? In AOLserver 4 the function to be modified is NsTclHTUUEncodeObjCmd in tclmisc.c

I think there are two bugs, one minor and one major.

  1. Minor bug - also a problem with the current AOLserver CVS HEAD I think. The buffer to receive the UUEncoded data is declared char bufcoded[1 + (4 * 48) / 2];. I think it should actually be char bufcoded[1 + (4 * 48) / 3];. Just allocating a little more space than necessary, not a showstopper.
  2. Major bug - when the patched function is padding the array with zeros, it overwrites memory it shouldn't be.
    bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &nbytes);
    ...
    padbytes = nbytes;
    while (padbytes % 3 != 0) {
        bytes[padbytes] = '
Hmm. That post had a backslash-zero in it, so it isn't being displayed. A bug with the bboard code? I think it looked fine on the confirm page. Trying again:

2. Major bug - when the patched function is padding the array with zeros, it overwrites memory it shouldn't be.

bytes = (char *) Tcl_GetByteArrayFromObj(objv[1], &nbytes);
...
padbytes = nbytes;
while (padbytes % 3 != 0) {
    bytes[padbytes] = '
Collapse
Posted by Vinod Kurup on
Ack! I think you're right - my patch is buggy. I'm not sure how I missed the memory-overwrite, but I did :(

It seems to me that your fix is appropriate, but I hope someone with actual knowledge of C will comment.

Thanks Jamie!