Ticket #96: segfault-on-invalid-mtime.patch

File segfault-on-invalid-mtime.patch, 1.1 KB (added by slavazanko, 15 years ago)
  • src/util.c

    #
    # Invalid timestamps on files caused mc to segfault by passing a null
    # pointer to strftime. Avoid trying to print the time in this case.
    # 
    # Source:       Gentoo Portage
    # Reference:	mc-4.6.1
    # Reported-By:	Maxim Britov <maxim office modum by>
    # Reported-Bug: <a rel="nofollow" href="http://bugs.gentoo.org/184296">http://bugs.gentoo.org/184296</a>
    # Submit-By:    Enrico Weigelt, metux IT service <weigelt metux de>
    # Submit-Date:	2008-12-26
    # State:	new
    #
    diff -ruN mc-4.6.1.orig/src/util.c mc-4.6.1/src/util.c
    old new  
    717717    static size_t i18n_timelength = 0; 
    718718    static const char *fmtyear, *fmttime; 
    719719    const char *fmt; 
     720    struct tm *whentm; 
    720721 
    721722    if (i18n_timelength == 0){ 
    722723        i18n_timelength = i18n_checktimelength() + 1; 
     
    740741    else 
    741742        fmt = fmttime; 
    742743     
    743     strftime (timebuf, i18n_timelength, fmt, localtime(&when)); 
     744    whentm = localtime(&when); 
     745    if (whentm == NULL) 
     746        return "(invalid)"; 
     747 
     748    strftime (timebuf, i18n_timelength, fmt, whentm); 
    744749    return timebuf; 
    745750} 
    746751