Ticket #1902: tftpDriver-lbl-p5.diff

File tftpDriver-lbl-p5.diff, 2.5 KB (added by Carl Lionberger, on Sep 1, 2011 at 9:16:08 PM)

several fixes to tftpDriver.c from 4.10.1

  • tftpDriver.c

    old new  
    492492{
    493493    tftpfs_info_t *fs;
    494494    char          *cp;
     495    int nal = 0;
    495496
    496497    /*
    497498     * Get the file system info.
     
    500501
    501502    pathloc->handlers = &rtems_tftp_handlers;
    502503
     504    if (pathloc->node_access != ROOT_NODE_ACCESS (fs))
     505        nal = strlen(pathloc->node_access);
    503506    /*
    504507     * Hack to provide the illusion of directories inside the TFTP file system.
    505508     * Paths ending in a / are assumed to be directories.
    506509     */
    507510    if (pathname[strlen(pathname)-1] == '/') {
    508         int nal = 0;
    509         if (pathloc->node_access != ROOT_NODE_ACCESS (fs))
    510             nal = strlen(pathloc->node_access);
    511511        cp = malloc(nal + pathnamelen + 1);
    512512        if (cp == NULL)
    513513            rtems_set_errno_and_return_minus_one(ENOMEM);
     
    536536            fixPath (cp);
    537537            pathloc->node_access_2 = cp;
    538538        }
     539        if (nal) {
     540            /* prevent eventually freeing the copy in the environment */
     541            cp = malloc(nal + 1);
     542            if (cp == NULL)
     543               rtems_set_errno_and_return_minus_one(ENOMEM);
     544            memcpy(cp, pathloc->node_access, nal);
     545            cp[nal] = '\0';
     546            pathloc->node_access = cp;
     547        }
    539548    }
    540549
    541550    return 0;
     
    586595     */
    587596    if (strcmp (hostname, "BOOTP_HOST") == 0)
    588597        farAddress = rtems_bsdnet_bootp_server_address;
    589     else if (inet_aton (hostname, &farAddress) == 0) {
     598    else if (inet_aton (hostname, &farAddress)) {
    590599        struct hostent *he = gethostbyname(hostname);
    591600        if (he == NULL)
    592601            return ENOENT;
     
    837846
    838847    err = rtems_tftp_open_worker (iop, full_path_name, flags, mode);
    839848    free (full_path_name);
    840     rtems_set_errno_and_return_minus_one(err);
     849    if (err)
     850      rtems_set_errno_and_return_minus_one(err);
     851    return 0;
    841852}
    842853
    843854/*
     
    9921003        rtems_task_wake_after (1 + ticksPerSecond / 10);
    9931004    }
    9941005    releaseStream (fs, iop->data0);
    995     rtems_set_errno_and_return_minus_one (e);
     1006    if (e)
     1007      rtems_set_errno_and_return_minus_one (e);
     1008    return 0;
    9961009}
    9971010
    9981011static ssize_t rtems_tftp_write(
     
    10691082)
    10701083{
    10711084    tftpfs_info_t *fs = tftpfs_info_pathloc (pathloc);
    1072     if (pathloc->node_access && \
     1085    if (pathloc->node_access &&
    10731086        (pathloc->node_access != ROOT_NODE_ACCESS (fs))) {
    10741087        free (pathloc->node_access);
    10751088        pathloc->node_access = NULL;