]> diplodocus.org Git - nmh/blobdiff - sbr/mime_type.c
mhlsbr.c: Don't strchr(3) non-string NUL-less buffer.
[nmh] / sbr / mime_type.c
index a640110a9f48b1fdbe9554e88500553e311fa7b8..cc6b1fbf58b85da7b14d3a97da3628cc547e6cc1 100644 (file)
@@ -33,17 +33,13 @@ mime_type(const char *file_name) {
         /* Try to append charset for text content. */
         char *mimeencoding;
 
-        if (strncasecmp(mimetype, "text", 4) == 0) {
-            if ((mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) {
-                content_type = concat(mimetype, "; charset=", mimeencoding,
-                                      NULL);
-                free (mimetype);
-            } else {
-                content_type = mimetype;
-            }
-        } else {
+        if (!strncasecmp(mimetype, "text", 4) &&
+            (mimeencoding = get_file_info(MIMEENCODINGPROC, file_name))) {
+            content_type = concat(mimetype, "; charset=", mimeencoding, NULL);
+            free(mimeencoding);
+            free(mimetype);
+        } else
             content_type = mimetype;
-        }
 #else  /* MIMEENCODINGPROC */
         content_type = mimetype;
 #endif /* MIMEENCODINGPROC */
@@ -112,7 +108,7 @@ mime_type(const char *file_name) {
 #ifdef MIMETYPEPROC
 /*
  * Get information using proc about a file.
- */
+ * Non-null return value must be free(3)'d. */
 static char *
 get_file_info(const char *proc, const char *file_name)
 {
@@ -152,7 +148,7 @@ get_file_info(const char *proc, const char *file_name)
     if (!ok)
         return NULL;
 
-    /* s#^.*:[ \t]*##. */
+    /* s#^[^:]*:[ \t]*##. */
     info = buf;
     if ((needle = strchr(info, ':'))) {
         info = needle + 1;